DSA Paper Solution
DSA Paper Solution
#include <iostream>
#include <queue>
#include <string>
class RestaurantOrderManager {
private:
queue<string> orders;
const int maxCapacity = 5;
public:
void addOrder(const string& order) {
if (orders.size() < maxCapacity) {
orders.push(order);
cout << "Order added: " << order << endl;
} else {
cout << "Cannot add order. Order list is full!" << endl;
}
displayOrders();
}
void serveOrder() {
if (!orders.empty()) {
cout << "Serving order: " << orders.front() << endl;
orders.pop();
} else {
cout << "No orders to serve. The list is empty!" << endl;
}
displayOrders();
}
void displayOrders() {
cout << "Current orders: ";
if (orders.empty()) {
cout << "None" << endl;
} else {
queue<string> temp = orders; // Create a copy to display
while (!temp.empty()) {
cout << temp.front() << " ";
temp.pop();
}
cout << endl;
}
}
};
int main() {
RestaurantOrderManager manager;
// Adding 5 orders
manager.addOrder("Burger");
manager.addOrder("Pizza");
manager.addOrder("Pasta");
manager.addOrder("Salad");
manager.addOrder("Soda");
// Serving 2 orders
manager.serveOrder();
manager.serveOrder();
return 0;
}
solution 2:
#include <iostream>
#include <vector>
#include <string>
struct InventoryItem {
string name;
int quantity;
double price;
};
class InventoryManager {
private:
vector<InventoryItem> items;
public:
void addItem(const string& name, int quantity, double price) {
InventoryItem item = { name, quantity, price };
items.push_back(item);
cout << "Added item: " << name << endl;
}
int main() {
InventoryManager manager;
// Adding 3 items
manager.addItem("Apple", 10, 0.50);
manager.addItem("Banana", 5, 0.30);
manager.addItem("Orange", 8, 0.40);
// Removing 1 item
manager.removeItem("Banana");
return 0;
}
solution 3:
#include <iostream>
#include <stack>
#include <string>
int main() {
// Test expressions
string expressions[] = {
"(5 + (3 * 2))",
"((7 - 3) * (5 + 2)",
"(3 * (2 + (7 - 5)) - 1)"
};
return 0;
}
solution 4:
#include <iostream>
int main() {
// Initialize sales data array
int sales[] = {250, 300, 150, 400, 350, 200};
int size = sizeof(sales) / sizeof(sales[0]); // Calculate the size of the array
return 0;
}