class help

Here are the instructions
http://faculty.winthrop.edu/olsena/CSCI%20207/c207p6CalcAveClasses-s12.pdf


if you see where it says Note: These averages will be stored in the object’s data using methods.

I'm not understanding well or confused on what to do.....but i think i have everything set up correctly with finding the averages for each thing with their own functions. I'm just having trouble or don't understand what to do to store the averages in each of their methods. For example in the code, I have to store the labquiz averages in the method that belong to it. How do I correctly do that?? Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//Program Assignment 6
//Thomas Powe 4-12-12
//CS207


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


class Grade
{
private:
	int ID;
	int Exam;
	double test1, test2, test3;
	double program1, program2, program3, program4;
	double labquiz1, labquiz2, labquiz3, labquiz4, labquiz5;
	double lqavg, pavg, tavg;
	double cg;


public:
	//Grade();

	void SetData(ifstream &);
	void setID(int id);
	void setExam(int exam);
	void setLabquiz(double lq1, double lq2, double lq3, double lq4, double lq5, double lq);
	void setTest(double t1, double t2, double t3, double t);
	void setProg(double p1, double p2, double p3, double p4, double p);
	void CalcCourseGrade();
	double GetCourseGrade()
	{return cg;}
	void printResults(ofstream &OutputFile);
	//~Grade();
};


void Grade::SetData(ifstream &infile)
{

	infile>>ID;
	infile>>Exam;
	infile>>test1>>test2>>test3;
	infile>>program1>>program2>>program3>>program4;
	infile>>labquiz1>>labquiz2>>labquiz3>>labquiz4>>labquiz5;
	return;
}



void Grade::setID(int id)
{
	ID=id;
	return;
}

void Grade::setExam(int exam)
{
	Exam=exam;
	return;
}

void Grade::setLabquiz(double lq1, double lq2, double lq3, double lq4, double lq5, double lq)
{ 
	labquiz1=lq1;
	labquiz2=lq2;
	labquiz3=lq3;
	labquiz4=lq4;
	labquiz5=lq5;
	lqavg=lq;
	return;
}
void Grade::setTest(double t1, double t2, double t3, double t)
{
	test1=t1;
	test2=t2;
	test3=t3;
	tavg=t;
	return;
}
void Grade::setProg(double p1, double p2, double p3, double p4, double p)
{
	program1=p1;
	program2=p2;
	program3=p3;
	program4=p4;
	pavg=p;
	return;
}

void Grade::CalcCourseGrade()
{
	cg=(Exam+tavg+pavg+lqavg)/4.0;
	return;
}


void Grade::printResults(ofstream &OutputFile)
{
	OutputFile<<setw(13)<<ID<<setw(13)<<Exam<<setw(18)<<cg<<endl<<endl;
	return;
}


