Project 1
Question
Ramu, Raju and Shyam are working in an IT support team in an Organisation. An organisation has several departments which work on different projects. Due to covid organisations had to restructure their finances as work from home should be implemented across the organisation. There would be a number of workstations to be purchased in order to support employees work without any hindrance and achieve the project deliverables.
As a part of their duty, each of them (Ramu,Raju,Shyam) are given responsibilities to maintain the project budget and reduce the stationary expenses made by various departments. Each department expenses depends on the number of people working in the project, cubicles desk and cubicle chairs allocated for each person, Workstation allocation which includes Desktop/Laptop, headset and stationary items such as Notepad, Pen, Pencil, Stapler, A4 Sheets for printouts of project material etc. One or two printers would be allocated to departments based on the project size. Ramu, Raju and Shyam are required to maintain these commodities and bring down the project expense cost as the stationary items would not be required as employees would be working from home. Hence, the expenses on stationery should be transferred to the workstation expenses. Ramu is responsible for Department ADAS, Raju is the IT support contact for Department Electro, Shyam is the IT SPOC(single point of contact ) for Department Connexion. The manager of each department has shared the number of commodities required to the IT SPOC’s and they had approached two vendors who had given their reasonable quotations for the commodities. However, the finance department had asked the IT support team to purchase within the given budget and reduce the expenses as discussed above.
Say there are two vendors from whom the commodities/workstations are ordered, the individual prices and desired quantities of commodities are given in the following tables.
|
Person/Number of Commodities to be brought |
Laptop |
Mouse |
Headset |
Laptop Bag |
Adapter |
|
Ramu |
5 |
15 |
10 |
5 |
20 |
|
Raju |
10 |
10 |
25 |
10 |
15 |
|
Shyam |
3 |
5 |
6 |
3 |
10 |
|
Commodity/Commodity cost |
Vendor1 |
Vendor2 |
|
Laptop |
45000 |
43000 |
|
Mouse |
1500 |
1200 |
|
Headset |
2500 |
3000 |
|
Laptop Bag |
1200 |
1000 |
|
Adapter |
1600 |
1500 |
Taking the above mentioned data as a sample, Find the best vendor from whom the purchases can be made based on the number of commodities and respective prices to pay a reasonable price.
Now, using array of pointers or dynamically using double pointers dynamically allocate memory for every row in the following arrays:
-
Array one ->commodities
-
Array two ->Vendors
-
The Result will also be a two dimensional array or a double pointer.
Also, have a menu listed for prompting the user input to enter the commodities and vendors. The menu looks like
-
Enter Commodities to be purchased
-
Enter Vendor quotations
-
Exit
The data input provided by the user during runtime should be saved to a file(.dat or .txt) using stream classes. Note that this file contains commodities list and vendor data.
Code
#include // standard input-output stream
#include //for string handling and various memory handling functions
#include //file operations
using namespace std;
int main()
{
string *result=new string[5*3];//dynamically allocating memory of array of string datatype
int lap[3],mouse[3],headset[3],lap_bag[3],adapter[3];//for storing no of items each person require
int vendor1,vendor2,choice=1;
int n[5][2];//for storing the vendor quotation and comparing
fstream myfile;
myfile.open("myfile",ios::out);//creating file named "myfile"
if(!myfile)
{
cout<<"File creation failed"<<endl;
}
else
{
cout<<"File created successfully"<<endl;
while(choice!=0)
{
cout<<"Press 1 to enter the Commodities "<<endl;
cout<<"Press 2 to enter the Vendor quotations"<<endl;
cout<<"Press 3 to find best vendor (use this only after entering vendor quotations)"<<endl;
cout<<"press 0 to exit"<<endl;
cin>>choice;
myfile<<"User entered choice:"<<choice<<endl;
switch(choice)
{
case 1:
{
cout<<"Enter the Name of Commodities"<<endl;
myfile<<"Name of Commodities n";
for(int i=0,j=0;i<5;i++)
{
cin>>*(result+i*3+j);
myfile<<*(result+i*3+j)<<endl;
}
myfile<<endl;
break;
}
case 2:
{
cout<<"Enter the Vendor-1 quotations"<<endl;
myfile<<"Vendor-1 quotations n";
for(int i=0,j=1;i<5;i++)
{
cin>>*(result+i*3+j);
myfile<<*(result+i*3+j)<<endl;
}
myfile<<endl;
cout<<"Enter the Vendor-2 quotations"<<endl;
myfile<<"Vendor-2 quotations n";
for(int i=0,j=2;i<5;i++)
{
cin>>*(result+i*3+j);
myfile<<*(result+i*3+j)<<endl;
}
myfile<<endl;
break;
}
case 3:
{
cout<<"Enter the number of laptops Ramu,Raju,Shyam want to purchase"<<endl;
myfile<<"Number of laptops Ramu,Raju,Shyam want to purchase"<<endl;
for(int i=0;i<3;i++)
{
cin>>lap[i];
myfile<<lap[i]<<endl;
}
cout<<"Enter the number of Mouses Ramu,Raju,Shyam want to purchase"<<endl;
myfile<<"Number of Mouse Ramu,Raju,Shyam want to purchase"<<endl;
for(int i=0;i<3;i++)
{
cin>>mouse[i];
myfile<<mouse[i]<<endl;
}
cout<<"Enter the number of Headsets Ramu,Raju,Shyam want to purchase"<<endl;
myfile<<"Number of Headsets Ramu,Raju,Shyam want to purchase"<<endl;
for(int i=0;i<3;i++)
{
cin>>headset[i];
myfile<<headset[i]<<endl;
}
cout<<"Enter the number of Laptop bag Ramu,Raju,Shyam want to purchase"<<endl;
myfile<<"Number of Laptop bag Ramu,Raju,Shyam want to purchase"<<endl;
for(int i=0;i<3;i++)
{
cin>>lap_bag[i];
myfile<<lap_bag[i]<<endl;
}
cout<<"Enter the number of Adaptors Ramu,Raju,Shyam want to purchase"<<endl;
myfile<<"Number of Adaptors Ramu,Raju,Shyam want to purchase"<<endl;
for(int i=0;i<3;i++)
{
cin>>adapter[i];
myfile<<adapter[i]<<endl;
}
for(int i=0;i<5;i++)
{
for(int j=1;j<3;j++)
{
n[i][j]=stoi(*(result+i*3+j));
}
}
for(int i=0;i<3;i++)
{
if(i==0)
{
cout<<"Preffered vendor for Ramu is ";
myfile<<"Preffered vendor for Ramu is ";
}
else if(i==1)
{
cout<<"Preffered vendor for Raju is ";
myfile<<"Preffered vendor for Raju is ";
}
else
{
cout<<"Preffered vendor for Shyam is ";
myfile<<"Preffered vendor for Shyam is ";
}
vendor1=lap[i]*n[0][1]+mouse[i]*n[1][1]+headset[i]*n[2][1]+lap_bag[i]*n[3][1]+adapter[i]*n[4][1];
vendor2=lap[i]*n[0][2]+mouse[i]*n[1][2]+headset[i]*n[2][2]+lap_bag[i]*n[3][2]+adapter[i]*n[4][2];
if(vendor1>vendor2)
{
cout<<"Vendor-2"<<endl;
myfile<<"Vendor-2"<<endl;
}
else
{
cout<<"Vendor-1"<<endl;
myfile<<"Vendor-1"<<endl;
}
}
break;
}
default:
cout<<"Error Invalid choice"<<endl;
}
}
delete[] result;//deallocate the memory
myfile.close();//close fileoperations
}
return 0;
}







Output


File ("myfile")

