Answer to Question #175335 in C++ for meng

Question #175335

Write a program that lets a lecturer keep track of test scores for their students. Your program should begin by asking the lecturer for a number of students in their class as well as the total number of exams that will be given to the class. Validate this information to ensure that the numbers entered are positive.

 

Next, give the message to lecturer to enter scores for each student. Make sure that the values entered are valid (marks cannot be neagtive) —if they aren’t you will need to prompt them again. You may need to use nested loops for this; a “while” loop can be placed inside of a “for” loop as necessary.

 

Once your program has collected all exam scores for a student it should display that student’s average and move on to the next student. When all students have been calculated the program should compute the overall average score for the entire class.



1
Expert's answer
2021-03-25T08:27:25-0400
#include <iostream>


using namespace std;


//The start point of the program
int main (){
	int numberStudents=-1;
	int numberExams=-1;
	//ask the lecturer for a number of students in their class as well 
	//as the total number of exams that will be given to the class. 
	//Validate this information to ensure that the numbers entered are positive. 
	while(numberStudents<=0){
		cout<<"Enter the number of students in the class: ";
		cin>>numberStudents;
	}
	while(numberExams<=0){
		cout<<"Enter the number of exams in the class: ";
		cin>>numberExams;
	}
	float overallAverage=0;
	for(int i=0;i<numberStudents;i++){
		int j=0;
		float sum=0;
		//a "while" loop can be placed inside of a "for" loop as necessary.
		while(j<numberExams){
			//enter scores for each student.
			int score=-1;
			while(score<0){
				cout<<"Enter enter score >=0 for the student "<<(i+1)<<": ";
				cin>>score;
				sum+=score;
			}
			j++;
		}
		//Once your program has collected all exam scores for a student it should display that student’s average 
		float studentAverage= sum/numberExams;
		overallAverage+=studentAverage;
		cout<<"\nThe average score for the student "<<(i+1)<<": "<<studentAverage<<"\n\n";
	}
	//When all students have been calculated the program should compute the overall average score for the entire class.
	overallAverage=overallAverage/numberStudents;
	cout<<"\nThe overall average score for the entire class: "<<overallAverage<<"\n\n";
	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
APPROVED BY CLIENTS