122k views
5 votes
Create a C++ console application to store points for contestants in a contest. Ask the user for the number of contestants. Create two parallel dynamic arrays, one to store the names and one to store integer scores from zero to 100. Do not accept out of range numbers. Ask the user for each name and the score one at a time.

When you encounter the end of the array, print all names and scores. Also, print the average and indicate whether each score is above or below average. The example is attached in the file and I want you to get the same output on the shown display of the program.
Requirements:
1 Add comments as you code. Do NOT wait until you are done coding. Also, in the beginning of your codes include the following comments:
Purpose of the program,
Name of the author, and
Date
2 Tell the user what the program is all about.
3 Create a function to get the values from the user and store them in the arrays. Pass the pointers and array size to the function. This function will have a void return type.
4 Create a function to calculate the average. Pass a pointer and the size to the array. The function should return the average.
5 Create another function to print the result. Pass the pointers, the array size, and the average to the function.
6 Do not pass arrays to functions. Even though it is possible to do so, we are trying to practice using pointers.
7 All functions will be called only by the main. Prevent calling them by other functions.
8 No global variables are allowed.
9 Delete the arrays to free the memory after printing the results.
10 Ask the user if they want to continue. If so, ask the questions again.
11 Test, test, and test.
Hints:
Please, do NOT use 'break' or 'continue' in the code.
This is how you create a dynamic array: arrayPtr = new int[size];
Use this syntax to pass the pointer to a function: void display (string* namePtr){ }

User Emybob
by
4.5k points

1 Answer

6 votes

Answer:

Open your python console and execute the following .py code

Step-by-step explanation:

Code bellow:

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

void inputInfo(string*, int*, int);

double mathAvr(int*, int);

void printInfo(string*, int*, int, double);

int main()

{

double avg;

int n;

string *names;

int *scores;

char ch;

do

{

cout << "\\ contestants quantity: ";

cin >> n;

names = new string[n];

scores = new int[n];

inputInfo(names, scores, n);

avg = mathAvr(scores, n);

printInfo(names, scores, n, avg);

delete [] names;

delete [] scores;

cout << "\\ again? (Y/N): ";

cin >> ch;

}while(ch=='Y' || ch=='y');

cout << "\\\\";

return 0;

}

void inputInfo(string *names, int *scores, int n)

{

int i;

for(i=0; i<n; i++)

{

cout << "\\\\ Name of the participant: ";

cin >> *(names+i);

do

{

cout << "\\ score " << *(names+i) << " (0-100): ";

cin >> *(scores+i);

}while(*(scores+i) < 0 || *(scores+i) > 100);

}

}

double mathAvr(int *scores, int n)

{

int i, sum=0;

double avg;

for(i=0; i<n; i++)

{

sum += *(scores+i);

}

avg = sum / (double)n;

return avg;

}

void printInfo(string *names, int *scores, int n, double avg)

{

int i;

cout << "\\\\ " << left << setw(20) << "Participant name" << left << setw(6) << "Score" << " \\";

for(i=0; i<n; i++)

{

cout << "\\ " << left << setw(20) << *(names+i) << left << setw(6) << *(scores+i);

}

cout << fixed << setprecision(2);

cout << "\\\\ Average: " << avg << " \\\\";

}

User Dimshik
by
3.3k points