Write a Program That Reads Students Names Followed by Their Test Scores C++

I have implemented the program as per the requirements given above. Delight find the following Lawmaking Screenshot, Output, and Code.

ANY CLARIFICATIONS REQUIRED LEAVE A COMMENT.

Delight Retrieve TO CREATE A INPUT FILE WITH 25 ENTRIES AS MENTIONED IN THE Chore OR COPY THE FILE AT THE END OF THE POST

i.CODE SCREENSHOT:

1 StudentGrades.cpp X #include <iostream> two #include <string> three #include <fstream> four #include <iomanip> 5 using namespace std

ܝܟ StudentGrades.cpp 28 29 -} 30 //A function to assign the relevant grade to each student. 31 şvoid assignGrades (Student s[

J7 J7 J7 J7 ܝܟ StudentGrades.cpp X 53 /*A function to find the lowest test score. */ 54 gint findLowestscore (const Student S

} StudentGrades.cpp X 80 /*A function to print the names of student having the highest test score. */ 81 void printHighest sc

} } StudentGrades.cpp X 104 şvoid print (const Student due south[], int size) { 105 cout<<left<<setw(thirty) <<Student Name<<right<<set

130 131 132 133 134 135 136 137 138 139 printLowest Score (s, 25); writeData (out,5,25); cout<<Data is Saved into file named

2.OUTPUT:

0:1 C:\WINDOWS\system32\cmd.exe - a D:\cppsrc\FILES\StudentGrades>g++ StudentGrades.cpp D:\cppsrc\FILES\StudentGrades>a Stude

C.S. C:\WINDOWS\system32\cmd.exe-a Dorothy, Mary Margaret, Ruth Annie, Elizabeth Helen, Mary Elsie, Agnes Lillian, Julia Mild

new 1 x StudentGrades.cpp X output.txt x 1 John, Smith 56 2 Hank, Tom 97 3 David, Hoper 78 4. James, Michel 95 5 John, Frankl

3.CODE:

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
struct Student
{
cord studentFName;
cord studentLName;
int testScore;
char grade;
};
/*A function to read the students information (i.e. Names & test scores) from text file into an assortment*/
void readData(ifstream& in,Student s[],int size){
int northward=0;
while(n<size){
in>>south[n].studentLName>>s[n].studentFName>>due south[n].testScore;
northward++;
}
}
/*
A part to write educatee data (i.e. Names, examination scores, and grades) from the array to a text file.*/
void writeData(ofstream& out,Student s[],int size){
int n=0;
while(due north<size){
out<<s[n].studentLName<<", "<<s[n].studentFName<<" "<<southward[northward].testScore<<endl;
n++;
}
}
//A function to assign the relevant course to each student.
void assignGrades(Educatee due south[], int size){
int i;
for(i=0;i<size;i++)
if (south[i].testScore<60)
s[i].course='F';
else if (s[i].testScore<seventy)
s[i].grade='D';
else if (southward[i].testScore<80)
s[i].form='C';
else if(s[i].testScore<ninety)
s[i].grade='B';
else
s[i].grade='A';
}
/*A role to find the highest exam score.*/
int findHighestScore(const Educatee s[], int size){
int high=0,i;
for(i=0;i<size;i++)
if (loftier < southward[i].testScore )
loftier=s[i].testScore;
render high;
}
/*A function to detect the lowest examination score.*/
int findLowestScore(const Student due south[], int size){
int depression=100,i;
for(i=0;i<size;i++)
if (low > s[i].testScore )
low=s[i].testScore;
return low;
}
/*A function to notice the boilerplate for all test scores.*/
double calculateAverage(const Educatee s[], int size){
double sum=0;
int i;
for(i=0;i<size;i++)
sum+=s[i].testScore;
return sum/size;
}

/*A function to find the variance of test scores*/
int calculateVariance(const Educatee s[], int size){
double sum=0,avg=0,v=0;
int i;
avg=calculateAverage(s,size);
for(i=0;i<size;i++){
v+=(s[i].testScore-avg)*(s[i].testScore-avg);
}
render v/size;
}
/*A function to print the names of student having the highest examination score.*/
void printHighestScore(const Student s[], int size){
int high=0,i,hi=-1;
for(i=0;i<size;i++)
if (loftier < due south[i].testScore ){
high=south[i].testScore;
hi=i;
}
cout<<"Highest Test Score: "<<high<<endl;
cout<<"Students having the highest test score: "<<s[hullo].studentLName<<", "<<s[hi].studentFName<<endl;

}
/*A function to impress the names of student having the lowest examination score*/
void printLowestScore(const Student south[], int size){
int low=100,i,li=-1;
for(i=0;i<size;i++)
if (low > due south[i].testScore ){
low=south[i].testScore;
li=i;
}
cout<<"Highest Examination Score: "<<low<<endl;
cout<<"Students having the Lowest examination score: "<<s[li].studentLName<<", "<<southward[li].studentFName<<endl;

}
void print(const Student southward[], int size){

   cout<<left<<setw(30)<<"Student Name"<<correct<<setw(20)<<"TestScore"<<right<<setw(7)<<"Class"<<endl;
string proper name;
int high,i;
for(i=0;i<size;i++) {
name=s[i].studentLName+", "+s[i].studentFName;
cout<<left<<setw(30)<<name<<right<<setw(20)<<s[i].testScore<<correct<<setw(7)<<s[i].grade<<endl;
}
cout<<endl;
}
int main()
{
ifstream in;
ofstream out;
in.open("input.txt");
out.open("output.txt");
if(in.fail()) {
cout<<"file did non open please check it\n";
exit(0);
}
Educatee s[25];
readData(in,south,25);
assignGrades(s,25);
impress(southward,25);
cout<<"\nThe Average is:"<<calculateAverage(s,25)<<endl;
cout<<"\nThe Variance is:"<<calculateVariance(south,25)<<endl;
printHighestScore(s,25);
printLowestScore(s,25);
writeData(out,s,25);
cout<<"Data is Saved into file named 'output.txt' Successfully..."<<endl;
out.close();
in.close();
arrangement("pause");
return 0;
}

4.INPUT FILE:

input.txt:

John Smith 56
Hank Tom 97
David Hoper 78
James Michel 95
John Franklin 56
Derrick Myers 89
Mary Anna 98
Margaret Helen 85
Elsie Luky 78
Dorothy Mary 58
Margaret Ruth 77
Annie Elizabeth 45
Helen Mary 75
Elsie Agnes 35
Lillian Julia 48
Mildred Alice 65
Elizabeth Ruth 68
Frances Clara 39
Emma Anna 86
Louise Marie 95
Peter John 84
Gorge Peter 69
Sallt Bob 86
Dorothy Olga 78
Rose Sophie 79

orourkesors1954.blogspot.com

Source: https://itprospt.com/qa/21786/write-a-complete-c-program-that-reads-students

0 Response to "Write a Program That Reads Students Names Followed by Their Test Scores C++"

إرسال تعليق

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel