Assignment#1
Assignment#1
};
struct history
{
string prod;
int price;
};
void insertion(Amazon *arr,int sizeA)
{
for(int i = 0 ; i<sizeA ;++i)
{
cout<<"enter product name: "<<endl;
cin>>arr[i].productName;
cout<<"enter product price: "<<endl;
cin>>arr[i].productPrice;
cout<<"enter product category: "<<endl;
cin>>arr[i].category;
cout<<"enter product description: "<<endl;
cin>>arr[i].decription;
}
}
void Display(Amazon *arr ,int sizeA)
{
for(int i=0;i<sizeA;++i)
{
if (arr[i].productPrice==0)
break;
else
{
cout<<arr[i].productName<<" ";
cout<<arr[i].productPrice<<" ";
cout<<arr[i].category<<" ";
cout<<arr[i].decription<<" ";
}
cout<<endl;
}
}
void AddProduct(Amazon *arr,int sizeA,int AddProducts)
{
for (int i=sizeA ; i<sizeA+AddProducts;++i)
{
cout<<"enter product name: "<<endl;
cin>>arr[i].productName;
cout<<"enter product price: "<<endl;
cin>>arr[i].productPrice;
cout<<"enter product category: "<<endl;
cin>>arr[i].category;
cout<<"enter product description: "<<endl;
cin>>arr[i].decription;
}
}
void DeleteProduct(Amazon *arr,int sizeA,string ele)
{
bool checker;
for(int i=0 ; i<sizeA ; ++i)
{
if(arr[i].productName==ele)
{
checker=true;
arr[i].productName='0';
arr[i].productPrice=0;
arr[i].category='0';
arr[i].decription='0';
}
else
checker=false;
}
if(checker==false)
cout<<"not found"<<endl;
}
void UpdateProduct(Amazon *arr,int sizeA,string ele)
{
char choice;
bool checker;
for(int i=0 ; i<sizeA ; ++i)
{
if(arr[i].productName==ele)
{ cout<<"press 1 to update name"<<endl<<"press 2
to update price"<<endl<<"press 3 to update
category"<<endl<<"press 4 to update decription"<<endl;
cin>>choice;
checker=true;
switch (choice)
{
case '1':
{
cout<<"enter name: "<<endl;
cin>>arr[i].productName;
break;
}
case '2':
{
cout<<"enter price: "<<endl;
cin>>arr[i].productPrice;
break;
}
case '3':
{
cout<<"enter category: ";
cin>>arr[i].category;
break;
}
case '4':
{
cout<<"enter decription: ";
cin>>arr[i].decription;
break;
}
}
}
else
{
checker=false;
continue;
}
}
if (checker==false)
{
cout<<"not found "<<endl;
}
}
int purchase(history *arr,Amazon *arrs,int x,int A,int &b)
{
int a=0;
string arre[x];
bool checker;
int sum=0;
while (a<x)
{
for(int i =0 ; i<A ;++i)
{
if(arr[a].prod==arrs[i].productName)
{
checker=true;
arr[a].price=arrs[i].productPrice;
sum=sum+(arr[a].price);
break;
}
else
checker=false;
}
if(checker==true)
{
cout<< arr[a].prod<<" purschased "<<endl;
}
else
{
cout<<arr[a].prod<<" not purschased "<<endl;
}
a++;
}
b=b-sum;
return sum;
}
int AdminProduct;
main()
{
history customer1[10000];
string h,g,m;
char choice,choice2,choice3,choice4;
int x,j,balance=1000000;
Amazon arr[10000];
cout<<"enter y/n to start the system: ";
cin>>choice;
while(choice=='y')
{
cout<<"create initial inventory add produts: "<<endl;
cin>>AdminProduct;
insertion(arr,AdminProduct);
Display(arr,AdminProduct);
cout<<"press x to get admin access"<<endl<<"press u
to get user access: "<<endl;
cin>>choice2;
while(choice2=='x')
{
cout<<"press 1 to issue balance to the
user"<<endl<<"press 2 ask a user to add products to the
inventory"<<endl<<"press 3 to delete a product
record"<<endl<<"press 4 to update the product
record"<<endl;
cin>>choice3;
if (choice3=='1')
{
cout<<"your balance is: ";
cout<<endl<<balance<<endl;
}
if(choice3=='2')
{
cout<<"enter number Of products u wan to add:
"<<endl;
cin>>x;
AddProduct(arr,AdminProduct,x);
AdminProduct=AdminProduct+x;
Display(arr,AdminProduct);
}
if (choice3=='3')
{
cout<<"enter element to delete: ";
cin>>h;
DeleteProduct(arr,AdminProduct,h);
Display(arr,AdminProduct);
}
if (choice3=='4')
{
cout<<"enter product Name to update: "<<endl;
cin>>g;
UpdateProduct(arr,AdminProduct,g);
Display(arr,AdminProduct);
}
cout<<"press x to continue/press u to move towards
user"<<endl;
cin>>choice2;
}
while (choice2=='u')
{
cout<<"press 1 to buy products: "<<endl<<"press 2 to
see balance"<<endl<<"press 3 to see history(need to
perform 1);
) first"<<endl;
cin>>choice4;
if (choice4=='1')
{
cout<<"enter number of products u want to buy:
"<<endl;
cin>>j;
for (int y=0 ;y<j; ++y)
{
cout<<"enter product u want to buy: "<<endl;
cin>>customer1[y].prod;
}
cout<<endl;
cout<<purchase(customer1,arr,j,AdminProduct,balance)
<<endl;
}
if(choice4=='2')
{
cout<<"following is yOur remainig balance: "<<endl;
cout<<balance<<endl;
}
if(choice4=='3')
{
cout<<"following are the products obtained:
"<<endl;
for(int s=0 ;s<j;++s)
{
if(customer1[s].price!=0)
{
cout<<customer1[s].prod<<endl;
}
}
cout<<"enter to b two times to break (as adding can
be done only once)"<<endl;
cin>>choice2;
cin>>choice;
}
}
}