Challenge

Project 1

Project 1:

C++ program that implements the described functionality using an array of pointers and dynamically allocated memory. We will also provide a menu for the user to enter commodities and vendor quotations, and save the data to a file.

Objectives:

  1. IT Support Team Management: The primary objective is to manage the IT support team (Ramu, Raju, and Shyam) responsible for handling the procurement and budgeting for commodities and workstations for various departments in the organization.

  2. Workstation Procurement: The team needs to handle the procurement of workstations, including laptops, mice, headsets, laptop bags, and adapters. The number of each commodity required for each team member should be managed efficiently.

  3. Vendor Selection: The team needs to evaluate two vendors and decide which one to choose for purchasing the required commodities. This decision should be based on reasonable prices and keeping the overall budget in mind.

  4. Expense Reduction: The team should focus on reducing stationary expenses for employees working from home and allocate those expenses to workstation-related items, ensuring that employees can work without any hindrance.

  5. Department-wise Management: The team members are assigned specific departments (ADAS, Electro, Connexion), and they need to maintain the budget and procurement for each department separately.

  6. Data Input and Management: The program should provide a user-friendly menu to allow data input for commodities and vendor quotations. The entered data should be saved to a file for future reference.

  7. Dynamic Memory Allocation: The program should use dynamic memory allocation to handle arrays of structures for commodities and vendors, allowing flexibility in the number of commodities and vendors.

  8. User Interaction: The program should interact with the user through the menu, providing options to input data, display data, and save data to a file.

  9. Error Handling: The program should handle invalid inputs and errors gracefully, providing appropriate feedback and instructions to the user.

  10. Financial Restructuring: The team's objective is to align the financial structure with the work-from-home policy, ensuring that the organization optimizes its resources and stays within budget constraints.

Here's the step-by-step process:

Step 1: Define the necessary header files and constants.

#include <iostream>
#include <fstream>
using namespace std;

const int MAX_COMMODITIES = 5;
const int MAX_VENDORS = 2;

Step 2: Define the structure for Commodities and Vendors.

struct Commodities {
    string name;
    int quantities[MAX_VENDORS];
};

struct Vendors {
    string name;
    int prices[MAX_COMMODITIES];
};

Step 3: Implement functions to input commodities and vendor quotations.

void inputCommodities(Commodities* commodities) {
    cout << "Enter Commodities to be purchased:" << endl;
    for (int i = 0; i < MAX_COMMODITIES; ++i) {
        cout << "Enter name of commodity " << i + 1 << ": ";
        cin >> commodities[i].name;
    }
}

void inputVendors(Vendors* vendors) {
    cout << "Enter Vendor quotations:" << endl;
    for (int i = 0; i < MAX_VENDORS; ++i) {
        cout << "Enter name of vendor " << i + 1 << ": ";
        cin >> vendors[i].name;
        for (int j = 0; j < MAX_COMMODITIES; ++j) {
            cout << "Enter price of " << vendors[i].name << " for commodity " << j + 1 << ": ";
            cin >> vendors[i].prices[j];
        }
    }
}
Step 4: Implement a function to display the commodities and vendor quotations.
void displayData(Commodities* commodities, Vendors* vendors) {
    cout << "Commodities:" << endl;
    for (int i = 0; i < MAX_COMMODITIES; ++i) {
        cout << commodities[i].name << endl;
    }

    cout << "Vendors:" << endl;
    for (int i = 0; i < MAX_VENDORS; ++i) {
        cout << vendors[i].name << endl;
    }
}
Step 5: Implement a function to save data to a file.
void saveDataToFile(Commodities* commodities, Vendors* vendors) {
    ofstream outFile("data.dat");
    if (!outFile.is_open()) {
        cout << "Error opening file." << endl;
        return;
    }

    outFile << "Commodities:" << endl;
    for (int i = 0; i < MAX_COMMODITIES; ++i) {
        outFile << commodities[i].name << endl;
    }

    outFile << "Vendors:" << endl;
    for (int i = 0; i < MAX_VENDORS; ++i) {
        outFile << vendors[i].name << endl;
    }

    outFile.close();
    cout << "Data saved to file successfully." << endl;
}

Step 6: Implement the main function with the menu

int main() {
    Commodities* commodities = new Commodities[MAX_COMMODITIES];
    Vendors* vendors = new Vendors[MAX_VENDORS];

    int choice;
    do {
        cout << "Menu:" << endl;
        cout << "1. Enter Commodities to be purchased" << endl;
        cout << "2. Enter Vendor quotations" << endl;
        cout << "3. Display Data" << endl;
        cout << "4. Save Data to File" << endl;
        cout << "5. Exit" << endl;
        cout << "Enter your choice: ";
        cin >> choice;

        switch (choice) {
        case 1:
            inputCommodities(commodities);
            break;
        case 2:
            inputVendors(vendors);
            break;
        case 3:
            displayData(commodities, vendors);
            break;
        case 4:
            saveDataToFile(commodities, vendors);
            break;
        case 5:
            cout << "Exiting..." << endl;
            break;
        default:
            cout << "Invalid choice. Try again." << endl;
            break;
        }
    } while (choice != 5);

    delete[] commodities;
    delete[] vendors;

    return 0;
}

