Challenge

Project 1

/* PROJECT-1 */

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.


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:

1. Array one ->commodities

2. Array two ->Vendors

3. 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

1. Enter Commodities to be purchased

2. Enter Vendor quotations

3. 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.

Ans:

#include <iostream>

#include <fstream>

#include <cstring>

#define M 5

#define N 3

using namespace std;

int main()

{

string* A = new string[M * N]; /* Dynamically allocated memory of size M*N */

int Laptop[3], Mouse[3], Headset[3], Laptop_bag[3], Adaptor[3]; /* Arrays for commodities */

int s, k;

int vendor1_total, vendor2_total; /* Variables for vendor totals */

int num[5][3]; /* Array to store vendor quotations */

ofstream outdata;

outdata.open("project_1_sample.txt");

start:

cout << "Select from the menu: \n" << endl;

cout << "1. Enter the commodities to be purchased\n" << endl;

cout << "2. Enter the vendor quotations\n" << endl;

cout << "3. Find the best vendor (Only select after entering commodities and vendor data)\n" << endl;

cout << "0. Exit\n" << endl;

cin >> s;

outdata << "Selected option: " << s << endl;

switch (s)

{

case 1:

cout << "Please enter the name of commodities:\n" << endl;

outdata << "\nName of the commodities:\n";

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

{

cout << "Commodity " << i + 1 << ": ";

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

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

}

outdata << endl;

cout << endl;

goto start;

break;

case 2:

cout << "Enter the vendor 1 quotations:\n" << endl;

outdata << "\nVendor 1 quotations as per commodities:\n";

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

{

cout << "Price for " << *(A + i * N) << ": ";

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

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

}

cout << "Enter the vendor 2 quotations:\n" << endl;

outdata << "\nVendor 2 quotations as per commodities:\n";

for (int i = 0; i < M; i++) {

cout << "Price for " << *(A + i * N) << ": ";

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

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

}

goto start;

break;

case 3:

cout << "Enter the number of laptops 'Ramu', 'Raju', and 'Shyam' want to buy:\n";

outdata << "\nNumber of laptops bought by 'Ramu', 'Raju', and 'Shyam':\n";

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

{

cin >> Laptop[i];

outdata << Laptop[i] << endl;

}

cout << "Enter the number of mice 'Ramu', 'Raju', and 'Shyam' want to buy:\n";

outdata << "\nNumber of mice bought by 'Ramu', 'Raju', and 'Shyam':\n";

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

{

cin >> Mouse[i];

outdata << Mouse[i] << endl;

}

cout << "Enter the number of headsets 'Ramu', 'Raju', and 'Shyam' want to buy:\n";

outdata << "\nNumber of headsets bought by 'Ramu', 'Raju', and 'Shyam':\n";

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

{

cin >> Headset[i];

outdata << Headset[i] << endl;

}

cout << "Enter the number of laptop bags 'Ramu', 'Raju', and 'Shyam' want to buy:\n";

outdata << "\nNumber of laptop bags bought by 'Ramu', 'Raju', and 'Shyam':\n";

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

{

cin >> Laptop_bag[i];

outdata << Laptop_bag[i] << endl;

}

cout << "Enter the number of adaptors 'Ramu', 'Raju', and 'Shyam' want to buy:\n";

outdata << "\nNumber of adaptors bought by 'Ramu', 'Raju', and 'Shyam':\n";

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

{

cin >> Adaptor[i];

outdata << Adaptor[i] << endl;

}

for (int i = 0; i < M; i++) /* Convert the stored vendor prices to integers for calculation */

{

for (int j = 1; j < 3; j++)

{

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

}

}

for (k = 0; k < 3; k++) /* Calculate the best vendor for each person */

{

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)

{

cout << "The best vendor for ";

}

else

{

cout << "The best vendor for ";

}

switch (k)

{

case 0:

cout << "Ramu is: Vendor " << (vendor1_total < vendor2_total ? "1" : "2") << endl;

break;

case 1:

cout << "Raju is: Vendor " << (vendor1_total < vendor2_total ? "1" : "2") << endl;

break;

case 2:

cout << "Shyam is: Vendor " << (vendor1_total < vendor2_total ? "1" : "2") << endl;

break;

}

}

break;

case 0:

outdata.close();

exit(0);

break;

default:

cout << "Invalid selection. Please try again.\n" << endl;

goto start;

}

delete[] A; /* Free dynamically allocated memory */

return 0;

}

Algorithm Used:

1. Input Collection:

(a). The program collects the names of commodities and the corresponding quotations from two vendors.

(b). It also gathers the number of each commodity that Ramu, Raju, and Shyam wish to purchase.

2. Cost Calculation:

(a). For each individual (Ramu, Raju, Shyam), the program calculates the total cost for purchasing all required commodities from each vendor.

(b). The total cost for Vendor 1 and Vendor 2 is calculated separately based on the quantities required and the unit prices provided by each vendor.

3. Comparison (Greedy Decision-Making):

(a). The program compares the total costs calculated for Vendor 1 and Vendor 2 for each individual.

(b). For each individual, the program selects the vendor offering the lower total cost. This selection is the "greedy" part because it makes a locally optimal choice (cheaper option) at each step for each person.

4. Output the Result:

The program outputs the best vendor for each individual based on the total cost comparison.

Description:

1. Greedy Choice:

(a). For each person (Ramu, Raju, Shyam), the algorithm calculates the total cost from both vendors and immediately selects the vendor with the lower total cost.

(b). This decision is "greedy" because it aims to minimize the cost without considering any potential future decisions or constraints.

2. Efficiency:

This algorithm is efficient and runs in linear time with respect to the number of commodities and individuals because it only involves basic arithmetic operations and comparisons.

Pseudocode for the Greedy Algorithm:

1. Input:

Commodities list, vendor quotations, quantities required by Ramu, Raju, and Shyam.

2. For each person (Ramu, Raju, Shyam):

(a). Calculate vendor1_total = sum(commodity_quantity[i] * vendor1_price[i]).

(b). Calculate vendor2_total = sum(commodity_quantity[i] * vendor2_price[i]).

(c). Compare vendor1_total and vendor2_total.

(d). Select the vendor with the lower total cost for that person.

3. Output:

Print the best vendor for each person.

Input given:


Uses of the project:

1. Cost Optimization for IT Procurement:

The project helps IT support teams or procurement departments select the most cost-effective vendor when purchasing IT-related commodities like laptops, mice, headsets, adapters, etc. By comparing the prices offered by different vendors, the organization can minimize its expenses while still meeting its equipment needs.

2. Budget Management:

For organizations operating within strict budget constraints, this project can ensure that purchases stay within the allocated budget. By optimizing vendor selection based on cost, the project helps manage and reduce expenditure, which is particularly crucial during financial restructuring or in a cost-sensitive environment.

3. Efficient Resource Allocation:

With the shift to remote work, companies need to allocate resources efficiently. This project assists in transitioning from physical office supplies (e.g., stationary) to necessary remote work commodities (e.g., laptops, headsets). It reallocates the budget from less essential items to critical IT resources needed for remote work.

4. Data-Driven Decision Making:

The project supports data-driven decision-making by systematically comparing costs across multiple vendors. This approach reduces the likelihood of biased or uninformed purchasing decisions, ensuring that decisions are based on factual cost analysis rather than guesswork.

5. Record-Keeping and Auditing:

By saving all inputs and outputs to a file, the project ensures that there is a clear record of the decisions made and the rationale behind them. This can be useful for auditing purposes, tracking expenses, or reviewing procurement decisions over time.

6. Scalability for Larger Procurement Tasks:

The program's design is easily scalable to handle more commodities or additional vendors. This makes it adaptable to larger procurement tasks beyond just IT commodities, allowing it to be used in other departments or for other types of goods and services.

7. Training and Simulation:

The project can be used as a training tool for IT support staff or procurement officers to practice making cost-effective purchasing decisions. It simulates real-world procurement scenarios, helping trainees develop the skills needed to evaluate vendor proposals and optimize spending.

8. Vendor Performance Evaluation:

Over time, the program can be used to track which vendors consistently offer the best prices, helping the organization build a database of preferred suppliers. This data can be valuable for negotiating better deals or making long-term procurement plans.

9. Automation of Routine Tasks:

The project automates the routine task of comparing vendor prices, freeing up time for IT support staff to focus on more complex tasks. This is especially useful in large organizations where such comparisons need to be made frequently.

10. Transparency and Accountability:

By documenting each step of the vendor selection process, the project promotes transparency in procurement decisions. This can be important in environments where accountability is critical, such as in public sector organizations or companies with stringent compliance requirements.

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.