Stuck on a project don't know what to do next

So I'm working on an assignment and I am out of ideas I think I'm making this more complicated than it needs to be can someone help me figure out what to do next. I'm specifically having trouble with the GPA and coursesandgrades stuff

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
//  Implement a Collegestudent class with appropriate data members
//  such as name, year, expectedgrad, major, minor, GPA, coursesandGrades
//  and maritalStatus and the like.

//  The class should have at least a have dozen methods in it's public
//  interface.  For example, there should be a method to computre GPA
//  from CoursesandGrades and to determine whether the GPA merits 
//  honors or probation.  There also should be methods to display
//  a college student's current course load and to print remaining
//  required courses.

//  Include the default constructor, a constructor with parameter(s), 
//  the copy constructor. Show uses of each constructor in main().


#include <iostream>
using namespace std;

class CollegeStudent{
public:
    Collegestuden(){name = "John"};
    void setName(string n) {name = n;}
    void setMinor(string b) {minor =  i;}                   
    void setMajor(string c) {major =  a;}
    void setMaritalStatus(string d) {maritalStatus =  m;}
    void setYear(unsigned y) {year = y};
    void setExpectedGrad(unsigned e) {expectedGrad = e};
    void setGPA(float g) {GPA = g};
private:
    string name;
    string minor;
    string major;
    string maritalStatus;
    unsigned year;
    unsigned expectedGrad;
    unsigned GPA;
    class CoursesAndGrades{ // This is where I get stuck
        string title
        char grades
    };

int main(){

CollegeStudent();
CollegeStudent("John");
CollegeStudent c;
CollegeStudent d = c;
Sorry, I don't live in English language area, so I have looked what is the GPA. I've found it:

http://www.back2college.com/gpa.htm

So, you need to store the courses and grades. It is ok, because you have done it.

1
2
3
4
5
class CoursesAndGrades{ // This is where I get stuck
public:
        string title;
        char grades;
    };


(Instead of 'public' you could make set or get function.)

I will continue.

You can use array or vector to hold the data:

for example:

1
2
3
4
5
6
7
8
9
...
class CoursesAndGrades{ // This is where I get stuck
        string title
        char grades
    };
...
private:
 CoursesAndGrades arrayOfCourses[10]; // Here you can hold max 10 Courses.


Other storing:

vector<CoursesAndGrades> vectorOfCourses;


http://www.dreamincode.net/forums/showtopic33631.htm
http://www.cplusplus.com/reference/stl/vector/

I advise to use vector.

1
2
3
4
5
class CollegeStudent{
...
private:
vector<CoursesAndGrades> vectorOfCoursesAndGrades;
}



So you need an add function:

1
2
3
4
5
6
7
8
9
void CollegeStudent::add(string title, char grade)
{
  CoursesAndGrades *pCaG = new CoursesAndGrades();
  pCaG->title = title;
  pCaG->grade = grade;
  vectorOfCoursesAndGrades.push_back(pCaG);
  
  
}


// ! in the destructor you have to destroy the elements of the vector!!!!

1
2
3
4
5
6
7
8
9
~CollegeStudent::CollegeStudent()
{
  CoursesAndGrades *pCaG;
  for ( int i = 0; i < vectorOfCoursesAndGrades.size(); i++)
  {
     vectorOfCoursesAndGrades.pop_back(pCaG);  
     delete pCaG;
  }
}


After that you need a get function which gets the data;

Of course my code is not ready.
write if you stuck somewhere.
Last edited on
:) I forgot the GPA computing.


like this:

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
float CollegeStudent::GPAComputing()
{
	float gpa;
	float numberOfGrades = 0;
	
	for ( int i = 0; i < vectorOfCoursesAndGrades.size(); i++, numberOfGrades++)
        {
		CoursesAndGrades *pCaG = vectorOfCoursesAndGrades[i]; // it is possible you have to cast
		// if you store the grades as a char like this: 'ABCDF' then:
		int valueOfGrades;
		switch(pCAG->Grade)
		{
			case 'A':
			case 'a': valueOfGrades = 4; break;
			
			case 'B':
			case 'b': valueOfGrades = 3; break;
			
			case 'C':
			case 'c': valueOfGrades = 2; break;
			
			case 'D':
			case 'd': valueOfGrades = 1; break;
			
			case 'F':
			case 'f': valueOfGrades = 0; break;
			
			
		}
		gpa += valueOfGrade;
		
	}

	return gpa / numberOfGrades;
}
Last edited on
Topic archived. No new replies allowed.