C++ program that combines all the steps, implementing the IT Support Team Management system for commodity procurement and vendor selection, with user interaction and data saving to a file:

#include <iostream>
#include <fstream>
using namespace std;

const int MAX_COMMODITIES = 5;
const int MAX_VENDORS = 2;

struct Commodities {
    string name;
    int quantities[MAX_VENDORS];
};

struct Vendors {
    string name;
    int prices[MAX_COMMODITIES];
};

void inputCommodities(Commodities* commodities) {
    cout << "Enter Commodities to be purchased:" << endl;
    for (int i = 0; i < MAX_COMMODITIES; ++i) {
        cout << "Enter name of commodity " << i + 1 << ": ";
        cin >> commodities[i].name;
    }
}

void inputVendors(Vendors* vendors) {
    cout << "Enter Vendor quotations:" << endl;
    for (int i = 0; i < MAX_VENDORS; ++i) {
        cout << "Enter name of vendor " << i + 1 << ": ";
        cin >> vendors[i].name;
        for (int j = 0; j < MAX_COMMODITIES; ++j) {
            cout << "Enter price of " << vendors[i].name << " for commodity " << j + 1 << ": ";
            cin >> vendors[i].prices[j];
        }
    }
}

void displayData(Commodities* commodities, Vendors* vendors) {
    cout << "Commodities:" << endl;
    for (int i = 0; i < MAX_COMMODITIES; ++i) {
        cout << commodities[i].name << endl;
    }

    cout << "Vendors:" << endl;
    for (int i = 0; i < MAX_VENDORS; ++i) {
        cout << vendors[i].name << endl;
    }
}

void saveDataToFile(Commodities* commodities, Vendors* vendors) {
    ofstream outFile("data.dat");
    if (!outFile.is_open()) {
        cout << "Error opening file." << endl;
        return;
    }

    outFile << "Commodities:" << endl;
    for (int i = 0; i < MAX_COMMODITIES; ++i) {
        outFile << commodities[i].name << endl;
    }

    outFile << "Vendors:" << endl;
    for (int i = 0; i < MAX_VENDORS; ++i) {
        outFile << vendors[i].name << endl;
    }

    outFile.close();
    cout << "Data saved to file successfully." << endl;
}

int main() {
    Commodities* commodities = new Commodities[MAX_COMMODITIES];
    Vendors* vendors = new Vendors[MAX_VENDORS];

    int choice;
    do {
        cout << "Menu:" << endl;
        cout << "1. Enter Commodities to be purchased" << endl;
        cout << "2. Enter Vendor quotations" << endl;
        cout << "3. Display Data" << endl;
        cout << "4. Save Data to File" << endl;
        cout << "5. Exit" << endl;
        cout << "Enter your choice: ";
        cin >> choice;

        switch (choice) {
        case 1:
            inputCommodities(commodities);
            break;
        case 2:
            inputVendors(vendors);
            break;
        case 3:
            displayData(commodities, vendors);
            break;
        case 4:
            saveDataToFile(commodities, vendors);
            break;
        case 5:
            cout << "Exiting..." << endl;
            break;
        default:
            cout << "Invalid choice. Try again." << endl;
            break;
        }
    } while (choice != 5);

    delete[] commodities;
    delete[] vendors;

    return 0;
}

Explanation:

  1. We start by defining the necessary header files, constants, and structures for Commodities and Vendors.

  2. We define the constants MAX_COMMODITIES and MAX_VENDORS to specify the maximum number of commodities and vendors, respectively. This provides flexibility to change these values easily in the future if needed.

  3. The inputCommodities() function is responsible for taking user input for the commodities. It prompts the user to enter the name of each commodity and stores them in the commodities array of structures.

  4. The inputVendors() function is responsible for taking user input for the vendor quotations. It prompts the user to enter the name and price of each commodity offered by each vendor. The data is stored in the vendors array of structures.

  5. The displayData() function is used to display the entered commodities and vendor quotations. It simply prints the names of commodities and vendors stored in the commodities and vendors arrays.

  6. The saveDataToFile() function is used to save the entered data to a file named "data.dat". It opens the file, writes the names of commodities and vendors to the file, and then closes it.

  7. In the main() function, we dynamically allocate memory for two arrays of structures: commodities and vendors.

  8. The program presents a menu to the user using a do-while loop. The menu allows the user to choose between entering commodities, entering vendor quotations, displaying data, saving data to a file, or exiting the program.

  9. Depending on the user's choice, the program calls the respective functions (inputCommodities(), inputVendors(), displayData(), saveDataToFile()) to perform the desired action.

  10. After the user exits the program, we free the dynamically allocated memory using delete[].

In summary, this C++ program is a simple IT Support Team Management system that allows users to input commodity and vendor data, display the entered data, and save it to a file for future reference. The program uses dynamic memory allocation to handle arrays of structures and provides a user-friendly menu for interaction.

Output:

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.