CafeInterface.cpp // Interface file for Vicks Cafe program. This will read the dishes from a // file, load them into the arrqay of dishes, then print out a menu. // File: menumain.cpp // Author: Dave Wallace // Version: 1.0, 17 June 1998 #include "CafeInterface.h" #include "menu.h" #include #include #include #include using namespace std; bool bLoaded = false; void CafeInterface::Run() { cout << "Welcome to Vick's Cafe"<> iOption; string sDummy; string sDishName; string sDishDesc; float fDishPrice; do { switch ( iOption ) { case 1: if ( !bLoaded ) LoadFromFile(); // Add a dish // ******* problems here used a dummy input cout << "Enter the name of the New Dish "<> fDishPrice; if (!xmMyMenu.AddDishtoMenu(sDishName, sDishDesc, fDishPrice )) { cout << "There has been an error adding to the menu "<> iOption; }while(iOption != 9); getch(); return; } void CafeInterface::LoadFromFile() { { cout<<"Enter name of input file :"; char acFile[20]; cin>>acFile; ifstream isFile( acFile ); if ( !isFile ) { cout << "I can't open the file" << endl; } else { xmMyMenu.LoadDishes( isFile ); bLoaded = true; } } } //___________________________________________________________________________ CafeMain.cpp // File: Cafemain.cpp // Author: Dave Wallace // Version: 1.0, 17 June 1998 #include "CafeInterface.h" #include "menu.h" #include #include #include using namespace std; int main() { CafeInterface xCIVicks; xCIVicks.Run(); cout << "Goodbye"< #include #include "dish.h" using namespace std; // Read the name and description of the dish from a stream. Dish::Dish( istream &isFile ) { getline( isFile, m_sName ); getline( isFile, m_sDescription ); isFile >> m_fPrice; isFile.ignore(1,'\n'); } Dish::Dish(const string &sDishName, const string &sDishDesc, float fDishPrice) { m_sName = sDishName; m_sDescription = sDishDesc; m_fPrice = fDishPrice; } // Write the dish to a stream in "menu format". void Dish::Write( ostream &osMenu ) { osMenu << m_sName << " $" << m_fPrice << endl; osMenu << m_sDescription << endl; osMenu << endl; return; } string Dish::GetsDishName() { return m_sName; } string Dish::GetsDishDesc() { return m_sDescription; } //___________________________________________________________________________________ Menu.cpp // Definition of "Menu" class: this is a container class for an // array of dish objects. // File: menu.cpp // Author: Dave Wallace // Version: 1.0, 17 June 1998 #include #include #include #include "menu.h" #include "dish.h" //# define DISHLIMIT 10 using namespace std; Menu::Menu() { m_iNoDishes = 0; } Menu::~Menu() { for(int iCount = 0; iCount< m_iNoDishes; iCount++) { delete m_axFood[iCount]; } } void Menu::LoadDishes(istream &isFile ) { int iPlace; m_iNoDishes = 0; for( iPlace = 0; iPlace < 6; iPlace++ ) { m_axFood[ iPlace ] = new Dish( isFile ); m_iNoDishes++; cout<<"no dishes "<Write( osMenu ); } } return; } bool Menu::AddDishtoMenu(const string &sDishName, const string &sDishDesc, float fDishPrice ) { if ( m_iNoDishes == DISHLIMIT) { //cout<<"There are too many Dishes to store in the array"< #include using namespace std; class CafeInterface { public: void Run(); void LoadFromFile(); void PrintMenu(); private: Menu xmMyMenu; }; #endif //______________________________________________________________________________ dish.h // Declaration of "Dish" class: stores a single dish name, dish // description and price. An object of this class can read these // details from a stream, prompt the user for a price, and write // itself to a menu. // File: dish.h // Author: Dave Wallace // Version: 1.0, 17 June 1998 #ifndef DISH_H #define DISH_H #include #include using namespace std; class Dish { public: Dish (istream &isFile); Dish(const string &sDishName, const string &sDishDesc,float fDishPrice); void Write( ostream &osMenu ); string GetsDishName(); string GetsDishDesc(); private: string m_sName; string m_sDescription; float m_fPrice; }; #endif //___________________________________________________________________________________ menu.h // Declaration of "Menu" class: this is a container class for an // array of 6 dish objects. // File: menu.h // Author: Dave Wallace // Version: 1.0, 17 June 1998 #ifndef MENU_H #define MENU_H # define DISHLIMIT 10 #include "dish.h" #include using namespace std; class Menu { public: Menu(); ~Menu(); void LoadDishes(istream &isMenu ); void WriteMenu(); bool AddDishtoMenu(const string &sDishName,const string &sDishDesc, float fDishPrice ); int FindItem( const string &sDishName, const string &sDishDesc ) const; private: Dish * m_axFood[ DISHLIMIT ]; int m_iNoDishes; }; #endif //_____________________________________________________________________________________ food.txt filet mignon fillet steak special 25.50 spanish omelette vegetarian omelette extraordinaire 14.50 Mussel Chowder Thick soup made from fresh Titahi Bay mussels 7.50 Chicken Ravioli Packets of Pasta filled with chicken in a white wine sauce 15.50 Beef Wellington Beef and Bacon rolls with our special spicy stuffing 13.00 Fruit Salad Straight from the tin to the table 3.50 //______________________________________________________________________ menu.txt Welcome to Vick's Cafe!! filet mignon $25.50 fillet steak special spanish omelette $14.50 vegetarian omelette extraordinaire Mussel Chowder $7.50 Thick soup made from fresh Titahi Bay mussels Chicken Ravioli $15.50 Packets of Pasta filled with chicken in a white wine sauce Beef Wellington $13.00 Beef and Bacon rolls with our special spicy stuffing Fruit Salad $3.50 Straight from the tin to the table chicken fettucine with pesto $15.75 its got chicken breast and yummy pesto