All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Aim and task: Using array of pointers or dynamically using double pointers dynamically allocate memory for every row. Menu should be listed for prompting the user input to enter the commodities and vendors. Find the best vendor from whom the purchases can be made based on the number of commodities and respective…
Akshay Chandel
updated on 12 Aug 2022
Aim and task:
Background and data available:
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.
Scripting/Code:
#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<<endl;
cin>>s;
outdata << "Selected option" << endl;
outdata << s << endl;
// operations for selected choice from menu
switch(s)
{
case 1:
cout<<"nPlease enter the name of commoditiesn";
cout<<endl;
outdata << "nName of commodities" << endl;
for (int i = 0; i < M; i++)
{
for (int j = 0; j < 1; j++)
{
cin>> *(A + i*N + j); // assign values to the allocated memory for commodities only
outdata << *(A + i*N + j) << endl;
}
}
outdata<<endl;
cout<<endl;
goto start;
break;
case 2:
cout<<"nPlease enter the Vendor 1 quotations (Strictly follow the sequence as per commodities entered): n";
cout<<endl;
outdata << "nVendor 1 quotations (Sequence: As per commodities entered)" << endl;
for (int i = 0; i < M; i++)
{
for (int j = 1; j < 2; j++)
{
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<<endl;
outdata << "nVendor 2 quotations (Sequence: As per commodities entered)" << endl;
for (int i = 0; i < M; i++)
{
for (int j = 2; j < 3; j++)
{
cin>> *(A + i*N + j); // assign values to the allocated memory for vendor 2 quotations
outdata << *(A + i*N + j) << endl;
}
}
outdata<<endl;
cout<<endl;
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<<endl;
outdata << "nNo. of laptops 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<<endl;
for(int i=0; i<3; i++)
{cin>>Laptop[i]; outdata << Laptop[i] << endl;} // Taking input and at the same time writing input data into file.
cout<<"nEnter the no. of Mouse 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):n";
cout<<endl;
outdata << "nNo. of Mouse 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<<endl;
for(int i=0; i<3; i++)
{cin>>Mouse[i]; outdata << Mouse[i] << endl;}
cout<<"nEnter the no. of Headset 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):n";
cout<<endl;
outdata << "nNo. of Headset 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<<endl;
for(int i=0; i<3; i++)
{cin>>Headset[i]; outdata << Headset[i] << endl;}
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<<endl;
outdata << "nNo. of Laptop_Bag 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<<endl;
for(int i=0; i<3; i++)
{cin>>Laptop_Bag[i]; outdata << Laptop_Bag[i] << endl;}
cout<<"nEnter the no. of Adapter 'Ramu', 'Raju' and 'Shyam' want to be bought (Strictly follow sequence as Ramu, raju and Shyam):n";
cout<<endl;
outdata << "nNo. of Adapter 'Ramu', 'Raju' and 'Shyam' want to be bought (Sequence: Ramu, raju and Shyam):"<<endl;
for(int i=0; i<3; i++)
{cin>>Adapter[i]; outdata << Adapter[i] << endl;}
//conveting strings to integer. As we have created array of strings while taking commodity and vendor inputs
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++)
{
//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<vendor2_total)
{
cout<<" Vendor 1 "<<endl;
}
else
{
cout<<" Vendor 2 "<<endl;
}
}
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 . . .
Inputs stored(write) in txt file:
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Using C++ to write/store and dynamically allocate the data to find Best vendor
Aim and task: Using array of pointers or dynamically using double pointers dynamically allocate memory for every row. Menu should be listed for prompting the user input to enter the commodities and vendors. Find the best vendor from whom the purchases can be made based on the number of commodities and respective…
12 Aug 2022 03:22 AM IST
ADAPTIVE CRUISE CONTROL
PROJECT ADAPTIVE CRUISE CONTROL AIM: To develop Simulink model for Adaptive cruise control logic, create and define data in Simulink data dictionary, perform model advisor check and generate c-code using simulink platform. Brief Overview of ACC (Adaptive cruise control): Adaptive cruise control (ACC)…
31 Oct 2021 01:00 PM IST
Project 2-Highway Assistant-Lane Changing Assistant
Highway Assistant-Lane Changing Assistant About the feature: The Highway Assistant supports the driver and takes over the longitudinal and lateral guidance of the vehicle in monotonous driving situations on highways. The partially automated function can automatically start, accelerate, brake as well as steer the…
18 Oct 2021 03:40 AM IST
Project 1- Traffic Jam Assistant Feature
Traffic Jam Assistant Feature About Tarffic jam assist feature Traffic Jam Assist can assist you to in driving in highway traffic jams up to 60 km/h while the host vehicle automatically follows the vehicle ahead. The latest forward-looking radar and camera technology helps sense traffic and the road ahead.…
09 Oct 2021 12:03 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.