Hey, this is the task I have to do

http://faculty.winthrop.edu/olsena/CSCI%20207/c207p6CalcAveClasses-s12.pdf

I'm trying to read each part..I have to read in the ID, exam, test grades, program grades, and lab test/quiz grades. In the insructions, it says I have to set methods for each one which I did. Now i'm having a problem reading the test grades together, then the program grades together, then the lab test grades together.

This is my input code

1547436 70 81 90 57 98 92 80 50 94 80 100 100 0 -9 -9
1478732 82 81 82 86 98 92 100 90 92 100 100 100 100 -9 -9
1327835 56 78 64 59 96 94 96 76 95 50 100 100 73 -9 -9
1426531 67 80 73 81 100 100 88 80 92 70 100 100 100 -9 -9
1250737 40 68 55 40 0 92 100 70 50 70 100 78 78 -9 -9
1140605 49 61 74 49 98 100 70 100 80 50 100 100 80 -9 -9
1128743 61 87 58 73 100 100 80 80 90 100 100 100 100 -9 -9
1250807 96 96 93 96 100 100 100 100 100 100 100 100 100 -9 -9
1227542 90 90 96 95 100 100 100 100 100 100 100 100 100 -9 -9
1250357 100 96 96 97 100 92 100 100 100 100 100 100 100 -9 -9
1123288 92 85 67 88 98 100 100 86 90 30 30 30 30 -9 -9

I put the -9's there as sentinel values if that's right.

Anyways, this is the code I have so far. Please help me in the right direction with reading these values in correctly. That way I can focus on getting the averages for each one. Thank you. You see, I tried to do while(g.setLabquiz >=0) but it won't accept the g.setLabquiz. Much help please

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <stdlib.h>
using namespace std;


class Grade
{
private:
    int ID;
    int exam;
    double test;
    double program;
    double labquiz;
    double cg;

public:
    //Grade();
    void setData(ifstream &);
    void setID(ifstream & );
    void setExam(ifstream &);
    void setLabquiz(ifstream &);
    void setTest(ifstream &);
    void setProg(ifstream &);
    void CalcCourseGrade();
    double GetCourseGrade()
    {return cg;}
    void printResults(ofstream &OutputFile);
    //~Grade();
};


void Grade::setID(ifstream &infile)
{
    infile>>ID;
    return;
}

void Grade::setExam(ifstream &infile)
{
    infile>>exam;
    return;
}

void Grade::setLabquiz(ifstream &infile)
{ 
    infile>>labquiz>>labquiz>>labquiz>>labquiz>>labquiz;
    return;
}
void Grade::setTest(ifstream &infile)
{
    infile>>test>>test>>test;
    return;
}
void Grade::setProg(ifstream &infile)
{
    infile>>program>>program>>program>>program;
    return;
}

void Grade::CalcCourseGrade()
{

    return;
}

void Grade::printResults(ofstream &OutputFile)
{
    OutputFile<<setw(13)<<ID<<setw(13)<<exam<<setw(18)<<"Course Grade"<<endl<<endl;
    return;
}

//Function Prototypes Go Here
void printHeadings(ofstream &OutputFile);
void labquizavg(Grade g);
void progavg(Grade g);
void testavg(Grade g);

int main()
{

    Grade g;
    ofstream OutputFile;
    OutputFile.open("Output.dat");

    ifstream infile;
    infile.open("Input.dat");
    OutputFile<<fixed<<showpoint<<setprecision(1)<<endl;
    printHeadings(OutputFile);

g.setID(infile);
g.setExam(infile);
while(!infile.eof())
{
    g.setLabquiz(infile);
    g.setProg(infile);
    g.setTest(infile);
    while(g.setLabquiz >=0)
    {

    g.setLabquiz(infile);
    g.setProg(infile);
    g.setTest(infile);
    }
    g.printResults(OutputFile);
    g.setID(infile);
    g.setExam(infile);
}

    OutputFile.close();
    infile.close();
    return 0; 
}
//Function Definitions Go Here
void printHeadings(ofstream &OutputFile)
{   
    OutputFile<<setw(33)<<"Grade Calculator"<<endl<<endl;
    OutputFile<<setw(30)<<"Thomas Powe"<<endl;
    OutputFile<<setw(29)<<"04-12-12"<<endl<<endl;
    OutputFile<<setw(13)<<"ID"<<setw(13)<<"Exam"<<setw(18)<<"Course Grade"<<endl<<endl;
    return;
}

void labquizavg(Grade g)
{

    return;
}
void progavg(Grade g)
{
    return;
}
void testavg(Grade g)
{

    return;
}

Recommended Answers

All 2 Replies

I put the -9's there as sentinel values if that's right.

I don't think you need that. The instructions states the exact number of grades in each category, so all your program has to do is read that quantity of numbers. No need for a sentinel value.

setProg() -- you need to read each of the grades in individual variables so that the function can later make calculations. It can't do that when you read all the grades into the same variable. Same goes for the other set functions.

so for example, I'll havee to read the program grades in like this???

infile>>program1>>program2>>program3>>program4;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.