Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete C++ program that reads a student\'s name and test scores from a

ID: 3539439 • Letter: W

Question

Write a complete C++ program that reads a student's name and test scores from a file. Do not use any global data except for any constant values you may need and your file stream variables.

1. Create a datafile that contains (at least) the following data:

Johnson 85 83 77 91 76

Aniston 80 90 95 93 48

Cooper 78 81 11 90 73

Gupta 92 83 30 69 87

Blair 23 45 96 38 59

Clark 60 85 45 39 67

Kennedy 77 31 52 74 83

You may add additional records of data for testing if you wish. Your program should work for any number of records added to the file.

2. Write a program that reads and processes the student name and exam scores. The program should calculate the average test score for each student, and assign each student an appropriate letter grade as follows: A= 90-100; B= 80-89; C= 70-79; D= 60-69; F= 59 or below. For output the program will print each student's name, average, and letter grade. In addition, as you process student records, accumulate and find the overall class average, and the total number of A, B, C, D, and F letter grades assigned in the class.

3. Your program must use the following functions :

Include your first and last name as the first line of all of your program outputs.

Explanation / Answer

#include<iostream>
#include<fstream>
using namespace std;
void initialize(int& no_of_students,int& total_score,int grade_count[6])
{
no_of_students = 7;
total_score = 0;
for(int i=0; i<6;i++)
grade_count[i] = 0;
}
double calculateAverage(int a[],int k)
{
double sum =0;
for(int i=0; i<k; i++)
sum+= a[i];
return sum/static_cast<double> (k);
}
char determineGrade(double avg)
{
if(avg>=90 && avg<=100)
return 'A';
else if(avg>=80 && avg<=89)
return 'B';
if(avg>=70 && avg<=79)
return 'C';
if(avg>=60 && avg<=69)
return 'D';
if(avg>=50 && avg<=59)
return 'E';
return 'F';
}
void printStudent(string name[7],double avg[7],char grade[7])
{
for(int i=0; i<7; i++)
cout << "Student name " << name[i] << " average is " << avg[i] << " Grade is " << grade[i] << endl;
}
void countGrade(char grade,int grade_count[])
{
grade_count[grade-'A']++;
}
int main()
{
int no_of_students;
int total_score;
int grade_count[6];
char grade[7];
double avg[7];
string name[7];
int scores[7][5];
initialize(no_of_students,total_score,grade_count);
ifstream infile("input.txt");
int i=0;
int j=0;
while(!infile.eof())
{
infile >> name[i];
for(int j=0; j<5; j++)
infile >> scores[i][j];
i++;
}
for(i=0; i<7; i++)
{
avg[i] = calculateAverage(scores[i],5);
grade[i] = determineGrade(avg[i]);
}

printStudent(name,avg,grade);
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote