OneCompiler

CPP RES_MENU PROGRAM

1608

#include <iostream>
#include <iomanip> // For setting decimal precision

using namespace std;

class RestaurantMenu {
public:
string menuName;
int numItems;
float prices[50]; // Array to store prices (maximum of 50 items)

public:
// Member function to read input
void readInput() {
getline(cin, menuName); // Read menu name
cin >> numItems; // Read number of items
for (int i = 0; i < numItems; ++i) {
cin >> prices[i]; // Read each price
}
}

// Member function to calculate the average price
float calculateAveragePrice() {
    float total = 0.0;
    for (int i = 0; i < numItems; ++i) {
        total += prices[i];
    }
    return total / numItems;
}

// Member function to display the result
void display() {
    cout << "Menu Name: " << menuName << endl;
    cout << fixed << setprecision(2);  // Set decimal precision to 2
    cout << "Average Price: " << calculateAveragePrice() << endl;
}

};

int main() {
RestaurantMenu menu;
menu.readInput(); // Read input data
menu.display(); // Display the results
return 0;
}