Program in C++ Write a program that prints out a student grade report. There is
ID: 3777690 • Letter: P
Question
Program in C++
Write a program that prints out a student grade report. There is a file, classes, txt, that contains the names of all classes taught at a college, such as CSC1 CSC2 CSC46 CSC151 MTH121 ... For each class, there is a file with student numbers and grades: 11234 A- 12547 B 16753 B+ 21886 C ... Write a program that asks for a student ID and prints out a grade report for that student, by searching all class files. Here is a sample report Student ID 16753 CSC2 B+ MTH121 C+ CHN1 A PHY50 A-Explanation / Answer
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;
class Report
{
private:
char id [12];
char name [20];
double midterm, final, p1, p2, p3;
ifstream in_file;
public:
Report ();
~Report ();
void print_heading();
void read_input();
int calc_grade();
char convert_grade(int);
void display_result(char, int);
ifstream & get();
};
Report::Report()
{ in_file.open ("C://Documents and Settings//Markus//Desktop//P3_input.DAT");
if (!in_file)
{
cerr<<"Error:File could not be opened"<<endl;
cerr<<"Program terminating"<<endl;
exit(1);
}
void Report::read_input()
{
in_file.getline(id, 12);
in_file.getline(name, 20);
in_file>>midterm>>f1>>p1>>p2>>cp;
in_file.get();
};
int Report::calc_grade()
int course_grade;
course_grade int=(midterm*0,25+f1*0,25+p1*0,20+p2*0,20+cp*0,10);
return course_grade;
};
char Report::convert_grade(int_grade)
{
if (grade>=90&&grade<=100)
return 'A';
else if (grade>=80&&grade<90)
return 'B';
else if (grade>=70&&grade<80)
return 'C';
else if (grade>=60&&grade<70)
return 'D';
else if (grade>=50&&grade<60)
return 'E';
else if (grade>=40&&grade<=50)
return 'F';
};
char Report::display_result (char letter, int grade)
{
cout << setw(5)<< "Student#" << setw(15) << "Student Name" << setw(5) << "MT" << setw(5) << "FL"
<< setw(5) << "P1" << setw(5) << "P2" << setw(5) << "CP" << setw(5)<< "CGN" << setw (5)<< "CGL"<<endl;
cout<<"-----------------------------------------------------------------------------------------"<<
cout<< setw(12)<<id<<setw(20)<<name<<setw(3)<<midterm<<setw(3)<<final<<setw(3)<<p1<<setw(3)<<p2<<
setw(3)<<course_grade<<setw(3)<<grade<<endl;
};
ifstream&report::get()
{
return in_file;
}
Report::~Report()
{
in_file.close();
}
int main()
{
int grade;
char letter;
Report s1;
s1.print.heading();
ifstream&read_file=s1.get();
s1.read_input();
while (!read_file.eof());
{
grade=s1.calc_grade();
letter=s1.convert_grade(grade);
s1.display_result (letter, grade);
s1.read_input();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.