fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Meal {
  5. private:
  6. float price;
  7.  
  8. public:
  9. string mealName;
  10. string size;
  11.  
  12. Meal(string m_mealName, string m_size) {
  13. mealName = m_mealName;
  14. size = m_size;
  15. price = 0;
  16. }
  17.  
  18. Meal() {
  19. price = 0;
  20. mealName = "";
  21. size = "";
  22. }
  23.  
  24. float getPrice() {
  25. return price;
  26. }
  27.  
  28. void setPrice(float p) {
  29. if (p > 0) {
  30. price = p;
  31. } else {
  32. cout << "price must be greater than zero" << endl;
  33. }
  34. }
  35.  
  36. void showInfo() {
  37. cout << "Size: " << size << endl;
  38. cout << "Meal name: " << mealName << endl;
  39. cout << "Price: " << price << endl;
  40. }
  41. };
  42.  
  43. int main() {
  44. Meal meal1("Burger", "Large");
  45. Meal meal2("Pizza", "Small");
  46.  
  47. meal1.setPrice(1299.0);
  48. meal2.setPrice(13999.0);
  49.  
  50. cout << "menu items:" << endl;
  51. meal1.showInfo();
  52. meal2.showInfo();
  53.  
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
menu items:
Size: Large
Meal name: Burger
Price: 1299
Size: Small
Meal name: Pizza
Price: 13999