HarryGSn

[GR] Simple C++ Class Example

Jun 20th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. // ποιος δεν βαριέται να βάζει συνέχεια std::...
  5. using namespace std;
  6.  
  7. // Κλάση <Person>
  8. class Person
  9. {
  10. public:
  11.     Person(string name, string car , int age)
  12.         {
  13.             this->name = name;
  14.             this->car = car;
  15.             this->age = age;
  16.         }
  17.  
  18.         // Όνομα του <Person>
  19.         string getName(string name)
  20.         {
  21.             cout << "Provide the Name of the Person" << endl;
  22.             cin >> name;
  23.             return name;
  24.         }
  25.  
  26.         // Όνομα αυτοκινήτου του <Person>
  27.         string getCar(string car)
  28.         {
  29.             cout << "Provide the Name of the Person's car" << endl;
  30.             cin >> car;
  31.             return car;
  32.         }
  33.  
  34.         // Ηλικία του <Person>
  35.         int getAge(int age)
  36.         {
  37.             cout << "Provide the Age of the Person" << endl;
  38.             cin >> age;
  39.             return age;
  40.         }
  41.  
  42. private:
  43.       string name, car;
  44.       int age;
  45. };
  46.  
  47. int main()
  48. {
  49.     string name;
  50.     string car;
  51.     int age;
  52.  
  53.     cout << "Let's write some info!" << endl;
  54.    
  55.     Person User(name, car , age);
  56.  
  57.     cout << "Person's name: " << User.getName(name) << endl;
  58.     cout << "Person's Car: " << User.getCar(car) << endl;
  59.     cout << "Person's age: " << User.getAge(age) << endl;
  60.  
  61.     system("pause");
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment