Advertisement
Guest User

Untitled

a guest
May 27th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3.                               Online C++ Compiler.
  4.                Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8. #include <stdio.h>
  9. #include <iostream>
  10.  
  11. class student
  12. {
  13.    public:
  14.    int course;  
  15.    int age;
  16.  
  17.    student()            
  18.    {
  19.       course = 1;
  20.       age = 18;
  21.    }
  22.  
  23.    student(int course, int age)
  24.    {
  25.       course = course;
  26.       age = age;
  27.    }
  28.  
  29.    student(const student &obj)            
  30.    {
  31.       course = obj.course;
  32.       age = obj.age;
  33.    }
  34.  
  35.    ~student()
  36.    {
  37.       std::cout<<"\nДеcтруктор сработал!\n";
  38.    }
  39.    
  40.    int getAge(){
  41.        return age;
  42.    }
  43.    
  44.    void setAge(int age){
  45.        age = age;
  46.    }
  47.    
  48.    int getCourse(){
  49.        return course;
  50.    }
  51.    
  52.    void setCourse(int course){
  53.        course = course;
  54.    }
  55. };
  56.  
  57. int main() {
  58.     student s1;
  59.     student s2(2,20);
  60.     student s3(s2);
  61.     s1.setAge(21);
  62.     s1.setCourse(5);
  63.     cout << s1.getAge() << " " << s1.getCourse();
  64.     cout << s2.getAge() << " " << s2.getCourse();
  65.     cout << s3.getAge() << " " << s3.getCourse();
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement