Advertisement
Marisichka

Untitled

Sep 27th, 2021
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class student {
  6. private:
  7.     string name;
  8.     int course;
  9.     bool gender;
  10.  
  11. public:
  12.     student() {}
  13.  
  14.     student(string _name, string _course, string _gender) : name(_name), course(_course), gender(_gender) {}
  15.  
  16.     student(const student& a) {
  17.  
  18.         name = a.name;
  19.         course = a.course;
  20.         gender = a.gender;
  21.     }
  22.  
  23.     student& operator = (const student& a) {
  24.  
  25.         name = a.name;
  26.         course = a.course;
  27.         gender = a.gender;
  28.  
  29.         return *this; // Возвращает ссылку на вызывающий объект
  30.     }
  31.  
  32.     int input() {
  33.  
  34.         cout << "Enter name of the student: ";
  35.         cin >> name;
  36.         cout << "Enter course of the student: ";
  37.         cin >> course;
  38.         cout << "Enter gender of the student: ";
  39.         cin >> gender;
  40.     }
  41.  
  42.     int output() {
  43.  
  44.         cout << "Name of the student is: " << name << endl;
  45.         cout << "Student's course is: " << course << endl;
  46.         cout << "Gender is: " << gender << endl << endl;
  47.     }
  48. };
  49.  
  50. int main() {
  51.  
  52.     student student_1 ( "Mariia", 2, "female");
  53.  
  54.     student   student_1 = student_2;
  55.  
  56.     student  student_3;
  57.  
  58.     student_1 = student_2 = student_3;
  59.  
  60.     student_3.output();
  61.  
  62.     return 0;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement