CODE
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int stunum;//# of students in the class
string stuname;// Name of the student
float Test1;//score for test 1
float Test2;//score for test 2
float Midterm;//score for midterm
float Final;//score for final
float Term;//score for term project
float Grade;
float NumA=0;
float NumB=0;
float NumC=0;
float NumF=0;
float Avg1;
float Avg2;
float Avg3;
float Avg4;
ifstream inFile;
ofstream outFile;
inFile.open ("ClassData.dat");
outFile.open ("ClassOutput");
inFile>>stunum;//reads in the # of students in the class
outFile<<"The # of students in the class:"<<stunum<<endl;
outFile<<setw(10)<<"Name"<<setw(10)<<"Test1"<<setw(10)<<"Test2"<<setw(10)<<"Midterm"<<setw(10)<<"Final"<<setw(14)<<"Project"<<setw(14)<<"Total Grade"<<setw(14)<<"Letter Grade"<<endl;
outFile<<& #34;****************************************************************************
****************"<<endl;
for (int j=0; j<stunum; j++)
{
inFile>>stuname>>Test1>>Test2>>Midterm>>Final>>Term;
Avg1=((Test1+Test2)/2*(.2));//Calculate average test score
Avg2=(Midterm*(.25));//Calculate average midterm score
Avg3=(Final*(.3));//calculate the final
Avg4=(Term*(.25));
Grade= Avg1+Avg2+Avg3+Avg4;
outFile<<setw(10)<<stuname<<setw(10)<<Test1<<setw(10)<<Test2<<setw(10)<<Midterm<<setw(10)<<Final<<setw(14)<<Term<<setw(14)<<Grade;
if(Grade>=90)
{
outFile<<setw(15)<<" A "<<endl;
NumA++;
}
else if (Grade>=80)
{
outFile<<setw(15)<<" B "<<endl;
NumB++;
}
else if (Grade>=70)
{
outFile<<setw(15)<<" C "<<endl;
NumC++;
}
else if (Grade<70)
{
outFile<<setw(15)<<" F "<<endl;
NumF++;
}
}
outFile<<endl<<endl;
outFile<<"The # of A's: "<<NumA<<endl;
outFile<<"The # of B's: "<<NumB<<endl;
outFile<<"The # of C's: "<<NumC<<endl;
outFile<<"The # of F's: "<<NumF<<endl;
inFile.close();
outFile.close();
return 0;
}
My assignment is as follws:
Accounting teachers, being naturally inept with numbers, have a difficult time calculating students’ averages and assigning letter grades at the end of each semester. Your accounting teacher is no exception. To make this end of semester grading easier, and more accurate, he hires you to write a program (C++) to automate the task. There are a variable number of students in his class, with each students grade being calculated as follows:
2 Tests 10% each
Midterm Exam 25%
Final Exam 30%
Term Project 25%
Input data is stored in a file named ClassData.dat. The first line in the input file has the number of students in the class. Each subsequent line contains one student’s Lastname, test-scores, exam scores and project score. Your program should begin by reading the number of students in the class, and then for each student, read the student’s name and test, exam and project scores. The program should then calculate the student’s average and assign him/her a letter grade (“A” for 90-100; “B” for 80-89; “C” for 70-79; and “F” for 69 and below). Finally, for each student, the program should print, to output file, his/her name, average, and grade.
Once all students have been processed, the program should print a summary report stating the number of “A”s, “B”’s, “C”’s and “F”’s assigned.
----------------------------------------------------------------------------------
I've created a Text file using notepad with the following data(grades are in %):
10
Gayle 86 88 92 96 78
Brown 47 40 57 29 49
Byles 61 49 28 52 71
Holst 71 82 78 70 69
Welsh 71 54 55 80 68
Hamms 93 77 86 74 84
Ellis 88 96 80 87 73
Spear 100 100 85 88 91
Wilks 48 53 62 74 75
Bolop 65 74 73 82 51
------------------------------------------------------------------------------------
How do i change this program(which works) into a program that has functions?