Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
c++ object oriented problems
#1
Alright, I'm working on trying a project for school that's object oriented and it's giving me tons and tons of errors. I've been going through for about an hour trying to debug, but not having much luck.

The error I keep getting is that my functions are undefined. So I'm thinking maybe I'm stupid and defined them incorrectly and am not noticing it.

Basically, the setup is three files (stud2.h, stud2.cxx, and the driver code runstud2.cxx).

stud2.h contains the initial functions that will be used and also contains some information about what is happening with each.

stud2.cxx contains much of the same as stud2.h, but actually places the code in the functions.

runstud2.cxx is the actual program that grabs the code from the previous two files and outputs the information through them.

There are 3 functions (ReadRd, WriteRd, avgOfExams). ReadRd (read record) reads the data file. WriteRd (write record) begins writing in the data. avgOfExams takes the average of all the students scores.

Here's the code from the files:

stud2.h
Code:
#include<fstream.h>
#include<iostream.h>
#include<iomanip.h>

void ReadRd(ifstream& inFile, int& id, int& exam1, int& exam2, int&
exam3);

// PURPOSE:  Reads student id and three exam scores.
// INPUT: inFile.
// PRE: Input file is opened and ok.
// OUTPUT: id, exam1, exam2, exam3.
// POST: id, exam1, exam2, exam3 are assigned.
// NOTE: none.

void WriteRd(ofstream& outFile, int id, int exam1, int exam2, int exam3,
float avg);

// PURPOSE:  It writes id, exam1, exam2 & exam3 values to outfile.
// INPUT: id, exam1, exam2, exam3 & avg.
// PRE: outFile is opened and ok.
// OUTPUT: outFile.
// POST: Values of id, exam1, exam2, exam3 & avg are written to outFile.
// NOTE: none.

float avgOfExams(int exam1, int exam2, int exam3);

// PURPOSE:  It calculates the average of three exams.
// INPUT: exam1, exam2, exam3.
// PRE: exam1, exam2 and exam3 are assigned.
// OUTPUT: float value (avgofExams)
// POST: It returns avg of three exams.
// NOTE: none.

stud2.cxx
Code:
#include "stud2.h"

void ReadRd(ifstream& inFile, int& id, int& exam1, int& exam2, int&
exam3);
// PURPOSE:  Reads student id and three exam scores.
// INPUT: inFile.
// PRE: Input file is opened and ok.
// OUTPUT: id, exam1, exam2, exam3.
// POST: id, exam1, exam2, exam3 are assigned.
// NOTE: none.

{
    inFile>>id>>exam1>>exam2>>exam3;
}

void WriteRd(ofstream& outFile, int id, int exam1, int exam2, int exam3,
float avg);
// PURPOSE:  It writes id, exam1, exam2 & exam3 values to outfile.
// INPUT: id, exam1, exam2, exam3 & avg.
// PRE: outFile is opened and ok.
// OUTPUT: outFile.
// POST: Values of id, exam1, exam2, exam3 & avg are written to outFile.
// NOTE: none.

{
    outFile<<"id= "<<id<<endl;
    outFile<<"exam1= "<<exam1<<endl;
    outFile<<"exam2= "<<exam2<<endl;
    outFile<<"exam3= "<<exam3<<endl;
    outFile.setf(ios::fixed);
    outFile.setf(ios::showpoint);
    outFile.precision(2);
    outFile<<"Exams AVG= "<<avg<<endl;
}

float avgOfExams(int exam1, int exam2, int exam3);
// PURPOSE:  It calculates the average of three exams.
// INPUT: exam1, exam2, exam3.
// PRE: exam1, exam2 and exam3 are assigned.
// OUTPUT: float value (avgofExams)
// POST: It returns avg of three exams.
// NOTE: none.

{
    return float(exam1+exam2+exam3)/float(3);
}


runstud2.cxx
Code:
#include "stud2.h"
using namespace std;

// Author            : Mike Davis
// Course Title            : Computer Programming II
// Course Number        : CS216
// Class Meets            :  MW/ 2:30-4:00
// Prof Name            :  Moe Bidgoli
// Assignment Number        :  #1
// Due Date            :  9-11-2006
// Possible Points        :  
// Purpose            :
//  This program will read in a students id and three of their exam scores
//  It will then add the scores together and create an average based on
//  the resulting division of that sum.  

int main()

{
    ifstream inFile;
    ofstream outFile;
    inFile.open("in.data");
    outFile.open("out.data");

    int id, exam1, exam2, exam3;
    float avg;

    ReadRd(inFile, id, exam1, exam2, exam3);
    avg = avgOfExams(exam1, exam2, exam3);
    WriteRd(outFile, id, exam1, exam2, exam3, avg);
    outFile<<"*** END ***"<<endl;

    return 0;

}

If anyone could find what's up with this, it would be greatly appreciated as I've been staring at this for about an hour and a half.
url=http://fileanchor.com]FileAnchor[/url] - ImageAnchor - FBTK - QbasicNews - VPlanet - Various
#2
Also, I know this is very simple for having so many functions, but we have to do it this way.

If anyone has any questions on the setup or something, please ask and I'll explain.

The data I'm running is

Code:
2001, 70, 80, 75
2002, 100, 0, 100
2003, 0,0,0
url=http://fileanchor.com]FileAnchor[/url] - ImageAnchor - FBTK - QbasicNews - VPlanet - Various
#3
Got it fixed.
url=http://fileanchor.com]FileAnchor[/url] - ImageAnchor - FBTK - QbasicNews - VPlanet - Various


Forum Jump:


Users browsing this thread: 1 Guest(s)