Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Date
- {
- public:
- Date (int, int, int);
- private:
- int day;
- int month;
- int year;
- friend ostream& operator << (ostream&, const Date&);
- };
- Date::Date(int dy, int mn, int yr)
- {
- day = dy;
- month = mn;
- year = yr;
- }
- ostream& operator << (ostream& os, const Date& x)
- {
- os <<x.day<<"/"<<x.month<<"/"<<x.year;
- return os;
- }
- class Student
- {
- public:
- Student(const string&, const int&, const Date&, const Date&);
- private:
- string name;
- int matricno;
- const Date birthDate;
- const Date regDate;
- friend ostream& operator << (ostream&, const Student&);
- };
- Student::Student (const string& n, const int& mat, const Date &DOB, const Date &DOR)
- : birthDate(DOB), regDate(DOR)
- {
- name = n;
- matricno = mat;
- }
- ostream& operator << (ostream& os, const Student& course)
- {
- os << "Student's name: " << course.name << endl;
- os << "Student's matric no: " << course.matricno << endl;
- os << "Date of birth: " << course.birthDate << endl;
- os << "Date of registration: " << course.regDate << endl;
- return os;
- }
- int main ()
- {
- Date birth (24, 7, 1997);
- Date reg (3, 9, 2015);
- Student physics ("Hanisah", 1319987, birth, reg);
- cout << physics << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement