fork download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. #ifndef CLASS2_HPP
  7. #define CLASS2_HPP
  8.  
  9. class Passenger
  10. {
  11.  
  12. public:
  13.  
  14. enum class Location
  15. {
  16. Business,
  17. Economy,
  18. Vip
  19. };
  20.  
  21. Passenger(Location clas_s, char* firstName, char* secondName, int seat, int terminal, float time_of_departure);
  22.  
  23. const char* get_location() const;
  24. int get_seat() const;
  25. int get_terminal() const;
  26. float get_time() const;
  27. char* get_firstName() const;
  28. char* get_secondName() const;
  29. void print() const;
  30.  
  31. private:
  32.  
  33. Location _clas_s;
  34. char _firstName[50];
  35. char _secondName[50];
  36. int _seat;
  37. int _terminal;
  38. float _time_of_departure;
  39.  
  40. };
  41.  
  42. #endif // CLASS2
  43.  
  44.  
  45.  
  46.  
  47. Passenger::Passenger(Location clas_s, char* firstName, char* secondName, int seat, int terminal, float time_of_departure)
  48. : _clas_s(clas_s), _seat(seat), _terminal(terminal), _time_of_departure(time_of_departure) {
  49. strcpy(_firstName, firstName);
  50. strcpy(_secondName, secondName);
  51. };
  52.  
  53. void Passenger::print() const
  54. {
  55. cout << "Your name is " << _firstName
  56. << " " << _secondName << endl
  57. << "Your class is " << get_location() << endl
  58. << "Your seat is " << _seat << endl
  59. << "Your terminal is " << _terminal << endl
  60. << "Your time of departure is " << _time_of_departure << endl;
  61. }
  62.  
  63. const char* Passenger::get_location() const
  64. {
  65. switch (_clas_s)
  66. {
  67. case Location::Business : return "Business";
  68. case Location::Economy : return "Economy";
  69. case Location::Vip : return "Vip";
  70. }
  71. }
  72.  
  73. int main() {
  74.  
  75. Passenger p((Passenger::Location::Vip), "John", "Johnson", 25, 2, 13.53);
  76. p.print();
  77.  
  78. return 0;
  79. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Your name is John Johnson
Your class is Vip
Your seat is 25
Your terminal is 2
Your time of departure is 13.53