Code:
#include <iostream>
using namespace std;
void inventory(int& total_coke, int& total_pepsi, int&
total_dry, int& total_hires);
void sales_type(char& s_type, int& brand, int& quantity, int&
total_coke, int& total_pepsi, int& total_dry, int& total_hires);
void display_inventory(int& total_coke, int& total_pepsi, int&
total_dry, int& total_hires);
//void clearline();
void instructions(char& s_type, int& brand, int& quantity,int&
total_coke, int& total_pepsi, int& total_dry, int& total_hires);
void purchase(int& brand,int& quantity, int& total_coke, int&
total_pepsi, int& total_dry, int& total_hires);
void sell(int& brand, int& quantity, int& total_coke, int&
total_pepsi, int& total_dry, int& total_hires);
void initialize();
int get_total_coke(int& total_coke, int& coke_add);
int get_total_pepsi(int& total_pepsi, int& pepsi_add);
int get_total_dry(int& total_dry, int& dry_add);
int get_total_hires(int& total_hires, int& hires_add);
int main(){
int total_coke=0,
total_pepsi=0,
total_dry=0,
total_hires=0,
brand,
quantity;
char s_type;
initialize();
inventory(total_coke, total_pepsi, total_dry, total_hires);
sales_type(s_type, brand, quantity, total_coke, total_pepsi,
total_dry, total_hires);
display_inventory(total_coke, total_pepsi, total_dry,
total_hires);
//clearline();
return 0;
}
void inventory(int& total_coke, int& total_pepsi, int&
total_dry, int& total_hires){
int coke_add,
pepsi_add,
dry_add,
hires_add;
cout<<" Please enter the inventory for each item "<<endl
<<" Enter the number of Coke on hand ";
cin>> coke_add;
while (cin.fail())
{ cin.clear();
cin.ignore(cin.fail());
cout<<"Invalid input...please re-enter"<<endl;
cout<<" Enter the number of Coke on hand ";;
cin>>coke_add;}
total_coke+=get_total_coke(total_coke, coke_add);
cout<<" Enter the number of Pepsi on hand ";
cin>> pepsi_add;
while (cin.fail())
{ cin.clear();
cin.ignore();
cout<<"Invalid input...please re-enter"<<endl;
cout<<" Enter the number of Pepsi on hand "<<endl;
cin>>pepsi_add;}
total_pepsi+=get_total_pepsi( total_pepsi, pepsi_add);
cout<<" Enter the number of Canada Dry on hand ";
cin>> dry_add;
while (cin.fail())
{ cin.clear();
cin.ignore();
cout<<"Invalid input...please re-enter"<<endl;
cout<<" Enter the number of Canada Dry on hand "<<endl;
cin>>dry_add;}
total_dry+=get_total_dry(total_dry, dry_add);
cout<<" Enter the number of Hires on hand ";
cin>> hires_add;
while (cin.fail())
{ cin.clear();
cin.ignore();
cout<<"Invalid input...please re-enter"<<endl;
cout<<" Enter the number of Hires on hand "<<endl;
cin>>hires_add;}
total_hires+=get_total_hires( total_hires, hires_add);
//clearline();
}
void sales_type(char& s_type, int& brand, int& quantity,int&
total_coke,int& total_pepsi,int& total_dry,int& total_hires){
cout<<" Enter the action and , if needed, company code and amount";
cin>>s_type>>brand>>quantity;
while (s_type!='Q'){
switch(s_type){
case 'P':
purchase(brand,quantity, total_coke, total_pepsi, total_dry,
total_hires);
break;
case 'S':
sell(brand,quantity, total_coke, total_pepsi, total_dry,
total_hires);
break;
case 'D':
display_inventory(total_coke, total_pepsi, total_dry,
total_hires);
break;
case 'I':
instructions(s_type, brand, quantity,total_coke, total_pepsi, total_dry, total_hires);
break;
default: cout<<"The action you requested is invalid...nothing has been done"<<endl;
}
}
}
void purchase(int& brand, int& quantity,int& total_coke, int&
total_pepsi, int& total_dry, int& total_hires){
while (brand>=1 && brand<=4){
switch(brand){
case'1':total_coke=total_coke+quantity;
cout<<"Inventory updated...";
break;
case'2':total_pepsi=total_pepsi+quantity;
cout<<"Inventory updated...";
break;
case'3':total_dry=total_dry+quantity;
cout<<"Inventory updated...";
break;
case'4':total_hires=total_hires+quantity;
cout<<"Inventory updated...";
break;
default: cout<<"bbThe action you requested is invalid...nothing has been done"<<endl;
}
cin.clear();
cin.ignore();
cout<<"The action you requested is invalid...nothing has been done"<<endl;
}
}
void sell(int& brand, int& quantity,int& total_coke, int&
total_pepsi, int& total_dry, int& total_hires){
while (brand>=1 && brand<=4){
switch(brand){
case'1':
while (!cin.fail() && quantity>0)
if(quantity>total_coke)
{ cout<< "Insufficient inventory to fill sell order,nothing changed"<<endl;}
else total_coke=total_coke-quantity;
cout<<"Inventory updated...";
break;
case'2':
while (!cin.fail() && quantity>0)
if(quantity>total_pepsi)
{ cout<< "Insufficient inventory to fill sell order,nothing changed"<<endl;}
else total_pepsi=total_pepsi-quantity;
cout<<"Inventory updated...";
break;
case'3':
while (!cin.fail() && quantity>0)
if(quantity>total_dry)
{ cout<< "Insufficient inventory to fill sell order,nothing changed"<<endl;}
else total_dry=total_dry-quantity;
cout<<"Inventory updated...";
break;
case'4':
while (!cin.fail() && quantity>0)
if(quantity>total_hires)
{ cout<< "Insufficient inventory to fill sell order,nothing changed"<<endl;}
else total_hires=total_hires-quantity;
cout<<"Inventory updated...";
break;
default: cout<<"ccThe action you requested is invalid...nothing has been done"<<endl;
}
}
}
void display_inventory(int& total_coke, int& total_pepsi, int&
total_dry, int& total_hires){
cout<<"Present inventory:"<<endl;
cout<<"Coke--"<<total_coke<<endl;
cout<<"Pepsi--"<<total_pepsi<<endl;
cout<<"Canada Dry--"<<total_dry<<endl;
cout<<"Hires--"<<total_hires<<endl;
}
void instructions(char& s_type, int& brand, int& quantity, int&
total_coke, int& total_pepsi, int& total_dry, int& total_hires){
cout<<" Your commands should follow one of these formats:"<<endl
<<" (P)urchase +<brand number> + <amount> "<<endl
<<" (S)ell +<brand number> + <amount> "<<endl
<<" (D)isplay present inventory for the four brands"<<endl
<<" Show (I)nstructions for user input "<<endl
<<" (Q)uit"<<endl
<<" Brand number codes:"<<endl
<<"1 -- Coke 2 -- Pepsi 3 -- Canada Dry 4 -- Hires"<<endl;
//clearline();
sales_type(s_type, brand, quantity, total_coke, total_pepsi,
total_dry, total_hires);
}
void initialize(){
cout<<"You will first be prompted for the inventories for each of the four brands."<<endl;
cout<<"You should then enter the initial number of cases available for each brand."<<endl;
cout<<" Your commands should follow one of these formats:"<<endl
<<" (P)urchase +<brand number> + <amount> "<<endl
<<" (S)ell +<brand number> + <amount> "<<endl
<<" (D)isplay present inventory for the four brands"<<endl
<<" Show (I)nstructions for user input "<<endl
<<" (Q)uit"<<endl
<<" Brand number codes:"<<endl
<<"1 -- Coke 2 -- Pepsi 3 -- Canada Dry 4 -- Hires"<<endl;
}
int get_total_coke(int& total_coke, int& coke_add){
while (coke_add<0){
cout<<" The action you have requested is invalid....nothing changed"<<endl;
cout<<" Please enter the amount of Coke on hand "<<endl;
cin.clear();
cin>>coke_add;}
return coke_add;
}
int get_total_pepsi(int& total_pepsi, int& pepsi_add){
while (pepsi_add<0){
cout<<" The action you have requested is invalid....nothing changed"<<endl;
cout<<" Please enter the amount of Pepsi on hand "<<endl;
cin.clear();
cin>>pepsi_add;}
return pepsi_add;
}
int get_total_dry(int& total_dry, int& dry_add){
while (dry_add<0){
cout<<" The action you have requested is invalid....nothing changed"<<endl;
cout<<" Please enter the amount of Canada Dry on hand "<<endl;
cin.clear();
cin>>dry_add;}
return dry_add;
}
int get_total_hires(int& total_hires, int& hires_add){
while (hires_add<0){
cout<<" The action you have requested is invalid....nothing changed"<<endl;
cout<<" Please enter the amount of Hires on hand "<<endl;
cin.clear();
cin>>hires_add;}
return hires_add;
}