Challenge

Project 1

Hi,

I have attached my answers.

Thank you,

#include<iostream>

#include<stdlib.h>

#include<math.h>

#include<fstream>

#include<string>

using namespace std;

int main()

{

string fname, line;

int vendor,tprice=0,bill=0,choice,o=0;

ofstream file;

string orderslist[100];

string product[]={"Laptop","Mouse","Headset","Lap Bag","Adapter"};

int order[5];

int vendora[5][2]={{45000,43000},{1500,1200},{2500,3000},{1200,1000},{1600,1500}};

while(1)

{

cout<<"-----------------------------------------"<<endl;

cout<<"PRODUCTS \t"<<"VENDOR 1 \t"<<"VENDOR 2 \t"<<endl;

cout<<"-----------------------------------------"<<endl;

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

{

cout<<product[i];

for(int j=0; j<2;j++)

{

cout<<"\t\t"<<vendora[i][j];

}

cout<<endl;

}

cout<<"-----------------------------------------"<<endl;

cout<<endl;

cout<<"1. Orders List "<<endl;

cout<<"2. Make Order "<<endl;

cout<<"3. Check Order "<<endl;

cout<<"4. Exit "<<endl;

cout<<"\nEnter u r choice : ";

cin>>choice;

switch(choice)

{

case 1:

{

cout<<"Order List : "<<endl;

if(o==0)

{

cout<<"\nNO ORDERS....\n"<<endl;

}

else

{

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

{

cout<<i+1<<" : "<<orderslist[i]<<endl;

}

}

}

break;

case 2:

cout<<"Create Order : ";

cin>>fname;

file.open(fname+".txt");

file.close();

if(!file)

{

cout<<"Order isn't started...."<<endl;

}

else

{

orderslist[o]=fname;

++o;

cout<<"Vendor 1 or 2 : ";

cin>>vendor;

cout<<"Enter the orders : "<<endl;

file.open(fname+".txt");

cout<<"ORDER : "<<fname<<endl;

file<<"ORDER : "<<fname<<"\tVENDOR : "<<vendor<<endl;

file<<"----------------------------------------------------------------"<<endl;

file<<"PRODUCTS\t"<<"VENDOR PRICE\t"<<"QTY(NOS)\t"<<"TOTAL PRICE(RS)"<<endl;

file<<"----------------------------------------------------------------"<<endl;

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

{

cout<<product[i]<<" : ";

cin>>order[i];

tprice=vendora[i][vendor-1]*order[i];

file<<product[i]<<"\t\t"<<vendora[i][vendor-1]<<"\t\t"<<order[i]<<"\t\t\t"<<tprice<<endl;

bill+=tprice;

}

file<<"----------------------------------------------------------------"<<endl;

file<<"\t\t\t\tTotal : \tRS. "<<bill<<endl;

file<<"----------------------------------------------------------------"<<endl;

file.close();

cout<<"\nORDER PLACED SUCCESSFULLY....\n"<<endl;

bill=0;

}

break;

case 3:

{

cout<<"Enter Order Name : ";

cin>>fname;

ifstream file;

file.open(fname+".txt");

if(!file)

{

cout<<"\n"<<fname<<" : Order doesn't exist..."<<endl;

}

else

{

cout<<"Order : "<<fname<<"\n\n";

while (getline(file, line))

{

cout << line << endl;

}

}

cout<<"\n---------------------Thank you---------------------\n"<<endl;

}

break;

case 4:

cout<<"Thank you !!!"<<endl;

exit(0);

break;

default:

cout<<"In-valid option"<<endl;

break;

}

}

}

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.