Thread: Student Files

  1. #1
    Registered User
    Join Date
    Apr 2007

    Student Files

    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>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 ==========
    // 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
    		DBType( );
    		void Insert(StudRecType );
    		bool GetNext(StudRecType &);
    		void Reset( );
    		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;
    		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;
    			if (fGPA.course[i].grade = 'B')
    				heldGPA = gradeB;
    			if (fGPA.course[i].grade = 'C')
    				heldGPA = gradeC;
    			if (fGPA.course[i].grade = 'D')
    				heldGPA = gradeD;
    			if (fGPA.course[i].grade = 'F')
    				heldGPA = gradeF;
    			if (fGPA.course[i].grade = 'W')
    			totalGPA = (heldGPA + totalGPA);
    			fGPA.semGPA = (totalGPA / amtClass);
    			fGPA.cumGPA = ((fGPA.semGPA + fGPA.cumGPA) / 2);
    int main()
    	ifstream inStud;
    	ofstream outFile;
    	int	choice;
    	DBType StudDB;
    	if (!inStud)
    		cout <<"**Can't open input file Stud**"<< endl;
    		return 1;
    		cout <<"** Can't open output file **"<< endl;
    		return 1;
    	Get_Inf(inStud, StudDB);
    	//cout << "Total no. of Students is "<<noStud<<endl;
    	GenerateReports(outFile, StudDB);
    	return 0;
    void Get_Inf(
    	/* in  */ ifstream& 	inF1,
    	/* out */ DBType & 	 DB)
    	int i,j;
    	int jco;
    	StudRecType SR;
    		//Echo input data on the screen
    		SR.noCo = jco;
    		for (j = 0;j < jco; j++)
    		DB.Insert (SR);
    Last edited by GCNDoug; 03-04-2008 at 07:00 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    You declaring UpdateGPA, then defining it a few lines below that. The problem is that the declaration and definition don't match. Decide whether you want to pass by reference or pass by value, then change the definition to use that and delete the prototype that isn't needed.

    >> I am more worred about the actual task at hand as I can figure out the compiler errors later
    It's always wise to fix compiler errors before continuing to code, although coming up with a plan for the code before fixing them is fine.

  3. #3
    Registered User
    Join Date
    Apr 2007
    wow the only thing causing the errors was the declaration. It was suppose to be passed by reference.

    I hope that my code for the semester GPA, and cumGPA work ok. that function was really messy to write and I'm sure something got messed up somewhere going to test it now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading .dat files from a folder in current directory...
    By porsche911nfs in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2009, 09:52 PM
  2. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  3. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  5. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM