I need to write a student grade report using C++ classes, i am a beginner with C++.
Sample Output:
Student# Student Name Mt FL P1 P2 CP CGN CGL
-------------------------------------------------------------------------------------------------
876-54-3210 John Baker 98 92 99 98 80 94.90 A
978-34-2300 Karen Chen 85 75 98 95 99 88.50 B
345-21-0244 Pam Marange 60 65 80 50 70 64.25 D
Total number of students processed = 15
Class average for this course = 86.66
this is what i wrote so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#include <iostream>
#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();
}
|
i am getting the following error messages:
------ Build started: Project: Assignment3, Configuration: Debug Win32 ------
Compiling...
Report.cpp
..\..\..\Report.cpp(43) : error C2065: 'f1' : undeclared identifier
..\..\..\Report.cpp(43) : error C2065: 'cp' : undeclared identifier
..\..\..\Report.cpp(49) : error C2144: syntax error : 'int' should be preceded by ';'
..\..\..\Report.cpp(49) : error C2761: 'int Report::calc_grade(void)' : member function redeclaration not allowed
..\..\..\Report.cpp(50) : error C2144: syntax error : 'int' should be preceded by ';'
..\..\..\Report.cpp(50) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
..\..\..\Report.cpp(50) : error C2086: 'int course_grade' : redefinition
..\..\..\Report.cpp(49) : see declaration of 'course_grade'
..\..\..\Report.cpp(50) : error C2513: 'int' : no variable declared before '='
..\..\..\Report.cpp(50) : error C2065: 'midterm' : undeclared identifier
..\..\..\Report.cpp(50) : error C2065: 'f1' : undeclared identifier
..\..\..\Report.cpp(50) : error C2065: 'p1' : undeclared identifier
..\..\..\Report.cpp(50) : error C2065: 'p2' : undeclared identifier
..\..\..\Report.cpp(50) : error C2065: 'cp' : undeclared identifier
..\..\..\Report.cpp(51) : error C2059: syntax error : 'return'
..\..\..\Report.cpp(52) : error C2059: syntax error : '}'
..\..\..\Report.cpp(52) : error C2143: syntax error : missing ';' before '}'
..\..\..\Report.cpp(52) : error C2059: syntax error : '}'
..\..\..\Report.cpp(55) : error C2065: 'int_grade' : undeclared identifier
..\..\..\Report.cpp(56) : error C2448: 'Report::convert_grade' : function-style initializer appears to be a function definition
..\..\..\Report.cpp(73) : error C2556: 'char Report::display_result(char,int)' : overloaded function differs only by return type from 'void Report::display_result(char,int)'
..\..\..\Report.cpp(24) : see declaration of 'Report::display_result'
..\..\..\Report.cpp(73) : error C2371: 'Report::display_result' : redefinition; different basic types
..\..\..\Report.cpp(24) : see declaration of 'Report::display_result'
..\..\..\Report.cpp(87) : error C2653: 'report' : is not a class or namespace name
..\..\..\Report.cpp(89) : error C2065: 'in_file' : undeclared identifier
..\..\..\Report.cpp(102) : error C2039: 'print' : is not a member of 'Report'
..\..\..\Report.cpp(9) : see declaration of 'Report'
..\..\..\Report.cpp(102) : error C2228: left of '.heading' must have class/struct/union
..\..\..\Report.cpp(109) : error C2264: 'Report::display_result' : error in function definition or declaration; function not called
..\..\..\Report.cpp(118) : fatal error C1004: unexpected end-of-file found
Build log was saved at "file://c:\Documents and Settings\Markus\Desktop\Workspacefiles C++\Assignment3\Assignment3\Debug\BuildLog.htm"
Assignment3 - 27 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========