In: Computer Science
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int QUIZSIZE = 10;
const int LABSIZE = 10;
const int PROJSIZE = 3;
const int EXAMSIZE = 3;
float getAverage(float arr[], int size)
{
float total = 0;
for (int i = 0; i < size; i++)
{
total += arr[i];
}
return total/size;
}
// the following main function do....
int main()
{
ifstream dataIn;
string headingLine;
string firstName, lastName;
float quiz[QUIZSIZE];
float lab[LABSIZE];
float project[PROJSIZE];
float midExam[EXAMSIZE];
float finalExam;
float attendance;
// open the file
dataIn.open("grade120.dat");
//exception for file open
if (dataIn.fail())
{
cout << "File open error!" << endl;
return 0;
}
// read the first two lines
for (int i = 1; i <= 2; i++)
{
getline(dataIn,headingLine);
cout << headingLine << endl;
}
while (!dataIn.eof())
{
//read student's score from the file
dataIn >> firstName;
dataIn >> lastName;
for (int i = 0; i < QUIZSIZE; i++)
{
dataIn >> quiz[i];
}
for (int i = 0; i < LABSIZE; i++)
{
dataIn >> lab[i];
}
for (int i = 0; i < PROJSIZE; i++)
{
dataIn >> project[i];
}
for (int i = 0; i < EXAMSIZE; i++)
{
dataIn >> midExam[i];
}
dataIn >> finalExam;
dataIn >> attendance;
cout << "Average quiz is " << getAverage(quiz,QUIZSIZE)
<< endl;
cout << "Average lab is " << getAverage(lab,LABSIZE)
<< endl;
// call another function to calculate the final greade letter
//write the name + letter to a file
dataIn.close();
return 0;
}
Finish the C++ program below based on
(0 <= F < 60, 60 <= D < 70, 70 <= C< 80, 80 <= B < 90, 90 <= A <= 100)
THE RULES: · You need to have a total grade >=90 and average in projects >= 90 to get an A; · You need to have a total grade >=80 and < 90, and average in projects >=80 to get a B; · You need to have a total grade is >=70 and < 80, and average in projects >=70 to get a C. Poor attendance will be penalized by up to 10% of the final total grade. The grades of all the students and attendance
penalty are stored in an external file called grade120.dat. which will be given
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
The out put must be
First Name Last Name Final Grade
Nick Johnson A
Anne Lewis B
finish the program please
Please find below modified JAVA program. I have added the function to return the grade as per the total grade & average in projects.
#include < iostream >
#include < fstream >
#include < string >
using namespace std;
const int QUIZSIZE = 10;
const int LABSIZE = 10;
const int PROJSIZE = 3;
const int EXAMSIZE = 3;
float
getAverage(float arr[], int size) {
float total = 0;
for (int i = 0; i < size; i++) {
total += arr[i];
}
return total / size;
}
char
getGrade(float quiz, float lab) {
char grade;
if (quiz > 90 && lab > 90) grade = 'A';
else if (quiz >= 80 && quiz < 90 && lab >= 80) grade = 'B';
else if (quiz >= 70 && quiz < 80 && lab >= 70) grade = 'C';
else if (quiz >= 60 && quiz < 70 && lab >= 60) grade = 'D';
else grade = 'F';
return grade;
}
int
main() {
ifstream dataIn;
string headingLine;
string firstName,
lastName;
float quiz[QUIZSIZE];
float lab[LABSIZE];
float project[PROJSIZE];
float midExam[EXAMSIZE];
float finalExam;
float attendance;
dataIn.open("grade120.dat");
if (dataIn.fail()) {
cout << "File open error!" << endl;
return 0;
}
for (int i = 1; i <= 2; i++) {
getline(dataIn, headingLine);
cout << headingLine << endl;
}
while (!dataIn.eof()) {
dataIn >> firstName;
dataIn >> lastName;
for (int i = 0; i < QUIZSIZE; i++) {
dataIn >> quiz[i];
}
for (int i = 0; i < LABSIZE; i++) {
dataIn >> lab[i];
}
for (int i = 0; i < PROJSIZE; i++) {
dataIn >> project[i];
}
for (int i = 0; i < EXAMSIZE; i++) {
dataIn >> midExam[i];
}
dataIn >> finalExam;
dataIn >> attendance;
float avgQuiz = getAverage(quiz, QUIZSIZE);
float avgLab = getAverage(lab, LABSIZE);
cout << "Average quiz is " << avgQuiz << endl;
cout << "Average lab is " << avgLab << endl;
// call another function to calculate the final greade letter
char grade = getGrade(avgQuiz, avgLab);
//write the name + letter to a file
cout << firstName << " " << lastName << " " << grade << endl;
}
dataIn.close();
return 0;
}
Hope it helps. Thanks!