Skip to content

Instantly share code, notes, and snippets.

@arossouw
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arossouw/5e8753c3e3042b6a3df3 to your computer and use it in GitHub Desktop.
Save arossouw/5e8753c3e3042b6a3df3 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <string>
#include <map>
class exam {
int exam_questions;
int exam_passscore;
std::string exam_number;
std::string subject;
public:
exam() : exam_questions(0), exam_passscore(0), exam_number(""), subject("") {};
exam(std::string number,int questions, std::string subject) :
exam_number(number), exam_questions(questions), subject(subject) {};
};
class person
{
std::string firstname;
std::string surname;
int idno;
int age;
public:
person(std::string firstname, std::string surname, int idno, int age):
firstname(firstname), surname(surname), idno(idno), age(age) {};
std::string get_firstname () const { return firstname; }
};
class student : public person {
std::string student_no;
exam e;
public:
student (std::string student_no, std::string firstname, std::string surname, int idno, int age) :
student_no(student_no), person(firstname, surname, idno, age) { };
std::string get_studentno () const { return student_no; };
void take_exam(std::string examno, int questions, std::string subject);
};
void student::take_exam(std::string examno, int questions, std::string subject)
{
exam e(examno, questions, subject);
}
class teacher : public person {
public:
teacher (std::string firstname, std::string surname, int idno, int age) :
person(firstname, surname, idno, age) {};
};
class school {
std::vector<student> students;
std::vector<teacher> teachers;
std::vector<std::string> courses;
std::string school_name;
public:
void add_course (std::string course);
school(std::string school_name) : school_name(school_name) {};
void add_teacher (teacher &teach);
void add_student (student &stud);
};
void school::add_teacher (teacher &teach)
{
teachers.push_back(teach);
}
void school::add_student (student &stud)
{
students.push_back(stud);
}
int main(){
student first("20012EE", "John", "Doe", 882123123,15);
teacher t("Jane", "Doe", 9992123, 25);
school s("The School");
s.add_student(first);
s.add_teacher(t);
first.take_exam("T-2002", 200, "Biology");
std::cout << first.get_firstname() << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment