Project 1
#include <iostream> // headerfile
#include<fstream>
#include<cstring>
#define M 5
#define N 3
using namespace std;
int main()
{
string* A=new string[M*N]; //dynamically allocated memory of size M*new
int Laptop[3],Mouse[3],Headset[3],Laptop_bag[3],Adaptor[3]; //arrey declairation for comodities
int s,k;
int vendor1_total,vendor2_total; //arrey declairation for vendor
int num[2][2];
ofstream outdata;
outdata.open("project_1_sample.txt");
start:
cout<<"select from below menu: \n"<<endl;
cout<<"1.enter to select the comdities to be purchesed: \n"<<endl;
cout<<"2.enter to select the cvendor quotation: \n"<<endl;
cout<<"3.enter to find the best vendor(only select when you have enter the comdities and vendor data: \n"<<endl;
cout<<"0.Exit: \n"<<endl;
cin>>s;
outdata<<"selected option"<<endl;
outdata<<s<<endl;
switch(s)
{
case 1:
cout<<"please enter the name of comodities :"<<endl;
cout<<endl;
outdata<<"\n name of the comodities"<<endl;
for(int i=0; i<M; i++)
{
for (int j=0; j<1; j++)
{
cin>>*(A + i*N + j);
outdata<<*(A + i*N + j)<<endl;
}
}
outdata<<endl;
cout<<endl;
goto start;
break;
case 2:
cout<<"enter the vendor 1 quotation:"<<endl;
cout<<endl;
outdata<<"\n vendor 1 quotation as per commodities enter"<<endl;
for(int i=0; i<M;i++)
{
for (int j=1;j<2;j++)
{
cin>>*(A + i*N + j);
outdata<<*(A + i*N + j)<<endl;
}
}
cout<<"enter the vendor 2 quotation:"<<endl;
cout<<endl;
outdata<<"\n vendor 2 quotation as per commodities enter"<<endl;
for(int i=0; i<M;i++)
{
for (int j=2;j<3;j++)
{
cin>>*(A + i*N + j);
outdata<<*(A + i*N + j)<<endl;
}
}
goto start;
break;
case 3:
cout<<"enter the number of laptop 'ramu' 'raju' 'shyam' wants to buy\n"<<endl;
cout<<endl;
outdata<<"number of laptop 'ramu' 'raju' and shyam bought"<<endl;
for(int i=0;i<3;i++)
{
cin>>Laptop[i]; outdata<<Laptop[i]<<endl;
}
cout<<"\n Enter the number of mouse 'ramu','raju',and 'shyam' want to bought";
cout<<endl;
cout<<"\n number of mouse 'ramu','raju',and 'shyam' want to bought";
cout<<endl;
for(int i=0;i<3;i++)
{cin>>Mouse[i];outdata<<Mouse[i]<<endl;}
cout<<"\n Enter the number of headst 'ramu','raju',and 'shyam' want to bought";
cout<<endl;
cout<<"\n number of headset 'ramu','raju',and 'shyam' want to bought";
cout<<endl;
for(int i=0;i<3;i++)
{cin>>Headset[i];outdata<<Headset[i]<<endl;}
cout<<"\n Enter the number of Laptop_bag 'ramu','raju',and 'shyam' want to bought";
cout<<endl;
cout<<"\n number of Laptop_bag 'ramu','raju',and 'shyam' want to bought";
cout<<endl;
for(int i=0;i<3;i++)
{cin>>Laptop_bag[i];outdata<<Mouse[i]<<endl;}
cout<<"\n Enter the number of Adaptor 'ramu','raju',and 'shyam' want to bought";
cout<<endl;
cout<<"\n number of Adaptor 'ramu','raju',and 'shyam' want to bought";
cout<<endl;
for(int i=0;i<3;i++)
{cin>>Adaptor[i];outdata<<Mouse[i]<<endl;}
for(int i=0;i<M;i++)
{
for(int j=1;j<3;j++)
{
num[i][j]=stoi(*(A+i*N+j));
}
}
for(int k=0; k<3; k++)
{
if(k==0)
{
cout<<"the best vendor for ramu is:-";
}
else if(k==1)
{
cout<<"the best vendor for raju is:-";
}
else
{
cout<<"the best vendor for shyam is:-";
}
}
vendor1_total=Laptop[k]*num[0][1]+Mouse[k]*num[1][1]+Headset[k]*num[2][1]+Laptop_bag[k]*num[3][1]+Adaptor[k]*num[4][1];
vendor2_total=Laptop[k]*num[0][2]+Mouse[k]*num[1][2]+Headset[k]*num[2][2]+Laptop_bag[k]*num[3][2]+Adaptor[k]*num[4][2];;
if(vendor1_total<vendor2_total)
{
cout<<"vendor1"<<endl;
}
else
{
cout<<"vendor2"<<endl;
}
break;
case 0:
exit(0);
default:
cout<<"Invalid selection:\n"<<endl;
goto start;
}
return 0;
}
output:-