Advertisement
Josif_tepe

Untitled

Jan 19th, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 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.         cout << "with parameters" << endl;
  22.     }
  23.    
  24.     Student(const Student & tmp) {
  25.         name = tmp.name;
  26.         surname = tmp.surname;
  27.         age = tmp.age;
  28.         average = tmp.average;
  29.        
  30.         cout << "copy constructor" << endl;
  31.     }
  32.    
  33.    
  34. };
  35.  
  36. int main()
  37. {
  38.    
  39.     Student s("Petar", "Petrovski", 23, 9.5);
  40.    
  41.     Student s2 = s;
  42.     Student s3(s);
  43.    
  44.    
  45.    
  46.    
  47.  
  48.     return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement