Advertisement
Doragonroudo

[Missed Class] EGCO112 - Construct/Destruct

Apr 20th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. /* Construct Destruct */
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6. class MU_person
  7. {
  8. public:
  9.     MU_person()
  10.     {
  11.         cout << "MU_person constructor" << endl;
  12.     }
  13.     ~ MU_person ()
  14.     {
  15.         cout << "MU_person destructor" << endl;
  16.     }
  17. };
  18. class student: public MU_person
  19. {
  20. public:
  21.     student()
  22.     {
  23.         cout << "student constructor" << endl;
  24.     }
  25.     ~student()
  26.     {
  27.         cout << "student destructor" << endl;
  28.     }
  29. };
  30. int main(void)
  31. {
  32.     cout << "Program starts." << endl;
  33.     //MU_person d;
  34.     student d;
  35.     cout << "Program ends." << endl;
  36.     return 0;
  37. }
  38.  
  39.  
  40.  
  41.  
  42. /* Construct Destruct 2 */
  43.  
  44. #include <iostream>
  45.  
  46. using namespace std;
  47.  
  48. class MU_person
  49. {
  50. protected:
  51.     long id;
  52. public:
  53.     MU_person(long=10);
  54. };
  55. MU_person::MU_person(long x)
  56. {
  57.     id=x;
  58.     cout<< "MU person constructor " << id <<endl;
  59. }
  60.  
  61. class student:public MU_person
  62. {
  63. private:
  64.     double gpa;
  65. public:
  66.     student(long=20 ,double=2.5);
  67.     void display();
  68. };
  69. void student::display()
  70. {
  71.     cout<< "id" << id <<endl;
  72.     cout<< "gpa" << gpa <<endl;
  73. }
  74. student::student(long x,double g):MU_person(x)
  75. {
  76.     gpa=g;
  77.     cout<< "MU student constructor " << x << " " << g <<endl;
  78. }
  79.  
  80. int main()
  81. {
  82.     student m1(1111,2),m2(112),m3;
  83.     m1.display();
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement