Advertisement
M_A_Tabarani

Some School stuff (14)

Nov 3rd, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Date
  6. {
  7. public:
  8.     Date (int, int, int);
  9.  
  10. private:
  11.     int day;
  12.     int month;
  13.     int year;
  14.  
  15. friend ostream& operator << (ostream&, const Date&);
  16. };
  17.  
  18. Date::Date(int dy, int mn, int yr)
  19. {
  20.     day = dy;
  21.     month = mn;
  22.     year = yr;
  23. }
  24.  
  25. ostream& operator << (ostream& os, const Date& x)
  26. {
  27.     os <<x.day<<"/"<<x.month<<"/"<<x.year;
  28.     return os;
  29. }
  30.  
  31. class Student
  32. {
  33. public:
  34.     Student(const string&, const int&, const Date&, const Date&);
  35.  
  36. private:
  37.  
  38.     string name;
  39.     int matricno;
  40.     const Date birthDate;
  41.     const Date regDate;
  42.  
  43. friend ostream& operator << (ostream&, const Student&);
  44. };
  45.  
  46. Student::Student (const string& n, const int& mat, const Date &DOB, const Date &DOR)
  47.     : birthDate(DOB), regDate(DOR)
  48.     {
  49.         name = n;
  50.         matricno = mat;
  51.     }
  52.  
  53. ostream& operator << (ostream& os, const Student& course)
  54. {
  55.     os << "Student's name: " << course.name << endl;
  56.     os << "Student's matric no: " << course.matricno << endl;
  57.     os << "Date of birth: " << course.birthDate << endl;
  58.     os << "Date of registration: " << course.regDate << endl;
  59.     return os;
  60. }
  61.  
  62. int main ()
  63. {
  64.     Date birth (24, 7, 1997);
  65.     Date reg (3, 9, 2015);
  66.  
  67.     Student physics ("Hanisah", 1319987, birth, reg);
  68.  
  69.     cout << physics << endl;
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement