Answer to Question #234494 in C++ for Myname

Question #234494
Write a program of a menu-driven interface to offer the user four options as follows:
Enter a choice:
0 Print the array of grades
1 Find the minimum grade
2 Find the maximum grade
3 Print the average on all tests for each student
4 End program
Functions should be implemented using pass by reference method. The memory for the array
should be allocated dynamically
1
Expert's answer
2021-09-07T14:15:58-0400
#include <iostream>
#include <string>


using namespace std;


#define STUDENTS 3
#define EXAMS 4


void printArrayGrades(const int grades[][EXAMS]);
void findMinimumGrade(const int grades[][EXAMS]);
void findMaximumGrade(const int grades[][EXAMS]);
void findAverageGrade(const int grades[][EXAMS]);




int main(){
	int ch = 0;


	const int studentGrades[STUDENTS][EXAMS] = 
	{{ 77, 68, 86, 73 },
	{ 96, 87, 89, 78 },
	{ 70, 90, 86, 81 }};


	while(ch!=4){
		cout<<"Enter a choice:\n";
		cout<<"0 Print the array of grades\n";
		cout<<"1 Find the minimum grade\n";
		cout<<"2 Find the maximum grade\n";
		cout<<"3 Print the average on all tests for each student\n";
		cout<<"4 End program\n";
		cout<<"> ";
		cin>>ch;


		switch(ch){
		case 0:
			printArrayGrades(studentGrades);
		case 1:
			findMinimumGrade(studentGrades);
			break;
		case 2:
			findMaximumGrade(studentGrades);
			break;
		case 3:
			findAverageGrade(studentGrades);
			break;
		case 4:
			//exit
			break;
		default:
			break;
		}
	}




	int pause;
	cin>>pause;
	return 0;
}


void printArrayGrades(const int grades[][EXAMS]){
	for(int i = 0; i < STUDENTS; i++){
		cout<<"The student "<<(i+1)<<" has the following scores: ";
		for(int j = 0; j < EXAMS; j++){
			cout<<grades[i][j]<<" ";
		}
		cout<<"\n";
	}
	cout<<"\n";
}




void findMinimumGrade(const int grades[][EXAMS]){
	int minimumGrade = grades[0][0];
	int indexStudent=0;
	for(int i = 0; i < STUDENTS; i++){
		for(int j = 0; j < EXAMS; j++){
			if(grades[i][j]<minimumGrade){
				minimumGrade = grades[i][j];
				indexStudent=i;
			}
		}
	}
	cout<<"The student "<<(indexStudent+1)<<" has the minimum grade: "<<minimumGrade<<"\n";
}


void findMaximumGrade(const int grades[][EXAMS]){
	int maximumGrade = grades[0][0];
	int indexStudent=0;
	for(int i = 0; i < STUDENTS; i++){
		for(int j = 0; j < EXAMS; j++){
			if(grades[i][j]>maximumGrade){
				maximumGrade = grades[i][j];
				indexStudent=i;
			}
		}
	}
	cout<<"The student "<<(indexStudent+1)<<" has the maximum grade: "<<maximumGrade<<"\n";
}


void findAverageGrade(const int grades[][EXAMS]){ 
	for(int i = 0; i < STUDENTS; i++){
		float total = 0;
		for(int j = 0; j < EXAMS; j++){
			total += grades[ i ][ j ];
		}
		float average=(float)(total / EXAMS);
		cout<<"The average grade for student "<<(i+1)<<" is "<<average<<"\n";
	}
}







Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS