Advertisement
bhok

C++ Get/Set

Jun 1st, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. // Doesn't this code looks familar? Hm.
  6. // This looks a bit complex, please look at the code piece by piece
  7.  
  8.  
  9. // What two functions did kfcStore get?
  10. class kfcStore
  11. {
  12. public:
  13.     void setMenuName(string name)
  14.     {
  15.         menuName = name;
  16.     }
  17.  
  18.  
  19.     string getMenuName()
  20.     {
  21.         return menuName;
  22.     }
  23.  
  24.     void makeFoodFunction(string menuName)
  25.     {
  26.         // It appears we added something here. What did we add exactly?
  27.         // Don't tell me getMenuName()...Haha.
  28.         cout << "Hamburgers and " << getMenuName() << endl;
  29.  
  30.     }
  31. // Do you recall the differences between public and private access specifiers?
  32. private:
  33.     string menuName;
  34.  
  35.  
  36. };
  37.  
  38. int main()
  39. {
  40.     string dollarMenu;
  41.     kfcStore objectPopcornMachine;
  42.  
  43.     cout << "May I take your ORDER!?! " << objectPopcornMachine.getMenuName() << endl;
  44.  
  45.     cout << "What would you like sir?" << endl;
  46.     getline(cin, dollarMenu);
  47.     // So what exactly happened here? Please explain?
  48.     objectPopcornMachine.setMenuName(dollarMenu);
  49.  
  50.     objectPopcornMachine.makeFoodFunction(dollarMenu);
  51.     system("pause");
  52.  
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement