Hi I have to write a Program on C++ using this skeleton. #include <iostream> #in
ID: 3888816 • Letter: H
Question
Hi I have to write a Program on C++ using this skeleton.
#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
example output
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<iostream>
#include<fstream>
using namespace std;
void printFileToScreen();
int main(){
string name;
string class_deg;
int n;
ofstream fout;
int gr = 0;
int sum1 = 0;
int sum2 = 0;
int average = 0;
char grade;
int countC= 0;
int countA = 0;
int countB = 0;
int countD = 0;
int countF = 0;
int j;
double avg;
fout.open("class_statistics.txt");
cout << "Enter Teacher's name :";
getline(cin,name);
fout << "Teacher: " << name << endl;
cout << "Enter class designtion :";
getline(cin,class_deg);
fout << "Class:" << class_deg << endl;
cout << "Enter number of students :";
cin >> n;
fout <<"Student Name:";
sum1 = 0;
sum2 = 0;
for (int i = 0; i<n; i++){
cin.ignore();
cout << "Enter students name:";
getline(cin,name);
if (i == 0)
fout << name;
else
fout << " " << name;
sum1 = 0;
gr = 0;
cout << "Enter grades or 999 to quit " << endl;
for (j = 0; j<10 ; j++){
cin >> gr;
if (gr == 999)
break;
else
sum1 = sum1 + gr;
}
avg = sum1/(j+1);
if (avg >= 90 && avg <=100){
grade = 'A';
countA++;
}
if (avg >= 80 && avg <90){
grade = 'B';
countB++;
}
if (avg >= 70 && avg <80){
grade = 'C';
countC++;
}
if (avg >= 60 && avg <70){
grade = 'D';
countD++;
}
if ( avg <60){
grade = 'F';
countF++;
}
if (i == 0)
fout << " " << "Average:" << avg << " " << "Grade: " << grade << endl;
else
fout << " " << " " << avg << " " << " " << grade << endl;
sum2 = sum2 + avg;
}
fout << "Student Count : " << n << endl;
fout << "Student average : " << sum2/n << endl;
fout << "As:"<<countA << endl;
fout << "Bs:"<<countB << endl;
fout << "Cs:"<<countC << endl;
fout << "Ds:"<<countD << endl;
fout << "Fs:"<<countF << endl;
fout.close();
printFileToScreen();
}
void printFileToScreen()
{
ifstream inData;
string line = "";
inData.open("class_statistics.txt");
while(inData)
{
getline(inData,line);
cout << line << endl;
}
inData.close();
}