i am working on this program for a while need some help/input/miracle....
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <iostream>
using namespace std;
class Report
{
private:
char id [12];
char name [20];
double midterm, f1, p1, p2, p3,cp;
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';
}
void 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)<<f1<<setw(3)<<p1<<setw(3)<<p2<<
//setw(3)<<letter<<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();
cout<<setw(3)<<letter<<setw(3)<<grade<<endl;
}
return 0;
}
this is the error message:
------ Build started: Project: 3, Configuration: Debug Win32 ------
Linking...
3.obj : error LNK2028: unresolved token (0A000339) "public: void __thiscall Report::print_heading(void)" (?print_heading@Report@@$$FQAEXXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
3.obj : error LNK2019: unresolved external symbol "public: void __thiscall Report::print_heading(void)" (?print_heading@Report@@$$FQAEXXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
C:\Documents and Settings\Markus\Desktop\Workspacefiles C++\3\Debug\3.exe : fatal error LNK1120: 2 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Markus\Desktop\Workspacefiles C++\3\3\Debug\BuildLog.htm"
3 - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
wrote a second one and have other problems:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;
class Report
{
private:
char id [12];
char name [20];
double midterm, final,f1, p1, p2, p3,cp;
ifstream in_file;
public:
Report ();
~Report ();
int print_heading();
void read_input();
int calc_grade();
int course_grade();
char convert_grade(int);
void display_result();
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)
{
int course_grade;
if (course_grade>=90&&grade<=100)
return 'A';
else if (course_grade>=80&&grade<90)
return 'B';
else if (course_grade>=70&&grade<80)
return 'C';
else if (course_grade>=60&&grade<70)
return 'D';
else if (course_grade>=50&&grade<60)
return 'E';
else if (course_grade>=40&&grade<=50)
return 'F';
}
void Report::display_result ()
{
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<<"-----------------------------------------------------------------------------------------"<<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();
cout<<setw(3)<<letter<<setw(3)<<grade<<endl;
}
}
error message:
------ Build started: Project: Assignment3, Configuration: Debug Win32 ------
Compiling...
Report.cpp
..\..\..\Report.cpp(103) : error C2039: 'print' : is not a member of 'Report'
..\..\..\Report.cpp(10) : see declaration of 'Report'
..\..\..\Report.cpp(103) : error C2228: left of '.heading' must have class/struct/union
..\..\..\Report.cpp(110) : error C2660: 'Report::display_result' : function does not take 2 arguments
Build log was saved at "file://c:\Documents and Settings\Markus\Desktop\Workspacefiles C++\Assignment3\Assignment3\Debug\BuildLog.htm"
Assignment3 - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========