fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class FoodType {
  6. public:
  7. FoodType(string foodType);
  8. static int nextId;
  9. void Print();
  10. private:
  11. string type = "None";
  12. int id = 0;
  13. };
  14.  
  15. FoodType::FoodType(string foodType) {
  16. type = foodType;
  17. id = nextId;
  18.  
  19. nextId += 4;
  20. }
  21.  
  22. void FoodType::Print() {
  23. cout << type << ": " << id << endl;
  24. }
  25.  
  26. int FoodType::nextId = 10;
  27.  
  28. int main() {
  29. FoodType order1("Taco");
  30. FoodType order2("Cake");
  31. FoodType order3("Muffins");
  32.  
  33. order3.Print();
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Muffins: 18