Advertisement
Josif_tepe

Untitled

Jan 19th, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Student {
  5. private:
  6.     string name, surname;
  7.     int age;
  8.     float average;
  9.    
  10. public:
  11.     Student () {
  12.         cout << "empty constructor" << endl;
  13.     }
  14.    
  15.     Student(string _name, string _surname, int _age, float _average) {
  16.         name = _name;
  17.         surname = _surname;
  18.         age = _age;
  19.         average = _average;
  20.        
  21.     }
  22.    
  23.     Student(const Student & tmp) {
  24.         name = tmp.name;
  25.         surname = tmp.surname;
  26.         age = tmp.age;
  27.         average = tmp.average;
  28.        
  29.     }
  30.    
  31.     // getters
  32.     string get_name() {
  33.         return name;
  34.     }
  35.    
  36.     string get_surname() {
  37.         return surname;
  38.     }
  39.    
  40.     int get_age() {
  41.         return age;
  42.     }
  43.    
  44.     float get_average() {
  45.         return average;
  46.     }
  47.    
  48.     //setters
  49.     void set_name(string _name) {
  50.         name = _name;
  51.     }
  52.     void set_surname(string _surname) {
  53.         surname = _surname;
  54.     }
  55.     void set_age(int _age) {
  56.         age = _age;
  57.     }
  58.     void set_average(float _average) {
  59.         average = _average;
  60.     }
  61.    
  62.     void print() {
  63.         cout << name << " " << surname << " " << age << " " << average << endl;
  64.     }
  65. };
  66.  
  67. int main()
  68. {
  69.    
  70.     Student s("Petar", "Petrovski", 23, 9.5);
  71.    
  72.    
  73.     cout << s.get_name() << " " << s.get_age() << endl;
  74.    
  75.     s.set_name("Petat");
  76.     cout << s.get_name() << endl;
  77.  
  78.     return 0;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement