Answer to Question #296583 in C++ for se7le

Question #296583

Write a C++ program that stores the grades of N students in an array of size 100. The


user must input at the beginning of the program the number of students N., then the


user must input the grade for each student. The program then must display the


following menu (use functions):


1. Print the minimum and maximum grade. (10 points)


2. Print the number of passing and failing students. (10 points)


3. Print the average grade, the percentage of passing students (grade >=70), and


the percentage of students that got a grade greater or equal to the average


grade. (15 points)


4. Exit. (5 points)

1
Expert's answer
2022-02-11T11:56:53-0500


#include <iostream>






using namespace std;
int main(){
	int choice;
	int N;
	int grades[100];
	cout<<"Enter the number of students N: ";
	cin>>N;
	for(int i=0;i<N;i++){
		cout<<"Ente the grade for the student "<<(i+1)<<": ";
		cin>>grades[i];
	}


	do{
		cout<<"1. Print the minimum and maximum grade.\n";
		cout<<"2. Print the number of passing and failing students.\n";
		cout<<"3. Print the average grade, the percentage of passing students (grade >=70), and\n";
		cout<<"the percentage of students that got a grade greater or equal to the average grade.\n";
		cout<<"4. Exit.\n";
		cout<<"Your choice: ";
		cin>>choice;
		if(choice==1){
			int minimuGrade=grades[0];
			int maximumGrade=grades[0];
			for(int i=0;i<N;i++){
				if(grades[i]<minimuGrade){
					minimuGrade=grades[i];
				}
				if(grades[i]>maximumGrade){
					maximumGrade=grades[i];
				}
			}
			cout<<"The minimum grade: "<<minimuGrade<<"\n";
			cout<<"The maximum grade: "<<maximumGrade<<"\n";
		}else if(choice==2){
			int numberPassing=0;
			int numberFailing=0;
			for(int i=0;i<N;i++){
				if(grades[i]>=70){
					numberPassing++;
				}else{
					numberFailing++;
				}
			}
			cout<<"The number of passing students: "<<numberPassing<<"\n";
			cout<<"The number of failing students: "<<numberFailing<<"\n";


		}else if(choice==3){
			float averageGrade;
			float sum=0;
			float percentagePassingStudents;
			float percentageAverageStudents;
			int numberPassing=0;


			for(int i=0;i<N;i++){
				if(grades[i]>=70){
					numberPassing++;
				}
				sum+=grades[i];
			}
			averageGrade=sum/(float)N;
			percentagePassingStudents=(((float)numberPassing)/(float)N)*100.0;


			int studentGradeGreaterEqualAverageGrade=0;
			for(int i=0;i<N;i++){
				if(grades[i]>=averageGrade){
					studentGradeGreaterEqualAverageGrade++;
				}
			}
			percentageAverageStudents=(((float)studentGradeGreaterEqualAverageGrade)/(float)N)*100.0;
			cout<<"The average grade the students: "<<averageGrade<<"\n";
			cout<<"The percentage of passing students (grade >=70): "<<percentagePassingStudents<<"\n";
			cout<<"The percentage of students that got a grade greater or equal to the average grade: "<<percentageAverageStudents<<"\n";
		}else if(choice==4){
			//exit
		}else{
			cout<<"Wrong menu item\n\n";
		}
		cout<<"\n\n";
	}while(choice!=4);


	system("pause");
	return 0;
}

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
New on Blog