C++ programming - Help your instructor Write a c++ program that helps out with g
ID: 657001 • Letter: C
Question
C++ programming - Help your instructor
Write a c++ program that helps out with grading a class for your instructor. The program should ask and read in the name of the class (such as Pre-calculus) as string. Then it should ask and read in the number of tests given for the class. For each test, there may be a different number of students taken the test. Your program should read in scores for each test until a sentinel value (negative number) is entered. It should count for all valid scores entered for each test. Then your program should calculate the average for each test (note that the counts may be different for each test) and finally the class average for all tests. Be sure to display the final results in a nicely formatted output.
(hint: use nested loops)
Explanation / Answer
#include <iostream.h>
#include <sting.h>
#include <cmath.h>
using namespace std;
int main()
{
int size,i;
int num=0;
int sum=average=0;
int marks[20];
do{
std::cout<<"Enter a positive number(-1 to stop):";
std::cin>>num;
if(num!=-1)
{
std::string classname;
std::cout<<"Enter the classname:";
getline(std::cin,classname);
std::cout<<"Enter the number of subjects:";
std::cin>>size;
std::cout<<"Enter the N marks:";
for(i=0;i<size;i++){std::cin>>marks[i];sum=sum+marks[i];}
std::cout<<"Average of N marks:";
average=sum/size;
std::cout<<average<<' ';
}
}while(num!=-1);
}
___________________________________________________________
OUTPUT
___________________________________________________________
Enter a positive number(-1 to stop):
1
Enter the classname:
cs
Enter the number of subjects:
5
Enter the N marks:
60
65
70
85
90
Average of N marks:
74
Enter a positive number(-1 to stop):
-1
__________________________________________
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.