/* I'm in computer programming 1b. so the libraries and styles maybe noobish, but i am having trouble with expanding the array to keep the inventory expanding...so it prints out all the albums when print is called and keeps them all in memory...i need to know placement of the arrays */
Code:
#include <iostream.h>
#include <lvp\string.h>
#include <lvp\vector.h>
struct rec{
long sku;
String artist;
String album;
long quantity;
double price;
};//end struct
struct inv{
inv();//constructer
vector<rec>album;
};
inv::inv()
:album(0)
{}
/////////////////////////////////////////////////////////////////
void read(rec&rec);//reads in records at start
void printer(rec&rec);//prints records
void add(rec&rec);//adds records to inventory
void del(rec&rec);//deleted records in inventory
void sell(rec&rec);//sells available inventory
int main(){
rec rec;
inv inv;
char answer;//answer for adding a new record at start
int menu_answer;//answer for menu
cout<<"\t\t\tThis Register Open"<<endl<<endl;
do{
cout<<"Would you like to add a new record to inventory(y/n)? ";
cin>>answer;
if((answer=='y'||answer=='Y')){
read(rec);
}//end if
else{
break;
}//end else
}while((answer!='N')||(answer!='n'));
system("cls");
do{
cout<<"Dj Mega Emporium"<<endl;
cout<<"\tMain Menu"<<endl<<endl;
cout<<"1)\tSell a record."<<endl;
cout<<"2)\tAdd a record."<<endl;
cout<<"3)\tDelete a record."<<endl;
cout<<"4)\tPrint record inventory report."<<endl;
cout<<"5)\tExit"<<endl<<endl;
cin>>menu_answer;
system("cls");
if(menu_answer==4){
printer(rec);
cout<<endl;
}//end if
else if(menu_answer==2){
add(rec);
cout<<endl;
}//end else if
else if(menu_answer==3){
del(rec);
cout<<endl;
}//end else if
else if(menu_answer==1){
sell(rec);
cout<<endl;
}//end else if
else if(menu_answer==5){
cout<<"k bye"<<endl;return 0;
}//end else if
else{
cout<<"Please choose a correct option"<<endl<<endl;
}//end else
}while(menu_answer!=5);//end do while
system("cls");
cout<<"k bye dont come back"<<endl;
return 0;
}//end main
void read(rec&rec){//reads in record data
cout<<"Enter the Sku Number: ";
cin>>rec.sku;
cout<<"Enter the Artist: ";
cin>>rec.artist;
cin.ignore(100, '\n');
cout<<"Enter the Album: ";
getline(cin,rec.album);
cout<<"Enter the Quantity: ";
cin>>rec.quantity;
cout<<"Enter the price: ";
cin>>rec.price;
cout<<endl<<endl;
cout<<"Record Added to Inventory"<<endl<<endl;
return;
}//ends function
void printer(rec&rec){
cout<<"Sku #: "<<rec.sku<<endl;
cout<<"Artist: "<<rec.artist<<endl;
cout<<"Album: "<<rec.album<<endl;
cout<<"Quantity: "<<rec.quantity<<endl;
cout<<"Price: "<<rec.price<<endl;
return;
}//ends function
void add(rec&rec){
int adding;
cout<<"Please enter the sku number of the record you are adding ";
cin>>rec.sku;
cout<<endl;
cout<<"We already have "<<rec.quantity<<" copies of "<<rec.artist<<"-"<<rec.album<<" in our inventory"<<endl;
cout<<"How many would you like to add? ";
cin>>adding;
rec.quantity=rec.quantity+adding;
}//ends function
void del(rec&rec){
cout<<"Enter the sku number of the record to delete :";
cin>>rec.sku;
cout<<rec.artist<<"-"<<rec.album<<" has been deleted";
} //ends function
void sell (rec&rec){
int purchasing;
do{
cout<<"Please enter the sku number of the record you are buying: "<<endl;
cin>>rec.sku;
cout<<endl;
cout<<"Please enter how many books you wish to purchase: "<<endl;
cin>>purchasing;
if(purchasing>rec.quantity){
cout<<"Please choose a smaller amount"<<endl<<endl;
}//end if
}while(purchasing>rec.quantity);//end do while
rec.quantity=rec.quantity-purchasing;
}//ends function