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
|
#include <iostream>
class Student
{
public:
std::string name;
int ID;
Student(){};
Student( std::string n, int id){ name = n; ID = id; }
};
class Course
{
public:
std::string name;
int course_no;
Course(){};
Course( std::string n, int c){ name = n; course_no = c; }
};
class Enrolment
{
public:
Student student;
Course course;
int grade{0};
Enrolment(){};
Enrolment(Student s, Course c){ student = s; course = c; }
};
class School
{
public:
std::string name;
int no_students{0};
int no_courses{0};
int no_enrolments{0};
Student* roll = new Student[5];
Course* curriculum = new Course[20];
Enrolment* report = new Enrolment[100];
void addStudent(Student s){roll[no_students] = s; no_students++;}
void addCourse(Course c){curriculum[no_courses] = c; no_courses++;}
void addEnrolment(Enrolment e){report[no_enrolments] = e; no_enrolments++;}
void display_students()
{
for(int i = 0; i < no_students; i++)
std::cout << roll[i].ID << '\t' << roll[i].name << '\n';
}
void display_courses()
{
for(int i = 0; i < no_courses; i++)
std::cout << curriculum[i].course_no << '\t' << curriculum[i].name << '\n';
}
void display_enrolments()
{
for(int i = 0; i < no_enrolments; i++)
std::cout
<< i << '\t' << report[i].student.name << " -> "
<< report[i].course.name << '\t' << "Grade: " << report[i].grade << '\n';
}
void setGrade(int i, int g)
{
report[i].grade = g;
}
};
int main()
{
School eton; eton.name = "Eton";
Student s1("Mary",11), s2("Bob",22), s3("Jack",44);
eton.addStudent(s1); eton.addStudent(s2); eton.addStudent(s3);
eton.display_students();
Course c1("Woodwork", 23); Course c2("English", 541);
eton.addCourse(c1); eton.addCourse(c2);
eton.display_courses();
Enrolment e1(s1,c2), e2(s1,c1), e3(s2,c2), e4(s3,c2);
eton.addEnrolment(e1); eton.addEnrolment(e2); eton.addEnrolment(e3); eton.addEnrolment(e4);
eton.display_enrolments();
eton.setGrade(1,96);
eton.setGrade(2,87);
eton.display_enrolments();
return 0;
}
|