Advertisement
Vladislav_Bezruk

Some task

Sep 28th, 2021
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 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, int _course, bool _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.     void input() {
  33.         string s_gender;
  34.        
  35.         cout << "Enter name of the student: ";
  36.         cin >> name;
  37.         cout << "Enter course of the student: ";
  38.         cin >> course;
  39.         cout << "Enter gender of the student (male or female): ";
  40.         cin >> s_gender;
  41.        
  42.         if (s_gender == "male") {
  43.             gender = false;
  44.         } else if (s_gender == "female") {
  45.             gender = true;
  46.         } else {
  47.             cout << "error";
  48.            
  49.             exit(1);
  50.         }
  51.     }
  52.  
  53.     void output() {
  54.  
  55.         cout << "Name of the student is: " << name << endl;
  56.         cout << "Student's course is: " << course << endl;
  57.         cout << "Gender is: ";
  58.        
  59.         if (gender) {
  60.             cout << "female";
  61.         } else {
  62.             cout << "male";
  63.         }
  64.        
  65.         cout << endl << endl;
  66.     }
  67. };
  68.  
  69. int main() {
  70.  
  71.     student student_1("Mariia", 2, "female");
  72.  
  73.     student_1.output();
  74.  
  75.     student student_2 = student_1;
  76.    
  77.     student_2.output();
  78.  
  79.     student student_3;
  80.  
  81.     student_3 = student_2 = student_1;
  82.    
  83.     student_3.output();
  84.  
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement