this is a array question...enter students names and scores and print out name wi
ID: 3841121 • Letter: T
Question
this is a array question...enter students names and scores and print out name with average...ch 7 ppj4
A Class teacher asks you to help him with his course management.He uses a flat file where he records the namesof his students.and thier scores for the first and second tests in the subject.moreover ,the teacher is loaded with the burden of manually comuting the scores to find a students average score in his subject for the end of the semester results.You are reqiured to write a c++ program that the user to inut the students first name,second name,first test score and second test score.the program should then be able to find the average score of each student for the subject,and print his or her first and second names together with thier corresponding scores.the size of the class changes from semester to semester but it will never be larger than 50 students.A posible outcome can be as follows:
first name:john
second name:jacob
average score :78
first name:James
Second Name:Johnson
Average score:85
Explanation / Answer
/////////****** Answer of ch7 ppj4******/////////////
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string fName[50];
string sName[50];
float ftScore[50];
float stScore[50];
float average[50];
int n,i;
cout<<" How many students record you want to enter? "; /////Number of students record which has to be inputed is stored here
cin>>n;
if (n>50)
{
cout<<"Number of students must be less than or equal to 50; Enter properly. ";
cout<<" How many students record you want to enter? ";
cin>>n;
}
/// here the record of the students is entered and stored in the proper array
for(i=0;i<n;i++)
{
cout<<" Enter the first name of the student ";
cin>>fName[i];
cout<<" Enter the second name of the student ";
cin>>sName[i];
cout<<" Enter the first test score of the student ";
cin>>ftScore[i];
cout<<" Enter the second test score of the student ";
cin>>stScore[i];
}
///// average of the test score is calculated below
for(i=0;i<n;i++)
{
average[i]=(float)(ftScore[i]+stScore[i])/2;
}
//// output is displayed here
for(i=0;i<n;i++)
{
cout<<" first name :"<<fName[i]<<endl;
cout<<" second name :"<<sName[i]<<endl;
//cout<<" first test score :"<<ftScore[i]<<endl;
//cout<<" second test score :"<<stScore[i]<<endl;
cout<<" average score :"<<average[i]<<endl;
cout<<endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.