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
|
int main(int argc, char *argv[])
{
int selection;
int n;
string file;
string filename;
int numberInput;
string nameInput;
vector<string> Names; // set to 15???
vector<int> Numbers;
int i;
do
{
menuSelection(selection , Names );
performSelection(selection, file, filename, numberInput, nameInput, Names, Numbers);
} while (selection !=0);
system("PAUSE");
return EXIT_SUCCESS;
}
void menuSelection(int &selection, vector<string> &Names)
{
cout << "1. Load Inventory" << endl;
cout << "2. Add Item" << endl;
cout << "3. Search for Item" << endl;
cout << "4. List Items" << endl;
cout << "5. Save Inventory" << endl;
cout << "6. End Program" << endl;
cout << "Number of Items in Inventory: "<< Names.size() << endl;
cout << endl;
cout << "Enter the number of the action you would like to do: " << endl;
cin >> selection;
}
void performSelection(int &selection, string &file ,string &filename, int &numberInput, string &nameInput, vector<string> &Names, vector<int> &Numbers)
{
if (selection==1)
{
loadfile(filename, Numbers, Names);
}
if (selection==2)
{
additem(numberInput, nameInput, Names, Numbers);
}
if (selection == 3)
{
searchitems(Numbers, Names);
}
if(selection == 4)
{
listitems(Names, Numbers);
}
if (selection == 5)
{
saveinventory(file, Numbers, Names);
}
if (selection == 6)
{
system ("PAUSE");
exit (1);
}
}
void loadfile(string &filename, vector<int> &Numbers, vector<string> &Names)
{
int i;
ifstream inputFile;
string line;
cout << "Enter the filename where the inventory is stored: " << endl;
cin >> filename;
inputFile.open(filename.c_str());
for (i = 0 ; i < Numbers.size() ; i++)
{
getline(inputFile, Numbers[i]);
getline(inputFile, Names[i]);
}
if (inputFile.fail())
{
cerr << "File opening failed.\n";
system ("PAUSE");
exit (1);
}
else
{
cout << "The file opened" << endl;
}
}
void saveinventory(string &file, vector<int> &Numbers, vector<string> &Names)
{
int i;
cout << "Enter what you would like the File Name to be: ";
cin >> file;
ofstream outputFile;
outputFile.open("filename");
for (i = 0 ; i < Numbers.size() ; i++)
{
outputFile << Numbers[i] << endl;
outputFile << Names[i] << endl;
}
outputFile.close();
}
|