Cpp

Please help

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

#pragma once
#include <iostream>
#include <string>
using namespace std;

class Student{
	public:
	    int StudentID;
		string Firstname;
		string Lastname;
		void PrintInfo();//this prints information about this student
		Student(){Attendance=0;	Final=0; Homework=0; Tests=0;}; //this is a default constructor. It does not do anything in this program. Normally, you should initialize your variables here
		Student(int id, string lname,string fname,double attd,double fnl,double hmk,double tst);//this is another constructor (not the default, because it has parameters)
		void SetAttendance(double grade);
		double GetAttendance() const{ return Attendance;};
		void SetFinal(double grade);
		double GetFinal() const{ return Final;};
		void SetHomework(double grade);
		double GetHomework() const{ return Homework;};
		void SetTests(double grade);
		double GetTests() const{ return Tests;};
		double GetGrade() const;
	private:
	   double Homework; //scores from homework max 300 points - 30% of final grade
	   double Tests;    // tests 100 max points - 30% of final grade
	   double Final;   // final exam 100 max points - 30% of final grade
	   double Attendance; //attendance max 10 points - 10% of final grade
};

//We are going to implement the functions we defined in the Student class below
///use the values given to initialize the variables defined in the class
Student::Student(int id, string lname,string fname,double attd,double fnl,double hmk,double tst)
{
	StudentID =id;
	Firstname = fname;
	Lastname  = lname;
	SetAttendance(attd);
	SetFinal(fnl);
	SetHomework(hmk);
	SetTests(tst);
};

void Student::PrintInfo()
{
	printf("ID=%d, Name:%s,%s\n\tAttendance: %2.2f\tTests:%2.2f\tHomework:%3.2f\tFinal:%3.2f\n\tFinal Grade:%3.2f\n--------------------------------\n",
	     StudentID,Lastname.c_str(),Firstname.c_str(),Attendance,Tests,Homework,Final,GetGrade());
};

// Calculate the final grade
double Student::GetGrade() const
{
//FILL IN THE CODES THAT COME HERE
};

//Attendance grade cannot be more than 10
void Student::SetAttendance(double grade)
{
//FILL IN THE CODES THAT COME HERE
};

//Final grade cannot be more than 100
void Student::SetFinal(double grade)
{
//FILL IN THE CODES THAT COME HERE
};

//Homework grade cannot be more than 300
void Student::SetHomework(double grade)
{
//FILL IN THE CODES THAT COME HERE
};

//Tests grade cannot be more than 100
void Student::SetTests(double grade)
{
//FILL IN THE CODES THAT COME HERE
};
Last edited on
not going to do it for you but typically getter and setter functions are named, and have parameters, etc, that involve setting or returning the value of a class member variable.

for example

class c
{
double attendance;
double get_attendance() {return attendance;} //tiny functions are ok put here without an external body.
void set_attendance(double in) {attendance = in;}
}

not sure why all yours take something called 'grade' which seems confusing (to human readers). It would work, its just confusing.
Last edited on
I just want to point out that I wouldn't use #pragma, as it is not supported by all compilers, but when it isn't, it won't produce an error and your program won't work. Better is:
1
2
3
4
5
#ifndef SOMETHING_H
#define SOMETHING_H
//Your code

#endif //SOMETHING_H defined 
Last edited on
If you're unsure what getters and setters are, take a quick look at google for C++ tutorials - this site has a tutorial course, in fact! There are tons of examples and explanations as to what setters and getters are.

Really all that setters are is that they take a parameter and use it to set the value of a corresponding data member in the class.
A getter returns the data member's value - it "gets" the value.

Joe
sparkprogrammer@gmail.com
www.concordspark.com
Topic archived. No new replies allowed.