Advertisement
Maestro1

лр4

May 20th, 2024
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. class Student
  8. {
  9.  
  10. private:
  11.     char surname[100];
  12.     int age;
  13.     double sr_ball;
  14.  
  15. public:
  16.     Student()
  17.     {
  18.         cout << "----------------------------------------" << endl;
  19.         cout << "Вызван конструктор по умолчанию" << endl;
  20.         strcpy_s(surname, "Неизвестно");
  21.         age = 0;
  22.         sr_ball = 0;
  23.         cout << "----------------------------------------" << endl;
  24.     }
  25.  
  26.     Student(const char* s_name)
  27.     {
  28.         cout << "----------------------------------------" << endl;
  29.         cout << "Вызван конструктор копирования" << endl;
  30.         strcpy_s(surname, s_name);
  31.         age = 0;
  32.         sr_ball = 0;
  33.         cout << "----------------------------------------" << endl;
  34.     }
  35.  
  36.     Student(const char* s_name, int a)
  37.     {
  38.         cout << "----------------------------------------" << endl;
  39.         cout << "Вызван конструктор копирования" << endl;
  40.         strcpy_s(surname, s_name);
  41.         age = a;
  42.         sr_ball = 0;
  43.         cout << "----------------------------------------" << endl;
  44.     }
  45.  
  46.     Student(const char* s_name, int a, double ball)
  47.     {
  48.         cout << "----------------------------------------" << endl;
  49.         cout << "Вызван конструктор с параметрами" << endl;
  50.         strcpy_s(surname, s_name);
  51.         age = a;
  52.         sr_ball = ball;
  53.         cout << "----------------------------------------" << endl;
  54.     }
  55.  
  56.     ~Student()
  57.     {
  58.         cout << "----------------------------------------" << endl;
  59.         cout << "\nВызван деструктор" << endl;
  60.         strcpy_s(surname, "");
  61.         age = 0;
  62.         sr_ball = 0;
  63.         cout << "----------------------------------------" << endl;
  64.     };
  65.  
  66.     void Input()
  67.     {
  68.         cout << "Введите фамилию студента: ";
  69.         cin.getline(surname, 100);
  70.         cout << "Введите возраст студента: ";
  71.         cin >> age;
  72.         cout << "Введите средний балл студента: ";
  73.         cin >> sr_ball;
  74.     };
  75.  
  76.     void Output()
  77.     {
  78.         cout << "----------------------------------------" << endl;
  79.         cout << "Фамилия студента: " << surname << endl;
  80.         cout << "Возраст студента:" << age << endl;
  81.         cout << "Средний балл студента:" << sr_ball << endl;
  82.         cout << "----------------------------------------" << endl;
  83.  
  84.     };
  85.  
  86. };
  87.  
  88.  
  89. int main()
  90. {
  91.  
  92.     Student student1;
  93.     Student student2("Левашов", 18, 4.5);
  94.     Student student3("Парамонов", 18);
  95.  
  96.     student1.Output();
  97.     student2.Output();
  98.     student3.Output();
  99.  
  100.     Student student4;
  101.     student4.Input();
  102.     student4.Output();
  103.  
  104.     return 0;
  105. }
  106.  
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement