Hello everyone I am currently working on a program that will take a crap load of information from a file and save it to a database within a class.
Essentially i have everything set up correctly except for the hard part... I have to calculate the GPA for a spring semester... if the student is even taking classes in the spring (this is found as to whether or not fGPA.noCo = 0. Calculate that gpa and then average it with the GPA before the semester.
I am having trouble with the
UpdateGPA and GenerateReport functions.
I also have these current compiler errors however I am more worred about the actual task at hand as I can figure out the compiler errors later. Please keep in mind that I am very new at working structs and ESPECIALLY classes. Any help would be great. Thanks so much!
1>------ Build started: Project: hw2, Configuration: Debug Win32 ------
1>Compiling...
1>hw2.cpp
1>c:\users\doug\documents\visual studio 2008\projects\hw2\hw2\hw2.cpp(159) : warning C4101: 'choice' : unreferenced local variable
1>c:\users\doug\documents\visual studio 2008\projects\hw2\hw2\hw2.cpp(222) : error C2668: 'UpdateGPA' : ambiguous call to overloaded function
1> c:\users\doug\documents\visual studio 2008\projects\hw2\hw2\hw2.cpp(99): could be 'void UpdateGPA(StudRecType)'
1> c:\users\doug\documents\visual studio 2008\projects\hw2\hw2\hw2.cpp(93): or 'void UpdateGPA(StudRecType &)'
1> while trying to match the argument list '(StudRecType)'
1>Build log was saved at "file://c:\Users\Doug\Documents\Visual Studio 2008\Projects\hw2\hw2\Debug\BuildLog.htm"
1>hw2 - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Code:
// Example for reading records from the input files for DB.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int Max_Stud = 30; //Max. no. of enrolled students
struct NameType
{
string last;
string first;
char middle;
};
struct CourseType
{
string name;
char grade;
int credits;
};
struct StudRecType
{
string ssno;
NameType name;
string tel;
char gender;
string level;
int totalCredit;
float cumGPA;
int noCo;
CourseType course[5];
int semCredit;
float semGPA;
};
typedef StudRecType StudDBType[Max_Stud];
// Type definition for an array of records
class DBType
{
public:
DBType( );
void Insert(StudRecType );
bool GetNext(StudRecType &);
void Reset( );
private:
StudDBType Stud;
int current;
int nost;
};
DBType::DBType( )
{
current = 0;
nost = 0;
}
void DBType:: Insert(StudRecType srec)
{
Stud[current] = srec;
current ++;
nost ++;
}
bool DBType::GetNext (StudRecType & srec)
{
if(current > nost)
return false;
else
{
srec = Stud[current];
current ++;
return true;
}
}
void DBType::Reset ( )
{
current = 0;
}
void Get_Inf (ifstream&, DBType &);
// Function prototype declaration statement for reading data from
// "Stud.txt"
//You have to implement the following functions//
void UpdateGPA(StudRecType &); // Calculate Sem. GPA and Cum GPA etc…
void GenerateReports(ofstream &, DBType &);
void UpdateGPA(StudRecType& fGPA)
{
int count = 0;
int i = 0;
float gradeA = 4.0;
float gradeB = 3.0;
float gradeC = 2.0;
float gradeD = 1.0;
float gradeF = 0.0;
float heldGPA = 0.0;
float totalGPA = 0.0;
count = fGPA.noCo;
int amtClass = 0;
if (fGPA.noCo != 0)
{
for (i = 0; i < count; i++)
{
if (fGPA.course[i].grade = 'A')
{
heldGPA = gradeA;
amtClass++;
}
if (fGPA.course[i].grade = 'B')
{
heldGPA = gradeB;
amtClass++;
}
if (fGPA.course[i].grade = 'C')
{
heldGPA = gradeC;
amtClass++;
}
if (fGPA.course[i].grade = 'D')
{
heldGPA = gradeD;
amtClass++;
}
if (fGPA.course[i].grade = 'F')
{
heldGPA = gradeF;
amtClass++;
}
if (fGPA.course[i].grade = 'W')
amtClass--;
totalGPA = (heldGPA + totalGPA);
}
fGPA.semGPA = (totalGPA / amtClass);
fGPA.cumGPA = ((fGPA.semGPA + fGPA.cumGPA) / 2);
}
}
int main()
{
ifstream inStud;
ofstream outFile;
int choice;
DBType StudDB;
inStud.open("Stud.txt");
if (!inStud)
{
cout <<"**Can't open input file Stud**"<< endl;
return 1;
}
outFile.open("Echo.dat");
if(!outFile)
{
cout <<"** Can't open output file **"<< endl;
return 1;
}
Get_Inf(inStud, StudDB);
//cout << "Total no. of Students is "<<noStud<<endl;
cout<<endl;
GenerateReports(outFile, StudDB);
return 0;
}
//*******************************************************************
void Get_Inf(
/* in */ ifstream& inF1,
/* out */ DBType & DB)
{
int i,j;
int jco;
StudRecType SR;
i=0;
while(!inF1.eof())
{
inF1>>SR.ssno;
inF1>>SR.name.last>>SR.name.first>>SR.name.middle;
inF1>>SR.tel>>SR.gender>>SR.level;
inF1>>SR.totalCredit>>SR.cumGPA;
//Echo input data on the screen
cout<<SR.ssno<<endl;
cout<<SR.name.last<<"*"<<SR.name.first;
cout<<"*"<<SR.name.middle<<endl;
cout<<SR.gender<<"*"<<SR.level<<endl;
cout<<SR.totalCredit<<"*"<<SR.cumGPA<<endl;
inF1>>jco;
SR.noCo = jco;
for (j = 0;j < jco; j++)
{
inF1>>SR.course[j].name;
inF1>>SR.course[j].credits;
inF1>>SR.course[j].grade;
cout<<SR.course[j].name
<<","<<SR.course[j].credits<<","
<<SR.course[j].grade<<endl;
}
i++;
UpdateGPA(SR);
DB.Insert (SR);
inF1.ignore(100,'\n');
cin.get();
}
}