Challenge

Project 1

Program :-

#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<

cin>>s;

outdata << "Selected option" << endl>

outdata << s>

    // operations for selected choice from menu

switch(s)

{

case 1:

cout<<"nPlease enter the name of commoditiesn";

cout<

outdata << "nName of commodities" << endl>

for (int i = 0; i < M>

    {

        for (int j = 0; j < 1>

{

           cin>> *(A + i*N + j);    // assign values to the allocated memory for commodities only

           outdata << *(A + i*N + j) << endl>

}

    }

    outdata<

cout<

goto start;

    break;

case 2:

cout<<"nPlease enter the Vendor 1 quotations (Strictly follow the sequence as per commodities entered): n";

cout<

outdata << "nVendor 1 quotations (Sequence: As per commodities entered)" << endl>

for (int i = 0; i < M>

    {

        for (int j = 1; j < 2>

{

           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<

outdata << "nVendor 2 quotations (Sequence: As per commodities entered)" << endl>

for (int i = 0; i < M>

    {

        for (int j = 2; j < 3>

{

           cin>> *(A + i*N + j);        // assign values to the allocated memory for vendor 2 quotations

           outdata << *(A + i*N + j) << endl>

}

    }

outdata<

cout<

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<

outdata << "nNo. of laptops 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<

for(int i=0; i<3>

    {cin>>Laptop[i]; outdata << Laptop>

    cout<<"nEnter the no. of Mouse 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):n";

        cout<

outdata << "nNo. of Mouse 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<

for(int i=0; i<3>

    {cin>>Mouse[i]; outdata << Mouse>

        cout<<"nEnter the no. of Headset 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):n";

    cout<

outdata << "nNo. of Headset 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<

for(int i=0; i<3>

    {cin>>Headset[i]; outdata << Headset>

    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<

outdata << "nNo. of Laptop_Bag 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<

for(int i=0; i<3>

    {cin>>Laptop_Bag[i]; outdata << Laptop>

        cout<<"nEnter the no. of Adapter 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):n";

    cout<

outdata << "nNo. of Adapter 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<

for(int i=0; i<3>

    {cin>>Adapter[i]; outdata << Adapter>

    //conveting strings to integer. As we have created array of strings while taking commodity and vendor inputs

    for (int i = 0; i < M>

        {

        for (int j = 1; j < 3>

{num[i][j] = stoi(*(A + i*N + j));}

        }

for(int k=0; k<3>

{

//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

{

cout<<" Vendor 1 "<

}

else

{

cout<<" Vendor 2 "<

}

}

break;

case 0:

exit(0);

default:

    cout<<"Invalid selection";

    goto start;

}

    return 0;

}

Output :-

Select from below menu
1. Select to Enter Commodities to be purchased
2. Select to Enter Vendor quotations
3. Select to find best vendor (Only select when you have enterd commodities and vendors data)
0. Exit

1

Please enter the name of commodities

Laptop
Mouse
Headset
Laptop_Bag
Adapter

Select from below menu
1. Select to Enter Commodities to be purchased
2. Select to Enter Vendor quotations
3. Select to find best vendor (Only select when you have enterd commodities and vendors data)
0. Exit

2

Please enter the Vendor 1 quotations (Strictly follow the sequence as per commodities entered):

45000
1500
2500
1200
1600

Please enter the Vendor 2 quotations (Strictly follow the sequence as per commodities entered):

43000
1200
3000
1000
1500

Select from below menu
1. Select to Enter Commodities to be purchased
2. Select to Enter Vendor quotations
3. Select to find best vendor (Only select when you have enterd commodities and vendors data)
0. Exit

3

Enter the no. of laptops 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):

5
10
3

Enter the no. of Mouse 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):

15
10
5

Enter the no. of Headset 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):

10
25
6

Enter the no. of Laptop_Bag 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):

5
10
3

Enter the no. of Adapter 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):

20
15
10

The best vendor for Ramu is :  Vendor 2

The best vendor for Raju is :  Vendor 2

The best vendor for Shyam is :  Vendor 2

--------------------------------
Process exited after 222.7 seconds with return value 0
Press any key to continue . . .
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.