I have 2 classes:
1. Student
2. Course

Under the Student class I have the following:

class Student {
private:
string StudentName;

public:
string name ();
void changeName(string);
void registerCourses(Course course);
void displayCourses(Course course);
};

The method "void registerCourses(Course course)" & "void displayCourses(Course course)" using the Course class.

Under the Course class I have the following:

class Course {

private:

string nameCourse;
int totalOfCourses;

public:

void registerCourses(string course[5], int numberOfCourses);
void displayCourses();
friend class Student;
};

Student can register maximum of 5 courses and minimum of 1 course.

My question is, how should I implement the relation between the Student and Course class? I try to use the "friend function" but I don't know how.

Below is my code so far:

[CPP]
#include <iostream>
#include <string>
using namespace std;

class Student;

class Course {

private:

string nameCourse;
int totalOfCourses;

public:

void registerCourses(string course[5], int numberOfCourses);
void displayCourses();
friend class Student;
};

class Student {
private:
string StudentName;

public:
string name ();
void changeName(string);
void registerCourses(Course course);
void displayCourses(Course course);
};

string Student::name()
{
return StudentName;
}

void Student::registerCourses(Course course)
{
????
}

void Student::displayCourses(Course course)
{
????
}

void setinput(Student&);
void getinput(Student&);

int main()
{

Student s;
Course c;
setinput(s);


cout << "Outputting Student data\n";
getinput(s);


system("pause");
return 0;


}

void setinput(Student &stu)
{
string strName;

cout << "Enter student's name: ";
getline(cin,strName);
stu.changeName(strName);

return;


}

void getinput(Student &stu)
{

cout << "Student's name: "<< stu.name() << endl;
return;
}

[/CPP]

Please place your code inside (CODE). And you should have a parameter inside your Student class that keep track of it's classes, such as an array of size 5. Then you can call addcourse(Course course) inside your Student class, where you add new Course objects to the array. Hope that helps.

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.