Project 1
live-batch "Esakki vigneshwaran"
program:
#include <iostream> // Include the input/output library
#include <cstring> // Include the string manipulation library
using namespace std; // Use the standard namespace
const int MAX_COMMODITIES = 5; // Define a constant integer for the maximum number of commodities
const int MAX_VENDORS = 2; // Define a constant integer for the maximum number of vendors
// Function to display the menu
void display_menu() { // Define a function to display the menu
cout << "Menu\n"; // Output the menu title
cout << "1. Enter Commodities to be purchased\n"; // Output the first menu option
cout << "2. Enter Vendor quotations\n"; // Output the second menu option
cout << "3. Exit\n"; // Output the third menu option
}
class Commodity // Define a class for a commodity
{
public: // Define public access
char name[50]; // Define a character array for the commodity name
int cost[MAX_VENDORS]; // Define an integer array for the cost of the commodity from each vendor
Commodity() // Define a default constructor
{
char name[50]; // Initialize the commodity name array
int cost[MAX_VENDORS]; // Initialize the cost array
}
};
class Vendor // Define a class for a vendor
{
public: // Define public access
char name[50]; // Define a character array for the vendor name
int prices[MAX_COMMODITIES]; // Define an integer array for the vendor's prices for each commodity
Vendor() // Define a default constructor
{
char name[50]; // Initialize the vendor name array
int prices[MAX_COMMODITIES]; // Initialize the prices array
}
};
int main()
{
int choice;
do {
display_menu();
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
{
Commodity commodities[MAX_COMMODITIES];
cout << "Enter the name of each commodity:\n";
for (int i = 0; i < MAX_COMMODITIES; i++) {
cout << i + 1 << ". ";
cin >> commodities[i].name;
}
break;
}
case 2:
{
Vendor vendors[MAX_VENDORS];
Commodity commodities[MAX_COMMODITIES];
cout << "Enter the name of each vendor:\n";
for (int i = 0; i < MAX_VENDORS; i++) {
cout << i + 1 << ". ";
cin >> vendors[i].name;
}
cout << "Enter the cost of each commodity for each vendor:\n";
for (int i = 0; i < MAX_COMMODITIES; i++) {
cout << commodities[i].name << ":\n";
for (int j = 0; j < MAX_VENDORS; j++) {
cout << vendors[j].name << ": ";
cin >> commodities[i].cost[j];
}
}
// Find the best vendors and display the result
for (int i = 0; i < MAX_COMMODITIES; i++) {
int min_cost = commodities[i].cost[0];
int best_vendor = 0;
for (int j = 1; j < MAX_VENDORS; j++) {
if (commodities[i].cost[j] < min_cost) {
min_cost = commodities[i].cost[j];
best_vendor = j;
}
}
cout << "Best vendor for " << commodities[i].name << ": " << vendors[best_vendor].name << endl;
}
break;
}
case 3:
cout << "Exiting program\n";
break;
default:
cout << "Invalid choice\n";
break;
}
} while (choice != 3);
return 0;
}



output:

