Challenge

Project 1

C++ PROJECT 1 (Esakki Vigneshwaran - Live Batch)

Pdf attached : C++ Project1.pdf

** Please check the pdf for output and compilation

The code has been provided below for your reference:

#include <iostream> // header file

#include<fstream> //library for file handling operation

#include<cstring> //library for string operation

#define M 5 //defining Macro

#define N 3 //defining Macro

using namespace std;

int main() //main function

{

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]; //array declaration for commodities

int s,k;

int vendor1_total,vendor2_total; //array declaration for vendor

int num[2][2];

ofstream outdata;

outdata.open("commodities.txt"); //opening file "commodities.txt"

//outputs

cout<<" Select from below menu: "<<endl;

cout<<"1.Press 1 to select the Commodities to be purchased: "<<endl;

cout<<"2.Press 2 to select the Vendor quotation: "<<endl;

cout<<"3.Press 3 to find the best vendor(choose only when you have entered the commodities and vendor data) "<<endl;

cout<<"0.Exit: press 0 "<<endl;

start:

cout<<endl<<" Option : ";

cin>>s;

outdata<<"Selected option : ";

outdata<<s<<endl;

switch(s) //switch statement

{

case 1:

cout<<endl<<" Enter the name of Commodities :";

outdata<<" Name of the Commodities"<<endl;

for(int i=0; i<M; i++) //conditional statement

{

for (int j=0; j<1; j++) //conditional statement

{

cin>>*(A + i*N + j);

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

}

}

outdata<<endl;

cout<<endl;

goto start; //unconditional jump to the start

break;

case 2:

cout<<endl<<" Enter Vendor 1 quotation:"<<endl;

outdata<<endl<<" Vendor 1 quotation as per commodities :"<<endl;

for(int i=0; i<M;i++) //conditional statement

{

for (int j=1;j<2;j++) //conditional statement

{

cin>>*(A + i*N + j);

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

}

}

cout<<endl<<" Enter Vendor 2 quotation:"<<endl;

outdata<<endl<<" Vendor 2 quotation as per commodities :"<<endl;

for(int i=0; i<M;i++) //conditional statement

{

for (int j=2;j<3;j++) //conditional statement

{

cin>>*(A + i*N + j);

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

}

}

goto start;

break; //unconditional jump to the start

case 3:

cout<<endl<<" Enter the number of laptops 'Ramu', 'Raju' & 'Shyam' want to purchase : ";

cout<<endl;

outdata<<" Number of Laptop 'Ramu', 'Raju' & 'Shyam' want to purchase"<<endl;

for(int i=0;i<3;i++) //conditional statement

{

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

}

cout<<endl<<" Enter the number of Mouse 'Ramu', 'Raju' & 'Shyam' want to purchase : ";

cout<<endl;

outdata<<" Number of Mouse 'Ramu', 'Raju' & 'Shyam' want to purchase"<<endl;

for(int i=0;i<3;i++)

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

cout<<endl<<" Enter the number of headsets 'Ramu', 'Raju' & 'Shyam' want to purchase : ";

cout<<endl;

outdata<<endl<<" Number of headsets 'Ramu', 'Raju' & 'Shyam' want to purchase"<<endl;

for(int i=0;i<3;i++)

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

cout<<endl<<" Enter the number of Laptop bags 'Ramu', 'Raju' & 'Shyam' want to purchase";

cout<<endl;

outdata<<endl<<" Number of Laptop bags 'Ramu', 'Raju' & 'Shyam' want to purchase"<<endl;

for(int i=0;i<3;i++)

{cin>>Laptop_bag[i];outdata<<Mouse[i]<<endl;}

cout<<endl<<" Enter the number of Adaptor 'Ramu', 'Raju' & 'Shyam' want to purchase";

cout<<endl;

outdata<<endl<<" Number of Adaptor 'Ramu', 'Raju' & 'Shyam' want to purchase"<<endl;

for(int i=0;i<3;i++)

{cin>>Adaptor[i];outdata<<Mouse[i]<<endl;}

for(int i=0;i<M;i++) //conditional statement

{

for(int j=1;j<3;j++) //conditional statement

{

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

}

}

for(int k=0; k<3; k++) //conditional statement

{

if(k==0) //conditional statement

{

cout<<" Preffered Vendor for Ramu :-";

}

else if(k==1) //conditional statement

{

cout<<" Preffered Vendor for Raju :-";

}

else //conditional statement

{

cout<<" Preffered Vendor for Shyam :-";

}

}

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) //conditional statement

{

cout<<"Vendor1"<<endl;

}

else //conditional statement

{

cout<<"Vendor2"<<endl;

}

break;

case 0:

exit(0);

default: //default statement for switch case

cout<<"Invalid selection:\n"<<endl;

goto start; //unconditional jump to the 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.