1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
#include <iostream>
#include <string>
#include <iomanip>
#include "Restaurant.h"
using namespace std;
const int MAX = 100;
enum choice{ADD = 1, PRINT, EXIT};
int ReadMenuChoice();
void ProcessChoice(int choice, Restaurant R[], int&count);
void ReadName(Restaurant R[]);
void ReadRating(Restaurant R[], int count);
void ReadHour(Restaurant R[], int count, string label1, string label2);
void displayMenu();
void displayInputMenu(Restaurant R[], int& count);
void displayOutputMenu( Restaurant R[], int count);
int crashPrevention();
void writeLine(char line, int size);
//function name: main()
//purpose:sets name, rating, opening and closing time for a restaurant
//input: none
//output:none
//in param:none
//out param:none
//return: 0
//function called: ReadMenuChoice();, ProcessChoice()
int main()
{
Restaurant R[MAX];
int choice;
int count = 0;
choice = ReadMenuChoice();
while(EXIT != (choice) )
{
ProcessChoice(choice, R, count);
choice = ReadMenuChoice();
}
return 0;
}
int ReadMenuChoice()
{
int choice;
bool valid;
do
{
displayMenu();
cin >> choice;
if(choice < ADD || choice > EXIT)
{
cout << "Invalid input" << endl;
valid = false;
}
else
valid = true;
}while(!valid);
cin.ignore(1000, '\n');
return choice;
}
void ProcessChoice(int choice, Restaurant R[], int&count)
{
switch(choice)
{
case ADD:
displayInputMenu(R, count);
break;
case PRINT:
displayOutputMenu(R, count);
break;
}
}
void ReadName(Restaurant R[], int count, string label)
{
string title;
bool valid;
do
{
cout << label;
getline(cin, title);
if(title == "")
{
cout << "Invaliid input" << endl;
valid = false;
}
else
{
valid = true;
}
}while(!valid);
R[count].setTitle(title);
}
void ReadRating(Restaurant R[], int count, string label)
{
bool valid;
int rating;
do
{
cout << label;
cin>>rating;
if(rating < 1 || rating > 5)
{
cout << "invalid" << endl;
valid = false;
}
else
valid = true;
}while(!valid);
R[count].setRating(rating);
}
void ReadHour(Restaurant R[], int count, string label1, string label2)
{
cout << label1<<endl;
R[count].setOpeningHour();
cout << label2<<endl;
R[count].setClosingHour();
}
void displayMenu()
{
cout << "MENU" << endl;
cout << "1. Add Movie" << endl;
cout << "2. Print All " << endl;
cout << "3. Exit" << endl;
}
void displayInputMenu(Restaurant R[], int& count)
{
ReadName( R, count, "Name: ");
ReadRating(R, count, "Rating: ");
ReadHour(R, count, "Opening Hour:", "Closing Hour:");
count++;
}
void displayOutputMenu(Restaurant R[], int count)
{
cout << "RESTAURANTS: " << endl;
for(int n = 0; n<count; n++)
{
writeLine('=', 50);
cout << "Name" << setw(20) << "Rating" << setw(10)
<< "Open" << setw(10) << "Close" << endl;
writeLine('-', 50);
cout << R[n].getTitle();
cout << setw(20);
cout << R[n].getRating();
cout << setw(10);
cout << R[n].getOpeningHour() << setw(10) << R[n].getClosingHour() << endl;
}
writeLine('-', 50);
}
int crashPrevention()
{
bool valid;
if(cin.fail())
{
cout << "Invaliid input" << endl;
valid = false;
cin.clear();
}
else
{
valid = true;
}
cin.ignore(1000, '\n');
return valid;
}
void writeLine(char line, int size)
{
cout << setfill(line) << setw(size) << " " << endl;
cout << setfill(' ') << endl;
}
|