In: Computer Science
Create a C++ program that will ask the user for how many test scores will be entered.
Setup a while loop with this loop iteration parameter. (no fstream)
The data needs to include the student’s first name, student number test score
the fields should be displayed with a total width of 15.
The prompt should be printed with a header in the file explaining what each is:
ex.
First Name student number Test Score
1) mike 6456464 98
2) phill 3453453. 85
Program:
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
int numStudents;
//accepting the number of students test score count
cout<<"How many test scores do you want to enter: ";
cin>>numStudents;
//creating an array for each field
string name[numStudents];
long sno[numStudents];
int testScore[numStudents];
int i=0;
//accepting the values of the students from user
cout<<"\nEnter "<<numStudents<<" students
name,number and test score: \n";
while(i<numStudents)
{
cout<<"\nEnter the name of student"<<(i+1)<<":
";
cin>>name[i];
cout<<"Enter the number of student"<<(i+1)<<":
";
cin>>sno[i];
cout<<"Enter the test score of
student"<<(i+1)<<": ";
cin>>testScore[i];
i++;
}
i=0;
cout<<endl<<endl;
//Displaying the firstname, number and test score of each
student
cout<<setw(15)<<"First
Name"<<setw(15)<<"Student
Number"<<setw(15)<<"Test Score"<<endl;
cout<<"-------------------------------------------------------------------"<<endl;
while(i<numStudents)
{
cout<<(i+1)<<")"<<setw(7)<<name[i]<<setw(15)<<sno[i]<<setw(15)<<testScore[i]<<endl;
i++;
}
return 0;
}
Output: