Advertisement
nq1s788

ооп(1)

Oct 2nd, 2024
93
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 grade; ///класс -- поля
  10.     int age; ///возраст
  11.     string name; //имя
  12.     double score; //оценка
  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.grade = 8;
  27.     vasya.name = "Vasya";
  28.     vasya.score = 5;
  29.     vasya.hi();
  30.     Student petya;
  31.     petya.age = 12;
  32.     petya.grade = 6;
  33.     petya.name = "Petya";
  34.     petya.hi();
  35.     petya.score = 3;
  36.     cout << petya.age << ' ' << vasya.age << '\n';
  37.  
  38.     int x = petya.solve(2, 3);
  39.     cout << x;
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement