repare a c++ program of the sample run below
Name Quiz1 Quiz2 Quiz3 Quiz4 Total Quiz
(20/20) (30/30) (15/15) (25/25) 90/90
Jessa Lee 12 15 15 20
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct Student{
string fullName;
int quiz[4];
int totalQuiz;
};
int main(){
int numberStudents=-1;
while(numberStudents<=0){
cout << "Ente the number of students: ";
cin>>numberStudents;
}
Student* students=new Student[numberStudents];
for(int i=0;i<numberStudents;i++){
cin.ignore();
cout << "Ente the name of the student "<<(i+1)<<": ";
getline(cin,students[i].fullName);
students[i].totalQuiz=0;
for(int j=0;j<4;j++){
cout << "Ente the quiz "<<(i+1)<<": ";
cin>>students[i].quiz[j];
students[i].totalQuiz+=students[i].quiz[j];
}
}
cout<<fixed<<left<<setw(30)<<"Name"<<setw(10)<<"Quiz1"<<setw(10)<<"Quiz2"<<setw(10)<<"Quiz3"<<setw(10)<<"Quiz4"<<setw(10)<<"Total Quiz\n";
cout<<"\t\t\t (20/20) (30/30) (15/15) (25/25) 90/90\n";
for(int i=0;i<numberStudents;i++){
cout<<setw(30)<<students[i].fullName<<setw(10)<<students[i].quiz[0]<<setw(10)<<students[i].quiz[1]<<setw(10)<<students[i].quiz[2]<<setw(10)<<students[i].quiz[3]<<setw(10)<<students[i].totalQuiz<<"\n";
}
delete[] students;
cin>>numberStudents;
return 0;
}
Comments
Leave a comment