//Function Prototypes Go Here
void printHeadings(ofstream &OutputFile);
double labquizavg(double labquiz1, double labquiz2, double labquiz3, double labquiz4, double labquiz5);
double progavg(double program1, double program2, double program3, double program4);
double testavg(double test1, double test2, double test3);


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.SetData(infile);
while(!infile.eof())
{
	
	tavg=testavg(test1, test2, test3);
	pavg=progavg(program1, program2, program3, program4);
	lqavg=labquizavg(labquiz1, labquiz2, labquiz3, labquiz4, labquiz5);
	g.setExam(exam);
	g.setTest(t1, t2, t3, t);
	g.setProg(p1, p2, p3, p4, p);
	g.setLabquiz(lq1, lq2, lq3, lq4, lq5, lq);
	g.CalcCourseGrade();
	g.GetCourseGrade();
	g.printResults(OutputFile);
	g.SetData(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;
}

double labquizavg(double labquiz1, double labquiz2, double labquiz3, double labquiz4, double labquiz5)
{
	double lqavg;
	lqavg=(labquiz1+labquiz2+labquiz3+labquiz4+labquiz5)/5.0;
	return lqavg;
}
double progavg(double program1, double program2, double program3, double program4)
{
	double pavg;
	pavg=(program1+program2+program3+program4)/4.0;
	return pavg;
}
double testavg(double test1, double test2, double test3)
{
	double tavg;
	tavg=(test1+test2+test3)/3.0;
	return tavg;
}
Last edited on
These averages will be stored in the object’s data using methods
These averages (will be stored (in the object's data) using (methods)).
I'm just having trouble or don't understand what to do to store the averages in each of their methods.
I'm (just having trouble) or (don't understand (what to do (to store the averages (in each of their methods))))
is this correct?? because the Output came out correctly as should
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//Program Assignment 6
//Thomas Powe 4-12-12
//CS207


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


class Grade
{
private:
	int ID;
	int exam;
	double test1, test2, test3;
	double program1, program2, program3, program4;
	double labquiz1, labquiz2, labquiz3, labquiz4, labquiz5;
	double lqavg, pavg, tavg;
	double cg;


public:
	//Grade();

	void SetData(ifstream &);
	void setID();
	void setExam();
	void setLabquiz();
	void setTest();
	void setProg();
	void CalcCourseGrade();
	void printResults(ofstream &OutputFile);
	//~Grade();
};


void Grade::SetData(ifstream &infile)
{

	infile>>ID;
	infile>>exam;
	infile>>test1>>test2>>test3;
	infile>>program1>>program2>>program3>>program4;
	infile>>labquiz1>>labquiz2>>labquiz3>>labquiz4>>labquiz5;
	return;
}



void Grade::setID()
{
	ID;
	return;
}

void Grade::setExam()
{
	exam;
	return;
}

void Grade::setLabquiz()
{ 

	lqavg=(labquiz1+labquiz2+labquiz3+labquiz4+labquiz5)/5.0;
	return;
}
void Grade::setTest()
{
	tavg=(test1+test2+test3)/3.0;
	return;
}
void Grade::setProg()
{
	pavg=(program1+program2+program3+program4)/4.0;
	return;
}

void Grade::CalcCourseGrade()
{
	cg=((exam*0.25)+(tavg*0.60)+(pavg*0.10)+(lqavg*0.05));
	return;
}


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


//Function Prototypes Go Here
void printHeadings(ofstream &OutputFile);



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.SetData(infile);
while(!infile.eof())
{
	g.setID();
	g.setExam();
	g.setTest();
	g.setProg();
	g.setLabquiz();
	g.CalcCourseGrade();
	g.printResults(OutputFile);
	g.SetData(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;
}
54
55
56
57
58
59
60
61
62
63
64
void Grade::setID()
{
	ID;
	return;
}

void Grade::setExam()
{
	exam;
	return;
}
These functions do nothing.

Also, putting return; at the end of every void-returning function is useless - you are not required to do that for functions which return void.

115
116
117
118
119
120
121
122
123
124
125
126
127
128
g.SetData(infile);
while(!infile.eof())
{
	g.setID();
	g.setExam();
	g.setTest();
	g.setProg();
	g.setLabquiz();
	g.CalcCourseGrade();
	g.printResults(OutputFile);
	g.SetData(infile);
	

}
Why do you work with the data before you set the data? That's like baking a cake and then adding the ingredients. Even though logically it is correct due to your statement before the loop, it can be simplified to code that makes more sense.
Last edited on
Based on the instructions for this assignment your class is incorrect. The only data members for your class should be:

id
test average
program average
lab test and quiz average
final exam grade
course grade

This is what you have:
1
2
3
4
5
6
7
int ID; //ok
int exam; //ok
double test1, test2, test3; //Incorrect, should only be the average
double program1, program2, program3, program4; //Incorrect, should only be the average
double labquiz1, labquiz2, labquiz3, labquiz4, labquiz5; //Incorrect, should only be the average
double lqavg, pavg, tavg; //oK
double cg; //ok 


All the non-average grades should be processed through functions that are not members of your class, the result of such processing with then be set using member functions from your class.

Just want to help you out before you turn this in.

In the end, your class will have this public interface when correctly implemented:

1
2
3
4
5
6
7
void setID(int);
void setExam(double);
void setLabquiz(double);
void setTest(double);
void setProg(double);
void CalcCourseGrade();
void printResults(ofstream &OutputFile);


In main you will have a few functions that look something like this...

1
2
3
4
5
6
7
8
9
void ReadData(ifstream &infile, Grade &grades)
{
    //Read Id
    //Read exam
    grades.setTest(GetTestAverage(infile)); //example of processing test average
    //process program average
    //process labs/quizes

}


example of GetTestAverage(infile):

1
2
3
4
5
6
7
double GetTestAverage(ifstream &infile)
{
    //read test1
    //read test2
    //read test3
    //return average
}


Take what I offer as a grain of salt, there are a million ways to do this, but I noticed you will be graded on your use of functions and the way you use your class, I just want to steer you in the right direction.

Last edited on
Ok this is what I have so far,

unfortunately, all of the ID and the exam is not getting read, and all is not getting read in their columns.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//Program Assignment 6
//Thomas Powe 4-12-12
//CS207


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


class Grade
{
private:
	int ID;
	int exam;
	double test1, test2, test3;
	double program1, program2, program3, program4;
	double labquiz1, labquiz2, labquiz3, labquiz4, labquiz5;
	double lqavg, pavg, tavg;
	double cg;


public:
	//Grade();

	void SetData(ifstream &);
	void setID();
	void setExam();
	void setLabquiz();
	void setTest();
	void setProg();
	void CalcCourseGrade();
	void printResults(ofstream &OutputFile);
	//~Grade();
};


void Grade::SetData(ifstream &infile)
{

	infile>>ID;
	infile>>exam;
	infile>>test1>>test2>>test3;
	infile>>program1>>program2>>program3>>program4;
	infile>>labquiz1>>labquiz2>>labquiz3>>labquiz4>>labquiz5;
	return;
}



void Grade::setID()
{
	ID;
	return;
}

void Grade::setExam()
{
	exam;
	return;
}

void Grade::setLabquiz()
{ 

	lqavg=(labquiz1+labquiz2+labquiz3+labquiz4+labquiz5)/5.0;
	return;
}
void Grade::setTest()
{
	tavg=(test1+test2+test3)/3.0;
	return;
}
void Grade::setProg()
{
	pavg=(program1+program2+program3+program4)/4.0;
	return;
}

void Grade::CalcCourseGrade()
{
	cg=((exam*0.25)+(tavg*0.60)+(pavg*0.10)+(lqavg*0.05));
	return;
}


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


//Function Prototypes Go Here
void printHeadings(ofstream &OutputFile);



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.SetData(infile);
while(!infile.eof())
{
	g.setID();
	g.setExam();
	g.setTest();
	g.setProg();
	g.setLabquiz();
	g.CalcCourseGrade();
	g.printResults(OutputFile);
	g.SetData(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;
}





And here's my current output.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
                 Grade Calculator

                   Thomas Powe
                     04-12-12

           ID         Exam      Course Grade

      1547436           70              76.6

           94           80              92.2

           86           98              94.7

          100      1327835          332006.5

           76           95              64.5

           73           81              92.3

          100          100          750471.8

          100           70          114110.5

           61           74              58.4

          100          100              85.3

          100           80           62618.4

           96           96              94.8

          100          100              99.3

          100          100             100.0

      1250357          100              97.6

          100          100              96.8

           88           98              89.0
oh, nevermind, I fixed it!
Topic archived. No new replies allowed.