UML problem

so i have this uml diagram and i dont understand much of it, i tried to do the first class but the other 2 i dont understand what i have to do, can you help me with 1 of those?

Person
#name : string
#affiliation : string
+Person(name : string, affiliation : string)
+getName() : string
+getAffiliation() : string
+setNume(affiliation: string) : void

Student
- listedCourses : vector<string>
- grades : vector<int>
- MAX_NR_COURSES : const int = 30
+ Student(name : string, specialization : string)
+ addCourseGrade(course : string, grade : int) :bool
+ printGrade():void
+ averageGrades():double
+ operator<<(o:ostream&, s : const Student&):ostream&

Professor
- listedCourses : vector<string>
- MAX_NR_COURSES : const int = 5
+ Professor(name : string, specialization : string)
+ addCourse ( course : string) :bool
+ eraseCourse ( course : string) : bool
+ operator<<(o:ostream&, p : const Professor&):ostream&




1
2
3
4
5
6
7
8
9
10
11
12
 class Person
{
public:
Person(string Name, string Affiliation );
string getName();
string getAffiliation ();
void setNume(string Affiliation );
protected :
    string Name;
    string Affiliation ;
};


i hope at least this class i wrote it good
The implementation of the class Person is ok. Does assignment requite to implement it?
What is the problem with the other 2 classes?
Can you post the complete assignment?
The assignment is to build these 3 classes so the main function my teacher gave me works without any change. The problem with the 2 other classes is that i dont know how to write them, and if i would post you the whole assignment you wouldnt understand anything becuase its not in english.
the only thing that i can say is that you need to imagine what exactly is trying to be accomplished by doing the various tasks. Even tho the instructions you provided were a little lacking i was able to figure out what was trying to be accomplished by thinking about what the desired result of said function would be. My initial printGrades function looked like this at first...

1
2
3
void printGrade(){
cout<<this;
}


bc i was like duh had no idea what needed to happen at that point so i just kinda made a placemarker even tho i knew it wasn't right. but anyways heres what i came up with. Im still not 100% sure this is what your teacher is looking for but here you go.

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
#include <iostream>
#include <string>
#include <vector>

using namespace std;
class Student {
public:
	Student()
		:name(),specialization(), MAX_NR_COURSES(30) {}

	Student(string name, string specialization)
	: name(name), specialization(specialization), MAX_NR_COURSES(30) {}

	bool addCourseGrade(string course, int grade) {
		if (grade && course != "" ) {
			listedCourses.push_back(course);
			grades.push_back(grade);
			return true;
		}
		else { return false; }
	}

	void printGrade() {
		cout << *this;
	}

	double averageGrades() {
		int total = 0;
		int i = 0;

		for (; i < this->grades.size() ; i++) {
			total += grades[i];
		}
		return (1.00 * total / i);
	}

	friend ostream& operator<< (ostream &o, const Student& s) {

		o << s.name << "\n";
		o << s.specialization << "\n" << "\n";

		for (int i = 0; i < s.grades.size(); i++) {

			o << s.listedCourses[i] << ": " << s.grades[i] << "\n";
		}

		return o;
	}

string name;
string specialization;

private:
const int MAX_NR_COURSES; 
vector<string> listedCourses;
vector<int> grades;


};



int main() {

	Student mark;

	mark.name = "Mark";
	mark.specialization = "wanker";

	mark.addCourseGrade("wanking", 76);
	mark.addCourseGrade("spanking", 77);

	
	mark.printGrade();

}


still not sure what to do with the averageGrades() function.
Last edited on
its sad that the mass majority of the time i spent on this i was trying to figure out how to get the eraseCourse() to fail... without looping through the whole vector. Apparently theres not way to check if a iterator is valid. Even using if(it != vec.end() doesn't work so maybe my computer is broken. idk. Kinda makes iterators less useful in scenarios where they would save from looping through the vector. The sad part is that when the gods invented the iterator they figured out a way to check to see if the memory was out of bounds and if it is it must just return from whereever you are trying to use it. I even attempted to check against the pointers in the vector everything i could think of. Anyway this is what i came up with.

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

class Professor {

public:
	string name, specialization;
	
	Professor()
		:name(),specialization(), MAX_NR_COURSES(5) {}

	Professor(string name, string specialization)
		:name(name), specialization(specialization), MAX_NR_COURSES(5) {}

	bool addCourse(string course) {
		if (course != "") {
			listedCourses.push_back(course);
			return true;
		}
		else { return false; }
	}

	bool eraseCourse(string course) {
		bool boo = false;

		for (int i = 0; i < listedCourses.size(); i++) {
			if (course == listedCourses[i]) { boo = true; break;}
		}
		if (boo) {
			vector<string>::iterator it = find(listedCourses.begin(), listedCourses.end(), course);
			listedCourses.erase(it);
			return true;
		}
		else { return false; }
	}

	friend ostream& operator<<(ostream& o, const Professor& p) {
		o << p.name << "\n" << p.specialization << "\n" << "\n";

		for (int i = 0; i < p.listedCourses.size(); i++) {
			o << p.listedCourses[i] << "\n";
		}
		return o;
	}

private:
int MAX_NR_COURSES;
vector<string> listedCourses;
};

int main() {

	Professor Mark;

	Mark.name = "Mark";
	Mark.specialization = "Wanker";

	Mark.addCourse("wanking");

	Mark.addCourse("spanking");

	Mark.addCourse("janking");

	if (!Mark.addCourse("")) {
		cout << "error" << "\n";  //supposed to error
	}

	if (!Mark.eraseCourse("hello")) {
		cout << "error course not found" << "\n" <<"\n";  //supposed to error
	}

	Mark.eraseCourse("spanking");

	cout << Mark;

}



error
error course not found

Mark
Wanker

wanking
janking
Last edited on
@martyrocks,
a much easier way to do:
1
2
3
4
5
6
7
8
9
bool eraseCourse(string course) 
  {
    auto it = std::find(listedCourses.begin(), listedCourses.end(), course);
    if (it == listedCourses.end())
      return false;

    listedCourses.erase(it);
    return true;
  }
Thanks a lot for the help, i appreciate it very much.
Topic archived. No new replies allowed.