Advertisement
Josif_tepe

Untitled

Oct 28th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 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.    
  9. public:
  10.     Student() {
  11.         name = "";
  12.         surname = "";
  13.         age = 0;
  14.     }
  15.     Student(string _name, string _surname, int _age) {
  16.         name = _name;
  17.         surname = _surname;
  18.         age = _age;
  19.     }
  20.    
  21.     Student(const Student &object) {
  22.         name = object.name;
  23.         surname = object.surname;
  24.         age = object.age;
  25.     }
  26.    
  27.     string get_name() {
  28.         return name;
  29.     }
  30.     string get_surname() {
  31.         return surname;
  32.     }
  33.     int get_age() {
  34.         return age;
  35.     }
  36.    
  37.     void set_name(string s) {
  38.         name = s;
  39.     }
  40.     void set_surname(string s) {
  41.         surname = s;
  42.     }
  43.     void set_age(int a) {
  44.         age = a;
  45.     }
  46.   friend ostream& operator << ( ostream& stream, Student &object);
  47.    
  48. };
  49. ostream& operator << (ostream &stream, Student &object) {
  50.     stream << object.name << " " << object.surname << " " << object.age << endl;
  51.     return stream;
  52. }
  53. int main() {
  54.  
  55.     Student s;
  56.     s.set_name("josif");
  57.     s.set_surname("tepegjozov");
  58.     s.set_age(100);
  59.    
  60.     cout << s << endl;
  61.    
  62.     return 0;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement