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
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int SIZE = 5;
int stores[SIZE];
string food[SIZE] = { "Milk", "Eggs", "Beef", "Poultry", "Flour" };
const int milk_Choice = 1;
const int eggs_Choice = 2;
const int beef_Choice = 3;
const int poultry_Choice = 4;
const int flour_Choice = 5;
const int list_Choice = 6;
const int math_Choice = 7;
const int output_Choice = 8;
const int input_Choice = 9;
const int end_Choice = 10;
void options();
void addFunction(int stores[]);
void showMilk(int stores[], string food[]);
void showEggs(int stores[], string food[]);
void showBeef(int stores[], string food[]);
void showPoultry(int stores[], string food[]);
void showFlour(int stores[], string food[]);
void fromFile(int stores, ifstream &inFile);
void toFile(int stores, ofstream &outFile);
void mathTotal(int stores);
int main()
{
int choice;
ofstream outFile("Total_List.txt");
ifstream inFile("Total_List.txt");
cout << "This program will allow you to store and view common foodstuffs in stock" << endl;
cout << endl;
options();
cin >> choice;
do
{
if (choice > 10 || choice < 0)
{
cout << "Please enter an appropriate choice" << endl;
cin >> choice;
}
else if (choice == milk_Choice)
{
showMilk(stores, food);
options();
cin >> choice;
}
else if (choice == eggs_Choice)
{
showEggs(stores, food);
options();
cin >> choice;
}
else if (choice == beef_Choice)
{
showBeef(stores, food);
options();
cin >> choice;
}
else if (choice == poultry_Choice)
{
showPoultry(stores, food);
options();
cin >> choice;
}
else if (choice == flour_Choice)
{
showFlour(stores, food);
options();
cin >> choice;
}
else if (choice == list_Choice)
{
addFunction(stores);
options();
cin >> choice;
}
else if (choice == math_Choice)
{
mathTotal(stores);
options();
cin >> choice;
}
else if (choice == output_Choice)
{
toFile(stores, outFile);
options();
cin >> choice;
}
else if (choice == input_Choice)
{
fromFile(stores, inFile);
options();
cin >> choice;
}
else if (choice == end_Choice)
return 0;
} while (choice == milk_Choice || choice == eggs_Choice || choice == beef_Choice || choice == poultry_Choice || choice == flour_Choice || choice == list_Choice);
system("pause");
return 0;
}
void options()
{
cout << "Please select from the following options" << endl;
cout << "1. View Milk(Gallons)" << endl;
cout << "2. View Eggs(Dozens)" << endl;
cout << "3. View Beef(lbs.)" << endl;
cout << "4. View Poultry(lbs.)" << endl;
cout << "5. View Flour(lbs.)" << endl;
cout << "6. Input A New Item" << endl;
cout << "7. Total amount of all items" << endl;
cout << "8. Send information to file" << endl;
cout << "9. Retrieve information from file" << endl;
cout << "10. End Program" << endl;
}
void addFunction(int stores[]) // The various sum functions
{
for (int i = 0; i < SIZE; i++)
{
cout << "Enter how many " << food[i] << " you wish to add." << endl;
cin >> stores[i];
cout << endl;
}
}
void showMilk(int stores[], string food[])
{
cout << "You have " << stores[0] << " gallons of "<< food[0] << endl;
cout << endl;
}
void showEggs(int stores[], string food[])
{
cout << "You have " << stores[1] << " dozen "<< food[1] << endl;
cout << endl;
}
void showBeef(int stores[], string food[])
{
cout << "You have " << stores[2] << " pounds of "<< food[2] << endl;
cout << endl;
}
void showPoultry(int stores[], string Food[])
{
cout << "You have " << stores[3] << " pounds of "<<food[3] << endl;
cout << endl;
}
void showFlour(int stores[], string food[])
{
cout << "You have " << stores[4] << " pounds of "<<food[4] << endl;
cout << endl;
}
void toFile(int stores[], ofstream &outFile)
{
for (int i = 0; i < SIZE; i++)
outFile << stores[i];
cout << " The quantity of each item has been listed onto the file" << endl;
}
void fromFile(int stores[], ifstream &inFile)
{
for (int i = 0; i < SIZE; i++)
inFile >> stores[i];
cout << " Your inventory has been updated from the file" << endl;
}
void mathTotal(int stores[])
{
int total = 0;
for (int count = 0; count < SIZE; count++)
total += stores[count];
cout << " The total amount of food items you have is " << total << endl;
}
|