fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Bicycle {
  6. public:
  7. Bicycle();
  8. void SetType(string bicycleType);
  9. void SetYear(int bicycleYear);
  10. void Print();
  11. private:
  12. string type;
  13. int year;
  14. };
  15.  
  16. Bicycle::Bicycle() {
  17. type = "NoType"; // NoType indicates brand was not set
  18. year = -1; // -1 indicates year was not set
  19. }
  20.  
  21. void Bicycle::SetType(string bicycleType) {
  22. type = bicycleType;
  23. }
  24.  
  25. void Bicycle::SetYear(int bicycleYear) {
  26. year = bicycleYear;
  27. }
  28.  
  29. void Bicycle::Print() {
  30. cout << type << " " << year << endl;
  31. }
  32.  
  33. int main() {
  34. Bicycle commuterBike;
  35.  
  36. commuterBike.Print();
  37.  
  38. commuterBike.SetType("sport");
  39.  
  40. commuterBike.Print();
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
NoType -1
sport -1