I have to do the program below using this skeleton , can you help me? #include <
ID: 3668829 • Letter: I
Question
I have to do the program below using this skeleton , can you help me?
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void printFileToScreen();
int main()
{
//close the input file here
printFileToScreen();
return 0;
}
void printFileToScreen()
{
ifstream inData;
string line = "";
inData.open("class_statistics.txt");
while(inData)
{
getline(inData,line);
cout << line<< endl;
}
inData.close();
}
Create a program to handle a college class grades:
Capture the Teacher's name
Capture the Class designation
The program should ask how many students are in the class and do the following for each student:
Read the students name
Read in up to 10 grades for the student (from 0 - 100 is acceptable. If outside the range don't use the input, ask for a correction , 999 should stop input of grades if there are less than 10)
Calculate the average of the student's grades
Compute the student's grade as a letter grade
For the entire class
Compute the class's grade average
Determine how many A's, B's, C's, D's and F's are in the class.
Write the following data to a file called class_statistics.txt
Teacher: Bob Marley
Class: CGS1010
Student Name: Jim Beam Average: 88 Grade: B
Donna Jenner 95 A
Student count: 2
Student average: 91.5
A's: 1
B's: 1
C's: 0
D's: 0
F's: 0
Explanation / Answer
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void printFileToScreen();
char grade(float marks){
if(marks >=90)
return 'A';
else if(marks >=80)
return 'B';
else if(marks >=70)
return 'C';
else if(marks >=60)
return 'D';
else
return 'A';
}
int main()
{
//close the input file here
printFileToScreen();
cout<<"Data Saved Successfully!!!";
return 0;
}
void printFileToScreen()
{
char data[100];
int n;
float average;
float total = 0;
int k = 0;
float marks;
float totalAll = 0;
int a=0,b=0,c=0,d=0,f=0;
// open a file in write mode.
ofstream outfile;
outfile.open("class_statistics.txt");
cout << "Writing to the file" << endl;
cout << "Enter Teacher name: ";
cin.getline(data, 100);
// write inputted data into the file.
outfile <<"Teacher:"<<data << endl;
cout << "Enter Class name: ";
cin.getline(data, 100);
outfile <<"Class:"<<data << endl;
cout<<"Enter number of students: ";
cin>>n;
for(int i=1;i<=n;i++){
k = 0;
total = 0;
cout<<"Enter name of "<<i<<" student: ";
cin.ignore();
cin.getline(data, 100);
cout<<"Enter at most 10 grades of "<<i<<" student:[999 to stop] ";
for(int j=0; j<10;j++){
cin>>marks;
if(marks == 999)
break;
total = total + marks;
k++;
}
average = double(total)/k;
totalAll = totalAll + average;
char g = grade(average);
if(g=='A')
a++;
else if(a=='B')
b++;
else if(g=='C')
c++;
else if(g=='D')
d++;
else
f++;
outfile <<"Student Name:"<<data<<" ";
outfile <<"Averag: "<<average<<" ";
outfile <<"Grade: "<<g<<endl;
}
outfile <<"Student Count:"<<n<<endl;
outfile <<"Student Average:"<<double(totalAll)/n<<endl;
outfile <<"A':"<<a<<endl;
outfile <<"B':"<<b<<endl;
outfile <<"C':"<<c<<endl;
outfile <<"D':"<<d<<endl;
outfile <<"F':"<<f<<endl;
outfile.close();
}