Challenge

Project 1

Project 1:

#include<iostream>
#include<string>
#include<fstream>

//M x N matric is taken -M=>no of Commodities,N=>IT person
#define M 5
#define N 3
using namespace std;


int main()
{
    string* A= new string[ M*N ];//dynamically allocating the memory of size 5X3
    int laptop[3],mouse[3],headset[3],laptop_bag[3],adapter[3];
    int x;
    int vendor1_total,vendor2_total;
    int num[2][2];
    ofstream outdata;
    outdata.open("Project1.txt");
    
    start:
    cout<<"Select option from below"<<endl;
    cout<<"1.Want to enter the Commodities to be purchased"<<endl;
    cout<<"2.Want to Enter Vendor quotations"<<endl;
    cout<<"3.Want to find the best vendor"<<endl;
    cout<<"0.Exit"<<endl;
    cin>>x;
    outdata<<"Selected option"<<endl;
    outdata<< x <<endl;
    //switch used to select the option
    
    switch(x)
    {
        case 1:
        cout<<"Enter the name of the commoditiesn"<<endl;
        outdata<<"Name of the commodities"<<endl;
        for(int i=0;i<M;i++)
        {
            cin>>*(A+i*N);//assign value to allocated memory.(a+i*N+j)=>j=0
            outdata<<*(A+i*N)<<endl;
        }
        outdata<<endl;
        cout<<endl;
        goto start;
        break;
        
        case 2:
        cout<<"Enter vendor 1 quotations"<<endl;
        outdata<<"Vendor 1 quotations"<<endl;
        for(int i=0;i<M;i++)
        {
            cin>>*(A+i*N+1);//assign value to allocated memory.(a+i*N+j)=>j=0
            outdata<<*(A+i*N+1)<<endl;
        }
        cout<<"Enter vendor 2 quotations"<<endl;
        outdata<<"Vendor 2 quotations"<<endl;
        for(int i=0;i<M;i++)
        {
            cin>>*(A+i*N+2);//assign value to allocated memory.(a+i*N+j)=>j=0
            outdata<<*(A+i*N+2)<<endl;
        }
        outdata<<endl;
        cout<<endl;
        goto start;
        break;
        
        case 3:
        cout<<"Enter the no. of laptops wanted to be bought by Ramu, Raju and Shyam respectively"<<endl;
        outdata<<"the no. of laptops wanted to be bought by Ramu, Raju and Shyam respectively"<<endl;
        for(int i=0;i<3;i++)
        {
            cin>>laptop[i];
            outdata<<laptop[i]<<endl;
        }
        cout<<"Enter the no. of mouse wanted to be bought by Ramu, Raju and Shyam respectively"<<endl;
        outdata<<"the no. of mouse wanted to be bought by Ramu, Raju and Shyam respectively"<<endl;
        for(int i=0;i<3;i++)
        {
            cin>>mouse[i];
            outdata<<mouse[i]<<endl;
        }
        cout<<"Enter the no. of headset wanted to be bought by Ramu, Raju and Shyam respectively"<<endl;
        outdata<<"the no. of headset wanted to be bought by Ramu, Raju and Shyam respectively"<<endl;
        for(int i=0;i<3;i++)
        {
            cin>>headset[i];
            outdata<<headset[i]<<endl;
        }
        cout<<"Enter the no. of laptop_bag wanted to be bought by Ramu, Raju and Shyam respectively"<<endl;
        outdata<<"the no. of laptop_bag wanted to be bought by Ramu, Raju and Shyam respectively"<<endl;
        for(int i=0;i<3;i++)
        {
            cin>>laptop_bag[i];
            outdata<<laptop_bag[i]<<endl;
        }
        cout<<"Enter the no. of adapter wanted to be bought by Ramu, Raju and Shyam respectively"<<endl;
        outdata<<"the no. of adapter wanted to be bought by Ramu, Raju and Shyam respectively"<<endl;
        for(int i=0;i<3;i++)
        {
            cin>>adapter[i];
            outdata<<adapter[i]<<endl;
        }
    
    //string is converted into integer,since inputs name were taken
    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 << "\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;
}

 

TXT file created:

Output:(console)

Select option from below
1.Want to enter the Commodities to be purchased
2.Want to Enter Vendor quotations
3.Want to find the best vendor
0.Exit
1
Enter the name of the commoditiesn
laptop
mouse
headset
laptopbag
adapter

Select option from below
1.Want to enter the Commodities to be purchased
2.Want to Enter Vendor quotations
3.Want to find the best vendor
0.Exit
2
Enter vendor 1 quotations
45000
1500
2500
1200
1600
Enter vendor 2 quotations
43000
1200
3000
1000
1500

Select option from below
1.Want to enter the Commodities to be purchased
2.Want to Enter Vendor quotations
3.Want to find the best vendor
0.Exit
3
Enter the no. of laptops wanted to be bought by Ramu, Raju and Shyam respectively
5
10
3
Enter the no. of mouse wanted to be bought by Ramu, Raju and Shyam respectively
15
10
5
Enter the no. of headset wanted to be bought by Ramu, Raju and Shyam respectively
10
25
6
Enter the no. of laptop_bag wanted to be bought by Ramu, Raju and Shyam respectively
5
10
3
Enter the no. of adapter wanted to be bought by Ramu, Raju and Shyam respectively
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

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.