/*
************************************************** ***********************
* *
* Main menu and function calls for soft drink inventory *
* *
* Team project for CS218a :: Mr. Steven King *
* *
* Team Members: Andrew Gonyea, Rick Hedden, James Kreger *
* *
************************************************** ***********************
*/
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <time.h>
#include <vector>
#include <stdlib.h>
#define SIZE 26
using namespace std;
using std::string;
//variable definitions
int l = 0;
int i = 0;
// data structures
struct productType
{
string brand;
string flavor;
string descript;
string size;
string SKU;
double deposit;
};
productType drink[1000];
struct costType
{
string sku;
double cost;
double salePrice;
};
costType drinkCost[3000];
struct companyType
{
string VID;
string coName;
string contactName;
string address1;
string address2;
string city;
string state;
string zip;
string phone;
string fax;
};
companyType vendor[1000];
struct invenType
{
string sku;
int quantity;
};
invenType inventoryLine[1000];
void makeLine(int); // function declarations
//void updateInfo (productType drink[],companytype vendor[]);
char updateProduct(productType drink[]);
char displayProduct(productType drink[]);
char updateVendor(companyType vendor[]);
char displayVendor(companyType vendor[]);
char updateMenu();
void makeLine(int l);
char makeMenu();
///////////////////////// MAIN FUNCTION /////////////////////////////////////////////
int main ()
{
char select;
select = 'i';
//set length of line
int l;
l = 55;
//Make the main menu
while(select != 'q' && select != 'Q')
{
select = makeMenu();
if(select == 'c' || select == 'C')
{
select = 'C';
//replace the following line with the call to the check() function
cout << "\t\tBegin Inventory Check" << endl;
}
if(select == 'a' || select == 'A')
{
select = 'A';
//replace the following line with the call to the addProduct() function
cout << "\t\tBegin Inventory Addition" << endl;
}
if(select == 's' || select == 'S')
{
select = 'S';
//replace the following line with the call to the sellProduct() function
cout << "\t\tBegin Sale" << endl;
}
if(select == 'u' || select == 'U')
{
select = 'U';
char changeAnother;
changeAnother = 'R';
char updateChoice = 'q';
cout << "\t\tBegin update function: " << endl << flush;
system ("CLS");
updateChoice = updateMenu();
if(updateChoice == 'v' || updateChoice == 'V')
{
updateChoice = 'V';
cout << "\t\tBegin Vendor Update" << flush;
while(changeAnother == 'R')
{
changeAnother = updateVendor(vendor);
}
}
if(updateChoice == 'd' || updateChoice == 'D')
{
updateChoice = 'D';
cout << "\t\tDisplay Vendor data" << flush;
changeAnother = displayVendor(vendor);
}
if(updateChoice == 'r' || updateChoice == 'R')
{
updateChoice = 'R';
cout << "\t\tReport Product data" << flush;
changeAnother = displayProduct(drink);
}
if(updateChoice == 'p' || updateChoice == 'P')
{
updateChoice = 'P';
cout << "\t\tBegin Product Update" << flush;
while(changeAnother == 'R')
{
changeAnother = updateProduct(drink);
}
}
}
if(select == 'q' || select == 'Q')
{
return 0;
}
} // end while loop
return 0;
}
////////////////////// CALLED MENU FUNCTIONS ///////////////////////////////////
char makeMenu()
{
int i;
char branch;
branch = 'i';
cout << flush;
system ("CLS");
makeLine(65);
for(i=0;i<2;i++)
{
cout << endl;
}
cout << "\t\t" << "Soft-Drink-Co -:- Inventory Control System " << endl << endl;
time_t ltime;
wchar_t buf[size];
errno_t err;
time( <ime );
err = _wctime_s( buf, SIZE, <ime );
if (err != 0)
{
printf("Invalid Arguments for _wctime_s. Error Code: %d\n", err);
}
wprintf( L"\t\tToday is %s\n", buf );
for(i=0;i<2;i++)
{
cout << endl;
}
makeLine(65);
cout << "\t\t" << "Enter a single-letter command" << endl << endl;
cout << "\t\t" << "C - Check inventory" << endl;
cout << "\t\t" << "A - Add product to inventory" << endl;
cout << "\t\t" << "S - Sell product in inventory" << endl;
cout << "\t\t" << "U - Update or display product/vendor info" << endl;
cout << "\t\t" << "Q - Quit program" << endl;
cout << endl << "\t\t" << "Please enter your selection now: ";
cin >> branch;
return branch;
}
void makeLine(int l)
{
int p;
cout << " ";
for(p=0;p<l;p++)
{
cout << "*";
}
cout << endl;
return;
}
////////////////////// CALLED APPLICATION FUNCTION ////////////////////////////
char updateMenu()
{
int i;
char branch,updateFlag;
branch = 'i';
makeLine(65);
for(i=0;i<2;i++)
{
cout << endl;
}
cout << "\t\t" << "Soft-Drink-Co -:- Inventory Control System " << endl << endl;
time_t ltime;
wchar_t buf[size];
errno_t err;
time( <ime );
err = _wctime_s( buf, SIZE, <ime );
if (err != 0)
{
printf("Invalid Arguments for _wctime_s. Error Code: %d\n", err);
}
wprintf( L"\t\tToday is %s\n", buf );
for(i=0;i<2;i++)
{
cout << endl;
}
makeLine(65);
cout << endl << endl;
cout << "\t\tWould you like to update Vendor or Product information? " << endl;
cout << "\t\t" << "Enter a single-letter command" << endl << endl;
cout << "\t\t" << "V - Update Vendor info" << endl;
cout << "\t\t" << "D - Display Vendor data" << endl;
cout << "\t\t" << "P - Update product info" << endl;
cout << "\t\t" << "R - Report proudct info" << endl;
cout << "\t\t" << "Q - Return to main menu" << endl;
cout << endl << "\t\t" << "Please enter your selection now: ";
cin >> updateFlag;
return updateFlag;
}
//////////////////////////// Function updates Vendor Data //////////////////////
char updateVendor(companyType vendor[])
{
// declare variables
char pause;
char vendorUpdateContinue = 'Y';
char recordUpdateContinue = 'Y';
string spacer;
string searchVID;
string searchNameString;
string tempString;
int foundItem;
int choiceNum = 0;
int selectItem = 0;
int maxRecord;
int candidateRecord[20];
// define input files
ifstream vendorFile;
ofstream newVendorFile;
vendorFile.open("vendorData.txt");
if (!vendorFile) //test for presence of productFile
{
cout << "\t\tUnable to open vendor DATA file." << endl;
cout << "\t\tPlease contact developer." << endl;
cout << "\t\tThis program will end." << endl;
return 'X';
}
system ("CLS");
cin.ignore(100,'\n');
for (i = 0;i < 1000;i++)
{
getline(vendorFile,vendor[i].VID);
getline(vendorFile,vendor[i].coName);
getline(vendorFile,vendor[i].contactName);
getline(vendorFile,vendor[i].address1);
getline(vendorFile,vendor[i].address2);
getline(vendorFile,vendor[i].city);
getline(vendorFile,vendor[i].state);
getline(vendorFile,vendor[i].zip);
getline(vendorFile,vendor[i].phone);
getline(vendorFile,vendor[i].fax);
}
//vendorFile.close();
cout << "\t\tRecent vendor entries:" << endl << endl;
for (i = 0;i < 1000;i++)
{
if(vendor[i].VID.empty())
{
maxRecord = i;
i = 1000;
}
else
{
cout << "\t\t" << vendor[i].VID << "\t\t"
<< vendor[i].coName << endl;
}
}
cout << endl << "\t\tMake a note of Vendor ID before proceding. " << endl << endl << "\t\t";
system("PAUSE");
while(vendorUpdateContinue=='Y')
{
system ("CLS");
makeLine(65);
cout << endl;
cout << "\t\tEnter Vendor ID of record to change, " << endl;
cout << "\t\tor, to search by company name, enter \'??\'" << endl;
cout << "\t\tto abandon ALL changes and return" << endl;
cout << "\t\tto the main menu enter 9999." << endl << endl;
makeLine(65);
cout << endl << endl << "\t\t";
getline(cin,searchVID);
if(searchVID=="9999")
{
return 'X';
}
if(searchVID=="??") // VID unknown, search by XX*
{
system ("CLS");
makeLine(65);
cout << endl << endl;
cout << "\t\tSearch for vendor data by first three " << endl;
cout << "\t\tletters of company name or enter 9999 to" << endl;
cout << "\t\tabandon ALL changes and return to main menu." << endl;
cout << endl << endl;
makeLine(65);
cout << "\t\t";
cin.ignore(100,'\n');
getline(cin,searchNameString);
cout << searchNameString;
system ("CLS");
makeLine(65);
cout << endl;
cout << "\t\tMatching records: " << endl;
for(i=0;i < maxRecord;i++)
{
if(vendor[i].coName.substr(0,3)==searchNameString)
{
candidateRecord[choicenum]= i;
choiceNum++;
cout << "\t\t" << choiceNum << ": " << vendor[i].coName;
}
}
makeLine(56);
if(choiceNum==0)
{
cout << endl << "\t\tNo records found." << endl;
break;
}
else if(choiceNum==1)
{
cout <<endl << "\t\tJust one company matches search: " << vendor[0].coName << endl;
foundItem = 0;
}
cout << endl;
cout << "\t\tEnter the line number of the record you want to update: ";
cin >> selectItem;
foundItem = candidateRecord[selectitem];
}
for(i=0;i<1000;i++)
{
if(vendor[i].VID==searchVID)
{
foundItem = i;
i = maxRecord;
}
}
while(recordUpdateContinue=='Y')
{
system ("CLS");
makeLine(65);
cout << endl << endl;
cout << "\t\t1. " << vendor[founditem].VID << endl;
cout << "\t\t2. " << vendor[founditem].coName << endl;
cout << "\t\t3. " << vendor[founditem].contactName << endl;
cout << "\t\t4. " << vendor[founditem].address1 << endl;
cout << "\t\t5. " << vendor[founditem].address2 << endl;
cout << "\t\t6. " << vendor[founditem].city << endl;
cout << "\t\t7. " << vendor[founditem].state << endl;
cout << "\t\t8. " << vendor[founditem].zip << endl;
cout << "\t\t9. " << vendor[founditem].phone << endl;
cout << "\t\t10. " << vendor[founditem].fax << endl;
cout << endl;
makeLine(65);
cout << "\t\tEnter the line number you would like to update" << endl;
cout << "\t\tor enter 0 to abandon changes and return to menu.\t\t ";
cin >> selectItem;
cin.ignore(100,'\n');
switch (selectItem)
{
case 0:
break;
case 1:
{
cout << "\t\tEnter new data for "
<< "Vendor ID: ";
getline(cin,vendor[founditem].VID);
break;
}
case 2:
{
cout << "\t\tEnter new data for "
<< "Vendor company name: ";
getline(cin,vendor[founditem].coName);
break;
}
case 3:
{
cout << "\t\tEnter new data for "
<< "Vendor contact name: ";
getline(cin,vendor[founditem].contactName);
break;
}
case 4:
{
cout << "\t\tEnter new data for "
<< "Vendor address line 1: ";
getline(cin,vendor[founditem].address1);
break;
}
case 5:
{
cout << "\t\tEnter new data for "
<< "Vendor address line 2: ";
getline(cin,vendor[founditem].address2);
break;
}
case 6:
{
cout << "\t\tEnter new data for "
<< "Vendor city: ";
getline(cin,vendor[founditem].city);
break;
}
case 7:
{
cout << "\t\tEnter new data for "
<< "Vendor state: ";
getline(cin,vendor[founditem].state);
break;
}
case 8:
{
cout << "\t\tEnter new data for "
<< "Vendor zip code: ";
getline(cin,vendor[founditem].zip);
break;
}
case 9:
{
cout << "\t\tEnter new data for "
<< "Vendor phone: ";
getline(cin,vendor[founditem].phone);
break;
}
case 10:
{
cout << "\t\tEnter new data for "
<< "Vendor Fax: ";
getline(cin,vendor[founditem].fax);
break;
}
} // end of switch strucure
cout << endl << "\t\tMake additional changes to same record? (y/n) ";
cin.ignore(100,'\n');
cin >> recordUpdateContinue;
} // end record update while loop
cout << endl << "\t\tMake changes to a different record? (y/n) ";
cin >> vendorUpdateContinue;
if(vendorUpdateContinue == 'y' || vendorUpdateContinue == 'Y')
{
vendorUpdateContinue = 'Y';
}
} // end of OTHER WHILE loop
/////////////////// routine saves vendor data file
newVendorFile.open("VendorData.txt");
for(i=0; i<1000; i++)
{
if(vendor[i].VID.empty())
{
i = 1000;
break;
}
else
{
newVendorFile << vendor[i].VID << endl
<< vendor[i].coName << endl
<< vendor[i].contactName << endl
<< vendor[i].address1 << endl
<< vendor[i].address2 << endl
<< vendor[i].city << endl
<< vendor[i].state << endl
<< vendor[i].zip << endl
<< vendor[i].phone << endl
<< vendor[i].fax << endl;
}
} // end of new vendor data file write loop
newVendorFile.close();
return 'X';
}
/////////////////// routine displays vendor data //////////////////////
char displayVendor(companyType vendor[])
{
// declare variables
char vendorUpdateContinue = 'Y';
char vendorDisplayContinue = 'Y';
char recordUpdateContinue = 'Y';
char recordDisplayContinue = 'Y';
string spacer;
string searchVID;
string searchNameString;
string tempString;
int foundItem;
int choiceNum = 0;
int selectItem = 0;
int maxRecord;
// define input files
ifstream vendorFile;
ofstream newVendorFile;
vendorFile.open("vendorData.txt");
if (!vendorFile) //test for presence of productFile
{
cout << "\t\tUnable to open vendor DATA file." << endl;
cout << "\t\tPlease contact developer." << endl;
cout << "\t\tThis program will end." << endl;
return 'X';
}
system ("CLS");
cin.ignore(100,'\n');
for (i = 0;i < 1000;i++)
{
getline(vendorFile,vendor[i].VID);
getline(vendorFile,vendor[i].coName);
getline(vendorFile,vendor[i].contactName);
getline(vendorFile,vendor[i].address1);
getline(vendorFile,vendor[i].address2);
getline(vendorFile,vendor[i].city);
getline(vendorFile,vendor[i].state);
getline(vendorFile,vendor[i].zip);
getline(vendorFile,vendor[i].phone);
getline(vendorFile,vendor[i].fax);
}
//vendorFile.close();
cout << "\t\tRecent vendor entries:" << endl << endl;
for (i = 0;i < 1000;i++)
{
if(vendor[i].VID.empty())
{
maxRecord = i;
i = 1000;
}
else
{
cout << "\t\t" << vendor[i].VID << "\t\t"
<< vendor[i].coName << endl;
}
}
cout << endl << "\t\tMake a note of Vendor ID before proceding. " << endl << endl << "\t\t";
system("PAUSE");
while(vendorDisplayContinue=='Y')
{
system ("CLS");
makeLine(65);
cout << endl;
cout << "\t\tEnter Vendor ID of record to display or \"9999\" to quit: " << endl << endl;
makeLine(65);
cout << endl << endl << "\t\t";
getline(cin,searchVID);
if(searchVID=="9999")
{
return 'X';
}
for(i=0;i<1000;i++)
{
if(vendor[i].VID==searchVID)
{
foundItem = i;
i = 1000;
}
}
system ("CLS");
makeLine(65);
cout << endl << endl;
cout << "\t\tV.I.D. : " << vendor[founditem].VID << endl;
cout << "\t\tCo Name: " << vendor[founditem].coName << endl;
cout << "\t\tName : " << vendor[founditem].contactName << endl;
cout << "\t\tAdd1 : " << vendor[founditem].address1 << endl;
cout << "\t\tAdd2 : " << vendor[founditem].address2 << endl;
cout << "\t\tCity : " << vendor[founditem].city << endl;
cout << "\t\tState : " << vendor[founditem].state << endl;
cout << "\t\tzip : " << vendor[founditem].zip << endl;
cout << "\t\tphone : " << vendor[founditem].phone << endl;
cout << "\t\tfax : " << vendor[founditem].fax << endl;
cout << endl;
makeLine(65);
cout << endl << "\t\tDisplay a different record? (y/n) ";
cin >> vendorDisplayContinue;
} // end of Display Vendor WHILE loop
newVendorFile.close();
return 'X';
}
/////////////////////////////////Update Product Data///////////////////////
char updateProduct(productType drink[])
{
// declare variables
char productUpdateContinue = 'Y';
string spacer;
string searchSKU;
string tempString;
int foundIndex;
// define input files
ifstream productFile;
ofstream newProductFile;
productFile.open("productData.txt");
if (!productFile) //test for presence of productFile
{
cout << "\t\tUnable to open product DATA file." << endl;
cout << "\t\tPlease contact developer." << endl;
cout << "\t\tThis program will end." << endl;
return 'X';
}
system ("CLS");
for (i = 0;i < 1000;i++)
{
getline(productFile,drink[i].brand);
getline(productFile,drink[i].flavor);
getline(productFile,drink[i].descript);
getline(productFile,drink[i].size);
getline(productFile,drink[i].SKU);
productFile >> drink[i].deposit;
getline(productFile,spacer);
}
productFile.close();
while(productUpdateContinue=='Y')
{
makeLine(65);
cout << endl;
cout << "\t\tEnter SKU of product to update, " << endl;
cout << "\t\tor, to abandon ALL changes and return" << endl;
cout << "\t\tto main menu, enter 999." << endl;
cout << endl;
makeLine(65);
cout << endl << endl << endl << "\t\tSKU: " ;
cin >> searchSKU;
if(searchSKU=="999")
{
return 'X';
}
for (i = 0; i < 1000;i++)
{
if(drink[i].SKU == searchSKU)
{
foundIndex = i;
cout << endl << "\t\tRecord found for " << searchSKU << flush << endl;
i = 1000;
break;
}
if(drink[i].SKU.empty())
{
i = 1000;
cout << endl << "\t\tSKU not Found. Try Again." << endl;
continue;
}
}
char action = 'n';
makeLine(65);
cout << endl << endl;
cout << "\t\t1. Brand name : " << drink[foundindex].brand << endl;
cout << "\t\t2. Flavor : " << drink[foundindex].flavor<< endl;
cout << "\t\t3. Description : " << drink[foundindex].descript<< endl;
cout << "\t\t4. Size : " << drink[foundindex].size<< endl;
cout << "\t\t5. SKU : " << drink[foundindex].SKU<< endl;
cout << "\t\t6. Deposit AMT : " << drink[foundindex].deposit<< endl;
cout << endl << endl;
makeLine(65);
cout << endl << "\t\tEnter line number (1-6) to edit," << endl;
cout << "Q to quit, or K to delete entire product: ";
cin >> action ;
if(action=='q' || action=='Q')
{
productUpdateContinue='N';
continue;
}
if(action=='k' || action == 'K')
{
char confirm;
cout << "\t\tAre you SURE? Deletion will be permanent. (y/n) ";
cin >> confirm;
if (confirm=='Y' || confirm == 'y')
{
drink[foundindex].SKU = "DELETED";
}
}
if(action=='1')
{
cout << endl << "\t\tEnter new brand for SKU: " << drink[foundindex].SKU << flush << endl;
cin.ignore(256,'\n');
getline(cin,tempString);
drink[foundindex].brand = tempString;
}
if(action=='2')
{
cout << endl << "\t\tEnter new flavor for SKU:" << drink[foundindex].SKU << endl;
cin.ignore(256,'\n');
getline(cin,tempString);
drink[foundindex].flavor = tempString;
}
if(action=='3')
{
cout << endl << "\t\tEnter new description for SKU:" << drink[foundindex].SKU << endl;
cin.ignore(256,'\n');
getline(cin,tempString);
drink[foundindex].descript=tempString;
}
if(action=='4')
{
cout << endl << "\t\tEnter new size for SKU:" << drink[foundindex].SKU << endl;
cin.ignore(256,'\n');
getline(cin,tempString);
drink[foundindex].size=tempString;
}
if(action=='5')
{
cout << endl << "\t\tEnter new SKU to replace SKU:" << drink[foundindex].SKU << endl;
cin.ignore(256,'\n');
getline(cin,tempString);
drink[foundindex].SKU=tempString;
}
if(action=='6')
{
cout << endl << "\t\tEnter new deposit amount for SKU:" << drink[foundindex].SKU << endl;
cin >> drink[foundindex].deposit;
}
char closeSave = 'n';
cout << endl << "\t\tSave changes to file (y) or abandon changes (n)?";
cin >> closeSave;
if(closeSave == 'y' || closeSave == 'Y')
{
cout << "\t\tAre you sure? Changes will be final. (y/n)";
cin >> closeSave;
if(closeSave == 'y' || closeSave == 'Y')
{
newProductFile.open("productData.txt");
for(i=0;i<1000;i++)
{
if(drink[i].SKU.empty())
{
i = 1000;
newProductFile << endl << "\t\tSKU not Found. Try Again." << endl;
continue;
}
newProductFile << drink[i].brand << endl
<< drink[i].flavor << endl
<< drink[i].descript << endl
<< drink[i].size << endl
<< drink[i].SKU<< endl
<< drink[i].deposit << endl;
}
newProductFile.close();
}
}
}
// end of while loop
return 'X';
}
//////////////////////////// display product data ////////////////////////////
char displayProduct(productType drink[])
{
// declare variables
char productDisplayContinue = 'Y';
string spacer;
string searchSKU;
string tempString;
int foundIndex;
// define input files
ifstream productFile;
ofstream newProductFile;
productFile.open("productData.txt");
if (!productFile) //test for presence of productFile
{
cout << "\t\tUnable to open product DATA file." << endl;
cout << "\t\tPlease contact developer." << endl;
cout << "\t\tThis program will end." << endl;
return 'X';
}
system ("CLS");
for (i = 0;i < 1000;i++)
{
getline(productFile,drink[i].brand);
getline(productFile,drink[i].flavor);
getline(productFile,drink[i].descript);
getline(productFile,drink[i].size);
getline(productFile,drink[i].SKU);
productFile >> drink[i].deposit;
getline(productFile,spacer);
}
productFile.close();
while(productDisplayContinue=='Y')
{
makeLine(65);
cout << endl;
cout << "\t\tEnter SKU of product to display, " << endl;
cout << "\t\tor, to quit, enter 999." << endl;
cout << endl;
makeLine(65);
cout << endl << endl << endl << "\t\tSKU: " ;
cin >> searchSKU;
if(searchSKU=="999")
{
return 'X';
}
for (i = 0; i < 1000;i++)
{
if(drink[i].SKU.empty())
{
i = 1000;
cout << endl << "\t\tSKU not Found. Try Again." << endl;
continue;
}
if(drink[i].SKU == searchSKU)
{
foundIndex = i;
i = 1000;
}
}
char action = 'n';
makeLine(65);
cout << endl << endl;
cout << "\t\t1. Brand name : " << drink[foundindex].brand << endl;
cout << "\t\t2. Flavor : " << drink[foundindex].flavor<< endl;
cout << "\t\t3. Description : " << drink[foundindex].descript<< endl;
cout << "\t\t4. Size : " << drink[foundindex].size<< endl;
cout << "\t\t5. SKU : " << drink[foundindex].SKU<< endl << flush;
cout << "\t\t6. Deposit AMT : " << drink[foundindex].deposit<< endl;
cout << endl << endl;
makeLine(65);
cout << endl << "\t\tWould you like to display another product? (y/n) ";
cin >> productDisplayContinue;
if(productDisplayContinue=='n' || productDisplayContinue=='N')
{
productDisplayContinue = 'N';
}
}
return 'R';
}
[B]My programming skill's are not the best, so bear with me.
Here's my section so far
i list the functions
[/B]
void reportline;
int findsku;
string itm = 0;
int index;
int found;
found = false;
int i;
cout << "Please enter in sku or type 0 for all skus";
cin >> findsku;
now do I use fstream here or can I just use
for (findsku=0; findsku<nextopen;findsku++
{
if(strcmp(invenType[inventoryline[index].sku,itm)= =0);
{found=1;
break;
}
}
break;
if inventoryLine.quantity <= 5;
cout << findsku << quantity << endl;
}
InventoryLine [1000]
int maxRecord;
#include fstream;
open inventoryType.inventoryLine;
for (i=0; i <1000, i++)
{
getline(inventFile.inventoryLine[i].sku;
getline(inventFile.inventoryLine[i].quantity;
if inventoryLine[i].sku== " ";
{
maxRecord= i;
i = 1000;
}