AbdurRehman 2 G 350
AbdurRehman 2 G 350
OOP
Name: AbdurRehman Roll no:350-2G
Section: 2-G Teacher: MISS Misbha
Qusetion 1
#include <iostream>
#include <string>
struct Student {
string name;
int score;
char grade;
};
int main() {
Student students[NUM_STUDENTS];
cout << "Enter student " << i + 1 << "'s name: ";
cout << "Enter student " << i + 1 << "'s score: ";
students[i].grade = 'A';
students[i].grade = 'B';
} else {
students[i].grade = 'F';
highestScore = students[i].score;
cout << "Name: " << students[i].name << ", Score: " << students[i].score << ", Grade: " <<
students[i].grade << endl;
}
Question # 2
#include <iostream>
#include <string>
struct menuItemType
{
string itemName;
double price;
};
int main()
{
menuItemType menu[] = {
{"Plain Egg", 1.45},
{"Bacon and Egg", 2.45},
{"Muffin", 0.99},
{"French Toast", 1.99},
{"Fruit Basket", 2.49},
{"Cereal", 0.69},
{"Coffee", 0.50},
{"Tea", 0.75}
};
double total = 0;
int choice;
while (true)
{
cout << "Enter your choice (1-8)"<<endl<<"Press 0 for bill : ";
cin >> choice;
if (choice == 0)
break;
total += menu[choice - 1].price;
}
Question 3
Code
#include <iostream>
#include <string>
struct menuItemType
{
string itemName;
double price;
};
int main()
{
menuItemType menu[] = {
{"Bacon and Egg", 3.52},
{"Muffin", 1.22},
{"Coffee", 0.75}
};
cout << "Welcome to Our Restaurant" << endl;
for (int i = 0; i < 3; i++)
{
cout << i + 1 << ". " << menu[i].itemName << " $" << menu[i].price << endl;
}
double total = 0;
int choice, quantity;
while (true)
{
cout << "Enter your choice (1-3)"<<endl<<"Pree 0 for bill: ";
cin >> choice;
if (choice == 0)
break;
cout << "Enter the quantity: ";
cin >> quantity;
total += menu[choice - 1].price * quantity;
}