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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>
const int NUM_MENU_ITEMS = 20; //all the constants needed for the entire program up here
const int ORDERS = 100;
const double PA_SALES_TAX = 1.06;
struct Menu_Items //structuring the menu.txt
{
string Item;
double Price;
};
struct Orders //structures the orders.txt
{
string Menu_Item_Ordered;
string Day_of_Week;
string CustomerID;
int Quantity;
int Line_Item_Total;
};
void ProfitableDay(Orders Orders_Total[], Menu_Items The_Items_List[]);
double GetPrice( Menu_Items [] , string ); //for the getprice function down below
int main(int argc, char *argv[])
{
Menu_Items Menu_List[NUM_MENU_ITEMS];
int i = 0;
ifstream InFileMenu;
InFileMenu.open("Menu.txt");
ifstream InFileorders;
InFileorders.open("Orders.txt");
if ( InFileMenu.fail() ) //this section reads and loads the menu.txt and either outputs it in cout or tells you the file isn't found
{
cout << "The menu file was NOT successfully opened!" << endl;
cout << "Please ensure that the file exists." << endl;
}
else
{
cout << "The menu file was sucessfully opened!\n\n" << " WELCOME TO CHRISTIANs\n" << setw(10) << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
string Item;
double Price;
while (InFileMenu >> Item >> Price) //assigning values to menu.txt strings
{
cout << setw(20) << Item << setw(10) << " ------------- $" << Price << endl;
Menu_List[i].Item = Item;
Menu_List[i].Price = Price;
i++;
}
cout << setw(10) << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cin.ignore();
}
Orders Orders_Placed[ORDERS];
int Orders_Index = 0;
if (InFileorders.fail()) //this section reads and loads the orders.txt and either outputs it in cout or tells you the file isn't found
{
cout << "The order file was NOT successfully opened!\n" << endl;
cout << "Please ensure that the file exists." << endl;
}
else
{
cout << "The order file was sucessfully opened!\n" << setw(10) << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
string Menu_Item_Ordered, Day_of_Week, Customer_ID;
int Quantity, Max = 0, Num_of_Orders, Line_Item_Total;
while ( InFileorders >> Menu_Item_Ordered >> Quantity >> Day_of_Week >> Customer_ID ) //assignes values to orders.txt strings
{
cout << Day_of_Week << " - " << Quantity << " order(s) of " << setw(20) << Menu_Item_Ordered << setw(20) << " ID: " << Customer_ID << endl;
cout << setw(10) << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
Orders_Placed[Orders_Index].Menu_Item_Ordered = Menu_Item_Ordered;
Orders_Placed[Orders_Index].Quantity = Quantity;
Orders_Placed[Orders_Index].Day_of_Week = Day_of_Week;
Orders_Placed[Orders_Index].CustomerID = Customer_ID;
Orders_Index++;
if (Orders_Index > Max)
{
Max = Orders_Index;
Num_of_Orders = Orders_Index;
}
}
cin.ignore();
system("pause");
for (i = 0; i < Num_of_Orders; ++i) //Line Item Total adds up the total spent per order line
{
Line_Item_Total = Orders_Placed[i].Quantity * GetPrice(Menu_List, Orders_Placed[i].Menu_Item_Ordered) * PA_SALES_TAX;
Orders_Placed[i].Line_Item_Total = Line_Item_Total;
cout << "The line item total for " << Orders_Placed[i].Quantity << " " << setw(20) << Orders_Placed[i].Menu_Item_Ordered << setw(20) << " comes to $" << fixed << setprecision(2) << Orders_Placed[i].Line_Item_Total << endl;
}
}
void ProfitableDay(Orders[], Menu_Items[]); //supposed to call your void function
{
cout << "\nThe Most Profitable Day is "<< "Best_Day" << endl; //snagged here???
system("pause");
return 0;
}
}
double GetPrice( Menu_Items Menu[], string Item) //this function calculates the prices of the items
{
int i = 0;
for (i = 0; i < NUM_MENU_ITEMS; ++i)
if (Menu[i].Item == Item)
return Menu[i].Price;
}
void ProfitableDay(Orders Orders_Total[], Menu_Items The_Items_List[])
{
double MonTotals = {0};
double TueTotals = {0};
double WedTotals = {0};
double ThuTotals = {0};
double FriTotals = {0};
double SatTotals = {0};
double SunTotals = {0};
//int i;
string Item;
for(int i = 0; i < ORDERS; i++ ) //this is supposed to total up the money made per day.
{
if( Orders_Total[i].Day_of_Week == "Mon")
{
Item = Orders_Total[i].Menu_Item_Ordered;
MonTotals += ( GetPrice( The_Items_List, Item ) * Orders_Total[i].Quantity);
}
if( Orders_Total[i].Day_of_Week == "Tue")
{
Item = Orders_Total[i].Menu_Item_Ordered;
TueTotals += (GetPrice( The_Items_List, Item ) * Orders_Total[i].Quantity);
}
if( Orders_Total[i].Day_of_Week == "Wed")
{
Item = Orders_Total[i].Menu_Item_Ordered;
WedTotals += (GetPrice( The_Items_List, Item ) * Orders_Total[i].Quantity);
}
if( Orders_Total[i].Day_of_Week == "Thu")
{
Item = Orders_Total[i].Menu_Item_Ordered;
ThuTotals += (GetPrice( The_Items_List, Item ) * Orders_Total[i].Quantity);
}
if( Orders_Total[i].Day_of_Week == "Fri")
{
Item = Orders_Total[i].Menu_Item_Ordered;
FriTotals += (GetPrice( The_Items_List, Item ) * Orders_Total[i].Quantity);
}
if( Orders_Total[i].Day_of_Week == "Sat")
{
Item = Orders_Total[i].Menu_Item_Ordered;
SatTotals += (GetPrice( The_Items_List, Item ) * Orders_Total[i].Quantity);
}
if( Orders_Total[i].Day_of_Week == "Sun")
{
Item = Orders_Total[i].Menu_Item_Ordered;
SunTotals += (GetPrice( The_Items_List, Item ) * Orders_Total[i].Quantity);
}
}
double Best_Day = 0;
double Previous_Best_Day = 0; //this section here is supposed to find the best day comparing totals per all the days.
do
{
Previous_Best_Day = Best_Day;
if( MonTotals > SunTotals )
{
Best_Day = MonTotals;
}
if( TueTotals > MonTotals )
{
Best_Day = TueTotals;
}
if( WedTotals > TueTotals )
{
Best_Day = WedTotals;
}
if( ThuTotals > WedTotals )
{
Best_Day = ThuTotals;
}
if( FriTotals > ThuTotals )
{
Best_Day = FriTotals;
}
if( SatTotals > FriTotals )
{
Best_Day = SatTotals;
}
if( SunTotals > SatTotals )
{
Best_Day = SunTotals;
}
}
while( Best_Day != Previous_Best_Day);
return;
}
|