Question: I need help making the C++ program restart the array if the input is 'y'. My assignment and code are below C++ Programming Programming Assignment

I need help making the C++ program restart the array if the input is 'y'. My assignment and code are below

C++ Programming

Programming Assignment 5 Arrays

Objectives:

1. Write a program that finds the highest, lowest, and mean values of a set of numerical data

2. Use Arrays to store data

3. Use an array as argument in function Calls

Problem statement:

Write a program that will

a) Prompt the user to enter the student name, numerical grade of each students in a test, one

at a time, and store it in an array. This is accomplished in the main module. The user

presses enter key for the name to indicate all the grades are entered. The program will

keep the count of the number of grades entered.

b) Display all the grades in a tabular form.

c) Create three functions

(i) one to find the average grade

(ii) second one to find the lowest grade

(iii) and a third function to find the highest grade

Pass the array name and the number of grades to each function and each function returns

the appropriate value.

d) Finally display the class average, highest grade, and the lowest grade, at the bottom. At

the end the user is prompted to exit or enter grades for another class.

Procedure or Details:

The arrays and the size of the array are passed to each function.

All calculations are done in the function.

The values are displayed in the main module.

The following is an example of the output:

Name Grade

---------- --------

Jim 65

George 90

Joe 72

Lila 86

Eric 89

John 62

Judy 82

Mary 92

Randy 95

Katy 68

The class average: 80.1

Highest Grade is: Randy 95

Lowest Grade: John 62

MY CODE IS AS FOLLOWS:

#include

#include

#include

#include

#include

using namespace std;

double average(int a[], int c) {

double sum = 0;

for (int i = 0; i < c; i++)

sum = sum + a[i];

return sum / c;

}

void highest(string n[], int a[], int c, string &nm, int &gr) {

gr = 0;

for (int i = 0; i < c; i++) {

if (a[i] > gr) {

gr = a[i];

nm = n[i];

}

}

}

void lowest(string n[], int a[], int c, string &nm, int &gr) {

gr = a[0];

nm = n[0];

for (int i = 0; i < c; i++) {

if (a[i] < gr) {

gr = a[i];

nm = n[i];

}

}

}

int main() {

string names[100];

int grade[100];

int count = 0;

int gr;

string nm;

string ch;

string str;

string m;

while (1) {

while (1) {

cout << "Enter name and grade (Once you are done, press enter twice): ";

getline(cin, str);

if (str != "") {

stringstream iss(str);

iss >> names[count];

iss >> grade[count];

count++;

}

else {

break;

}

}

cout << setw(20) << std::left << "Name" << setw(20) << "Grade" << endl;

cout << setw(20) << std::left << "----" << setw(20) << "-----" << endl;

for (int i = 0; i < count; i++) {

cout << setw(20) << std::left << names[i] << setw(20) << grade[i] << endl;

}

cout << setw(50) << std::left << "The class average is:" << setw(15) << fixed << setprecision(1) << average(grade, count) << endl;

highest(names, grade, count, nm, gr);

cout << setw(30) << std::left << "Highest grade is:" << setw(20) << std::left << nm << setw(15) << fixed << setprecision(1) << gr << endl;

lowest(names, grade, count, nm, gr);

cout << setw(30) << std::left << "Lowest grade is:" << setw(20) << std::left << nm << setw(15) << fixed << setprecision(1) << gr << endl;

cout << "Do you want to enter data for another class (y/n) ?:";

cin >> ch;

if (ch[0] == 'y')

{

return main();

}

else(ch[0] == 'n');

{

break;

}

}

cin.ignore();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!