Advertisement
nq1s788

ооп 1

Oct 23rd, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Student {
  8. public:
  9.     int group; ///класс -- поля
  10.     int age; ///возраст
  11.     string name; //имя
  12.     double grade; //оценка
  13.  
  14.     void hi() {
  15.         cout << "Привет, я " << name << ", мне " << age << " лет!\n";
  16.     }
  17.  
  18.     int solve(int a, int b) {
  19.         return a + b;
  20.     }
  21. };
  22.  
  23. int main() {
  24.     Student vasya;
  25.     vasya.age = 15;
  26.     vasya.group = 8;
  27.     vasya.name = "Вася";
  28.     vasya.grade = 5;
  29.     vasya.hi();
  30.     Student petya;
  31.     petya.age = 12;
  32.     petya.group = 6;
  33.     petya.name = "Петя";
  34.     petya.grade = 3;
  35.     petya.hi();
  36.     vasya.hi();
  37.     cout << petya.age << ' ' << vasya.age << '\n';
  38.     cout << petya.solve(10, 8);
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement