In: Computer Science
First Last Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 L0 L1 L2 L3 L4 L5 L6 L7
L8 L9 P0 P1 P2 E0 E1 E2 FI ATT
------------------------------------------------------------------------------------------------------------------------------------------
Kevin Smith 90 100 100 100 98 97 87 100 85 87 89 100 100 100 100 90
100 98 90 100 98 98 98 90 90 98 88 0.00
Morgan Kelly 80 100 65 67 69 71 100 100 100 67 95 85 87 89 100 65
67 69 71 100 98 98 98 65 67 69 71 0.10
Isaac Newton 100 90 100 90 100 90 100 90 100 100 100 100 100 100
100 100 100 100 100 100 98 98 98 90 90 98 88 0.00
Cole Jones 100 100 100 87 73 75 77 79 81 87 89 91 73 75 77 79 81
100 100 100 98 100 65 67 69 71 63 0.05
Angela Allen 100 100 100 87 89 91 93 95 100 100 100 100 100 100 100
95 97 100 98 98 98 90 73 75 77 79 81 0.02
David Cooper 56 58 60 62 64 100 100 100 87 73 75 77 100 100 77 79
81 100 100 100 98 70 72 74 76 78 88 0.00
Nancy Bailey 100 87 89 91 93 95 100 100 100 100 100 100 91 93 95 97
100 98 100 100 98 98 98 90 90 98 88 0.00
Emily Synder 65 67 69 71 62 64 73 75 77 58 60 62 79 66 68 70 72 81
74 76 78 90 90 74 76 98 88 0.00
Lori Austin 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 98 98 98 90 90 98 88 0.02
Jenny Howard 56 58 60 62 71 62 64 73 100 66 68 70 72 74 76 78 100
100 100 60 62 79 66 68 70 68 70 0.03
Anne Lewis 100 86 58 60 100 71 62 64 73 94 66 68 90 72 74 76 78 67
68 69 70 71 98 88 76 78 68 0.04
Nick Johnson 100 100 89 91 73 75 77 79 81 100 100 100 98 100 100 95
85 87 89 100 98 98 98 80 76 78 98 0.01
Nick Spickler 100 93 95 97 100 98 98 98 90 100 89 91 93 95 97 100
100 89 91 93 95 97 98 98 90 90 98 0.00
Joy Williams 75 77 58 60 62 79 66 68 70 72 81 100 100 71 62 64 73
94 66 98 90 90 98 68 90 88 77 0.00
Barbara Hood 100 67 95 85 87 89 91 93 95 97 85 87 100 100 100 71 62
64 73 94 66 68 98 98 90 90 88 0.00
Joe Hoarn 62 63 64 65 66 67 68 69 70 71 100 81 100 100 71 62 64 73
100 100 98 98 64 73 94 66 68 0.08
Payton Bardzell 100 100 100 97 87 67 95 85 87 89 91 93 95 97 100
100 100 95 85 87 89 100 98 90 90 78 98 0.00
Kim Ludwig 71 62 64 73 75 77 58 60 62 79 66 68 70 72 81 100 100 79
66 68 70 72 98 98 90 90 98 0.09
Susan Honks 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 90 90 88 100 100 100 100 0.00
Write the program in C++ read the grades of all the students from the file above. For each student’s scores,
The program most be define arrays to keep scores for quizzes, labs, projects, midterms. Secondly, read in the grades for each student and define a function to calculate and return the average grade of quizzes, labs, projects and midterms. Sample prototype of this function: float getAverage(float gradeArray[], int arraySize); // a function to calculate average of array. Also, define a function to calculate and return the final letter grade of this student. Note the total grade, average project grade, and the attendance will be taken into consideration when the final grade is calculated. Last importantly, output this student’s first name, last name, and final letter grade in a nice format to a file named letter120.dat. Each student’s data is in one line. This file should be in the same location as data that is given from the above file. The format should be as following:
First Name Last Name Final Grade
Nick Johnson A
Anne Lewis B
Writing the program in C++ beginners
Use constants to keep the percentage values in the above table.
COMMENT YOUR CODE.
Give meaningful variable, array, and function names based on this program.
Arrays and functions are implemented properly.
The grade is calculated correctly and output file is generated properly.
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
//variables declaration
string word;
string heading[50];
string f_name[50],l_name[50];
string u_line;
int l_index=0,q_index=0,p_index=0,e_index=0;
float l[50][50],p[50][50],q[50][50],e[50][50],f[50],att[50];
int count=0,linecount=0,k;
//function prototype for two functions
char getGrade(float num);
float getAverage(float getAverage[50][50] , int);
int main()
{
float sum;
ifstream f1;
//open file in read mode
f1.open("input.dat");
while (f1 >> word)
{
//first two lines needs to skipped hence linescount is
checked
if(linecount<1)
{
if(count%30==29)
{
linecount++;
}
heading[count]=word;
count++;
}
else if(linecount==1)
{
u_line=word;
linecount=2;
}
//for every word both line and count is checked and value is
inserted to the correspondin array
else if(linecount>1)
{
if(count%30==0)
{
f_name[linecount-2]=word;
}
else if(count%30==1)
{
l_name[linecount-2]=word;
}
else if(count%30>=2 && count%30<=11)
{
//string to float conversion
float x=std::stof(word);
q[linecount-2][q_index]=x;
q_index++;
}
else if(count%30>=12 && count%30<=21)
{
float x=std::stof(word);
l[linecount-2][l_index]=x;
l_index++;
}
else if(count%30>=22 && count%30<=24)
{
float x=std::stof(word);
p[linecount-2][p_index]=x;
p_index++;
}
else if(count%30>=25 && count%30<=27)
{
float x=std::stof(word);
e[linecount-2][e_index]=x;
e_index++;
}
else if(count%30==28)
{
float x=std::stof(word);
f[linecount-2]=x;
}
else if(count%30==29)
{
//count = 29 means the last word of the line hence line count is
incremented
float x=std::stof(word);
att[linecount-2]=x;
l_index=0;
q_index=0;
p_index=0;
e_index=0;
linecount++;
}
count++;
}
}
f1.close();
//opens the next file in write mode
std::ofstream f2;
f2.open("letter120.dat");
//writes the headings to file
f2<<setw(25)<<left<<"First Name
"<<setw(25)<<left<<"Last
Name"<<setw(25)<<left<<"Final
Grade"<<endl;
//displays headings for output window
cout<<setw(15)<<left<<"First Name
"<<setw(15)<<left<<"Last
Name"<<setw(15)<<left<<"Quiz Grade"
<<setw(15)<<left<<"Project
Grade"<<setw(15)<<left<<"labs
Grade"<<setw(15)<<left<<"Mid-term
Grade"<<endl;
//function calling for each students details are done here
for(k=0;k<linecount-2;k++)
{
cout<<setw(15)<<left<<f_name[k]<<setw(15)<<left<<l_name[k]<<setw(15)<<left<<getGrade(getAverage(q,10))
<<setw(15)<<left<<getGrade(getAverage(p,3))<<setw(15)<<left<<getGrade(getAverage(l,10))<<setw(15)<<left<<getGrade(getAverage(e,3))<<endl;
//here final grade is calculated by adding all scores and finds its
average then attendence is substracted
sum=getAverage(q,10)+getAverage(l,10)+getAverage(p,3)+getAverage(e,3)+f[k]-att[k];
f2<<setw(25)<<left<<f_name[k]<<setw(25)<<left<<l_name[k]<<setw(25)<<left<<getGrade(sum/5)<<std::endl;
}
f2.close();
return 0;
}
float getAverage(float gradeArray[][50],int n )
{
float a_sum=0;
for(int i=0;i<n;i++)
{
a_sum=a_sum+gradeArray[k][i];
}
return (a_sum/n);
}
char getGrade(float num)
{
if(num>=90 && num <=100)
return 'A';
else if(num>=80 && num<=89)
return 'B';
else if(num>=70 && num<=79)
return 'C';
else if(num>=60 && num<=69)
return 'D';
else if(num>=50 && num<=59)
return 'E';
else if(num>=49)
return 'F';
}
OUTPUT
First Name Last Name Quiz Grade Project Grade labs Grade
Mid-term Grade
Kevin Smith A A A A
Morgan Kelly B A B D
Isaac Newton A A A A
Cole Jones B B B D
Angela Allen A B A C
David Cooper C B B C
Nancy Bailey A A A A
Emily Synder D B C B
Lori Austin A A A A
Jenny Howard D D F D
Anne Lewis C F C B
Nick Johnson B A A C
Nick Spickler A A A A
Joy Williams D A B B
Barbara Hood F C B A
Joe Hoarn D B B C
Payton Bardzell A A A B
Kim Ludwig D B C A
Susan Honks A F A A
OUTPUT FILE
First Name Last Name Final Grade
Kevin Smith A
Morgan Kelly B
Isaac Newton A
Cole Jones C
Angela Allen B
David Cooper B
Nancy Bailey A
Emily Synder F
Lori Austin A
Jenny Howard C
Anne Lewis C
Nick Johnson A
Nick Spickler A
Joy Williams B
Barbara Hood B
Joe Hoarn C
Payton Bardzell A
Kim Ludwig B
Susan Honks A