Challenge

Project 1

#include
#include
#include
#include

// `M × N` matrix for storing data
#define M 5
#define N 3
using namespace std;

int main()
{

string* A = new string[M * N]; // dynamically allocate memory of size `M × N`

// declarations
int Laptop[3], Mouse[3], Headset[3], Laptop_Bag[3], Adapter[3];
int s;
int vendor1_total, vendor2_total;
int num[2][2];
ofstream outdata;
outdata.open("Project_1_sample.txt");

// Menu
start:
cout<<"Select from below menun";
cout<<"1. Select to Enter Commodities to be purchasedn";
cout<<"2. Select to Enter Vendor quotationsn";
cout<<"3. Select to find best vendor (Only select when you have enterd commodities and vendors data)n";
cout<<"0. Exitn";
cout<<endl;
cin>>s;
outdata << "Selected option" << endl;
outdata << s << endl;

// operations for selected choice from menu

switch(s)
{

case 1:
cout<<"nPlease enter the name of commoditiesn";
cout<<endl;
outdata << "nName of commodities" << endl;
for (int i = 0; i < M; i++)
{
for (int j = 0; j < 1; j++)
{
cin>> *(A + i*N + j); // assign values to the allocated memory for commodities only
outdata << *(A + i*N + j) << endl;
}
}
outdata<<endl;
cout<<endl;
goto start;
break;

case 2:
cout<<"nPlease enter the Vendor 1 quotations (Strictly follow the sequence as per commodities entered): n";
cout<<endl;
outdata << "nVendor 1 quotations (Sequence: As per commodities entered)" << endl;
for (int i = 0; i < M; i++)
{
for (int j = 1; j < 2; j++)
{
cin>> *(A + i*N + j); // assign values to the allocated memory for vendor 1 quotations
outdata << *(A + i*N + j) << endl;
}
}
cout<<"nPlease enter the Vendor 2 quotations (Strictly follow the sequence as per commodities entered): n";
cout<<endl;
outdata << "nVendor 2 quotations (Sequence: As per commodities entered)" << endl;
for (int i = 0; i < M; i++)
{
for (int j = 2; j < 3; j++)
{
cin>> *(A + i*N + j); // assign values to the allocated memory for vendor 2 quotations
outdata << *(A + i*N + j) << endl;
}
}
outdata<<endl;
cout<<endl;
goto start;
break;

case 3:
cout<<"nEnter the no. of laptops 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):n";
cout<<endl;
outdata << "nNo. of laptops 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<<endl;
for(int i=0; i<3; i++)
{cin>>Laptop[i]; outdata << Laptop[i] << endl;} // Taking input and at the same time writing input data into file.

cout<<"nEnter the no. of Mouse 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):n";
cout<<endl;
outdata << "nNo. of Mouse 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<<endl;
for(int i=0; i<3; i++)
{cin>>Mouse[i]; outdata << Mouse[i] << endl;}

cout<<"nEnter the no. of Headset 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):n";
cout<<endl;
outdata << "nNo. of Headset 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<<endl;
for(int i=0; i<3; i++)
{cin>>Headset[i]; outdata << Headset[i] << endl;}

cout<<"nEnter the no. of Laptop_Bag 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):n";
cout<<endl;
outdata << "nNo. of Laptop_Bag 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<<endl;
for(int i=0; i<3; i++)
{cin>>Laptop_Bag[i]; outdata << Laptop_Bag[i] << endl;}


cout<<"nEnter the no. of Adapter 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):n";
cout<<endl;
outdata << "nNo. of Adapter 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<<endl;
for(int i=0; i<3; i++)
{cin>>Adapter[i]; outdata << Adapter[i] << endl;}



//conveting strings to integer. As we have created array of strings while taking commodity and vendor inputs
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++)
{
//0 indice correspond to ramu, 1 to Raju and 2 to Shyam.
if (k==0)
{
cout << "nThe best vendor for Ramu is : ";
}
else if (k==1)
{
cout << "nThe best vendor for Raju is : ";
}
else
{
cout << "nThe 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] + Adapter[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] + Adapter[k]*num[4][2];

if(vendor1_total<vendor2_total)
{
cout<<" Vendor 1 "<<endl;
}
else
{
cout<<" Vendor 2 "<<endl;
}

}

break;

case 0:
exit(0);

default:
cout<<"Invalid selection";
goto start;

}

return 0;
}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.