Challenge

Project 1

PROJECT -1:-

#include <iostream>//header file

#include <fstream>//uses the H file extension ans is considered a Developer file.

#include <string> //string header file

// `M × N` matrix for storing data

#define M 5

#define N 3

using namespace std; //declare namespace

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]; //Array declaration

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 menu: \n";

cout<<"1. Select to Enter Commodities to be purchasedn \n";

cout<<"2. Select to Enter Vendor quotationsn \n";

cout<<"3. Select to find best vendor (Only select when you have enterd commodities and vendors data)\n";

cout<<"0. Exit\n";

cout<<endl;

cin>>s;

outdata << "Selected option" << endl;

outdata << s << endl;

// operations for selected choice from menu

switch(s) //switch block for switching case to another case as per condition.

{

case 1:

cout<<"Please enter the name of commodities:";

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; //jump statement to go start

break; //the loop iterations stop there and control returns from the loop immediately to the first statement after the loop.

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; //jump statement to go start

break; //the loop iterations stop there and control returns from the loop immediately to the first statement after the loop.

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;} // Taking input and at the same time writing input data into file.

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;} // Taking input and at the same time writing input data into file.

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;} // Taking input and at the same time writing input data into file.

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;} // Taking input and at the same time writing input data into file.

//converting 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 indicate 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; //if less than value of vendor1_total as compare to vendor2_total,its printing

}

else

{

cout<<" Vendor 2 "<<endl; // else its printing because greater value of vendor1_total as compare to vendor2_total

}

}

break; //the loop iterations stop there and control returns from the loop immediately to the first statement after the loop.

case 0:

exit(0); //if we select option 0 its access exit action.

default:

cout<<"Invalid selection!\n\n"; //default other option its showing invalid selection

goto start; //jump statement to go 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.