IN C++ You are to write a program that uses arrays to process the following data
ID: 3805666 • Letter: I
Question
IN C++
You are to write a program that uses arrays to process the following data:
Name Exam1 Exam2 Exam3
John 90.9 69.9 60.0
Jane 87.0 71.0 91.0
Bill 95.5 80.7 88.0
Susan 75.0 75.1 80.0
Create the following report to a file named initialGrades.txt:
Name
Exam1
Exam2
Exam3
TotaOfScores
AverageScore
John
90.9
69.9
60.0
220.8
73.6
Jane
87.0
71.0
91.0
249.0
83.0
Bill
95.5
80.7
88.0
264.2
88.1
Susan
75.0
75.1
80.0
230.1
76.7
AverageTestScore
87.1
74.2
79.8
241.0
80.3
Prompt for an exam to change and a percentage increase.
Test you program using an Increase of 10% on Exam2 and output the revised report to revisedGrades.txt
Submit your source Lab6.cpp file, your initial.Grades.txt and revisedGrades.txt to Catalyst
Note, you may input the initial data from a file or using console input. Report the data as real numbers and 1 decimal place
Name
Exam1
Exam2
Exam3
TotaOfScores
AverageScore
John
90.9
69.9
60.0
220.8
73.6
Jane
87.0
71.0
91.0
249.0
83.0
Bill
95.5
80.7
88.0
264.2
88.1
Susan
75.0
75.1
80.0
230.1
76.7
AverageTestScore
87.1
74.2
79.8
241.0
80.3
Explanation / Answer
#include<iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main() {
int count;
cout<<"Enter number of students";
cin>>count;
char name[count][50];
float marks1[count];
float marks2[count];
float marks3[count];
float total[count];
float avgMarks1 = 0;
float avgMarks2 = 0;
float avgMarks3 = 0;
float avgTotal = 0;
for (int i = 0; i < count; i++) {
cout<<"Enter name of student "<<(i+1)<<": ";
cin>>name[i];
cout<<"Enter Exam 1 marks of student "<<(i+1)<<": ";
cin>>marks1[i];
cout<<"Enter Exam 2 marks of student "<<(i+1)<<": ";
cin>>marks2[i];
cout<<"Enter Exam 3 marks of student "<<(i+1)<<": ";
cin>>marks3[i];
total[i] = marks1[i] + marks2[i] + marks3[i];
avgMarks1 += marks1[i];
avgMarks2 += marks2[i];
avgMarks3 += marks3[i];
avgTotal += total[i];
}
avgMarks1 /= count;
avgMarks2 /= count;
avgMarks3 /= count;
avgTotal /= count;
ofstream initialfile("initialGrades.txt");
if (initialfile.is_open()) {
initialfile << fixed;
initialfile << setprecision(1);
initialfile << "Name Exam1 Exam2 Exam3 TotaOfScores AverageScore ";
for (int i = 0; i < count; i++) {
initialfile << name[i]<<" "<<marks1[i]<<" "<<marks2[i]<<" "<<marks3[i]<<" "<<total[i]<<" "<<(total[i]/3)<<" ";
}
initialfile<<" ";
initialfile<<"AverageTestScore "<<avgMarks1<<" "<<avgMarks2<<" "<<avgMarks3<<" "<<avgTotal<<" "<<(avgTotal/3)<<" ";
initialfile.close();
}
else
cout << "Unable to open file";
int examchange;
double percent;
cout<<"change for exam: ";
cin>>examchange;
cout<<"percentage increase: ";
cin>>percent;
avgTotal = 0;
for (int i = 0; i < count; i++) {
if (examchange==1){
marks1[i] = marks1[i]*(1+percent/100);
total[i] = marks1[i]+marks2[i]+marks3[i];
avgTotal += total[i];
}
if (examchange==2){
marks2[i] = marks2[i]*(1+percent/100);
total[i] = marks1[i]+marks2[i]+marks3[i];
avgTotal += total[i];
}
if (examchange==3){
marks3[i] = marks3[i]*(1+percent/100);
total[i] = marks1[i]+marks2[i]+marks3[i];
avgTotal += total[i];
}
}
if (examchange==1){
avgMarks1 = avgMarks1 *(1+percent/100);
}
if (examchange==2){
avgMarks2 = avgMarks2*(1+percent/100);
}
if (examchange==3){
avgMarks3 = avgMarks3*(1+percent/100);
}
avgTotal /= count;
initialfile.open("revisedGrades.txt");
if (initialfile.is_open()) {
initialfile << fixed;
initialfile << setprecision(1);
initialfile << "Name Exam1 Exam2 Exam3 TotaOfScores AverageScore ";
for (int i = 0; i < count; i++) {
initialfile << name[i]<<" "<<marks1[i]<<" "<<marks2[i]<<" "<<marks3[i]<<" "<<total[i]<<" "<<(total[i]/3)<<" ";
}
initialfile<<" ";
initialfile<<"AverageTestScore "<<avgMarks1<<" "<<avgMarks2<<" "<<avgMarks3<<" "<<avgTotal<<" "<<(avgTotal/3)<<" ";
initialfile.close();
}
else
cout << "Unable to open file";
}
initialMarks:
Name Exam1 Exam2 Exam3 TotaOfScores AverageScore
John 90.9 69.9 60.0 220.8 73.6
Jane 87.0 71.0 91.0 249.0 83.0
Bill 95.5 80.7 88.0 264.2 88.1
Susan 75.0 75.1 80.0 230.1 76.7
AverageTestScore 87.1 74.2 79.8 241.0 80.3
revisedGrades:
Name Exam1 Exam2 Exam3 TotaOfScores AverageScore
John 90.9 76.9 60.0 227.8 75.9
Jane 87.0 78.1 91.0 256.1 85.4
Bill 95.5 88.8 88.0 272.3 90.8
Susan 75.0 82.6 80.0 237.6 79.2
AverageTestScore 87.1 81.6 79.8 248.4 82.8