Solved 1 Answer
See More Answers for FREE
Enhance your learning with StudyX
Receive support from our dedicated community users and experts
See up to 20 answers per week for free
Experience reliable customer service
#include <iostream> #include <string> #include <vector> enum JuiceTypes{ Orange, Apple, Mango, Strawberry_Banana, None }; class Juice{ public: Juice(){} Juice(JuiceTypes _type){     type = _type; } void addJuice(JuiceTypes _type){     type = _type; } JuiceTypes getJuiceType(int t){     if(t == 0)       return Orange;     else if(t == 1)       return Apple;     else if(t == 2)       return Mango;     else if(t == 3)       return Strawberry_Banana;     return None; } int getJuicePrice(){     if(type == Orange)       return 50;     else if(type == Apple)       return 65;     else if(type == Mango)       return 80;     else if(type == Strawberry_Banana)       return 85;     return 0; } int getJuicePrice(JuiceTypes t){     if(t == Orange)       return 50;     else if(t == Apple)       return 65;     else if(t == Mango)       return 80;     else if(t == Strawberry_Banana)       return 85;     return 0; } private: JuiceTypes type; }; class JuiceShop{ public: JuiceShop(){     juice = new Juice(); } void open(){     int choice = 9;     int price = 0;     while(true){       displayMenu();       std::cin>>choice;       if(choice < 1){         std::cout<<"Invalid choice! try again"<<std::endl;         continue;       }       if(choice == 9)         break;       if(acceptMoney(choice - 1)){         releaseJuiceItem();       }else{         std::cout<<"Error on accepting money!"<<std::endl;       }     } } void close(){     delete juice; } private: void displayMenu(){     std::cout<<"*** Welcome to Shelly's Juice Shop ***"<<std::endl;     std::cout<<"To select an item, enter"<<std::endl;     std::cout<<"1 for orange juice ("<<juice->getJuicePrice(Orange)<<" cents)"<<std::endl;     std::cout<<"2 for apple juice ("<<juice->getJuicePrice(Apple)<<" cents)"<<std::endl;     std::cout<<"3 for mango juice ("<<juice->getJuicePrice(Mango)<<" cents)"<<std::endl;     std::cout<<"4 for strawberry banana juice ("<<juice->getJuicePrice(Strawberry_Banana)<<" cents)"<<std::endl;     std::cout<<"9 to exit"<<std::endl; } bool acceptMoney(int t){     if(t < 0)       return false;     JuiceTypes type = juice->getJuiceType(t);     int juicePrice = 0, customerPrice = 0;     if(type == None)       return false;     juice->addJuice(type);     juicePrice = juice->getJuicePrice();     std::cout<<"Please deposit "<<juicePrice<<" cents"<<std::endl;     std::cin>>customerPrice;     if(customerPrice == juicePrice){       return true;     }else if(customerPrice < juicePrice){       int p = juicePrice - customerPrice;       while(true){         std::cout<<"Please deposit another "<<p<<" cents"<<std::endl;         std::cin>>customerPrice;         p -= customerPrice;         if(p == 0)           return true;       }     }     return false; } void releaseJuiceItem(){     std::cout<<"Collect your item at the bottom and enjoy"<<std::endl;     std::cout<<"*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*"<<std::endl;     std::cout<<std::endl; } private: Juice *juice; }; int main() { JuiceShop juiceShop; juiceShop.open(); juiceShop.close(); return 0; } ...