0% found this document useful (0 votes)
5 views

Nested + Elseif

C++ program practice qs

Uploaded by

alizehkhan0507
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Nested + Elseif

C++ program practice qs

Uploaded by

alizehkhan0507
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Else If Question

1. The Body Mass Index (BMI) is calculated as weight / (height * height) (weight in kg, height in
meters). Write a C++ program that takes weight and height as input from the user and calculate the
BMI to display the BMI category.
The BMI categories are:

 BMI < 18.5 → Underweight

 18.5 ≤ BMI < 24.9 → Normal weight

 25 ≤ BMI < 29.9 → Overweight

 BMI ≥ 30 → Obese

2. Write a C++ program that takes the person's age as input and determine the ticket price. A cinema
charges ticket prices based on age:

 Age < 5 → Free ticket


 5 ≤ Age < 18 → Child ticket: $10
 18 ≤ Age < 60 → Adult ticket: $20
 Age ≥ 60 → Senior citizen ticket: $15
3. Write a C++ program that takes the student's marks as input and determine and display the grade.
A student’s performance is evaluated based on their marks:
 Marks ≥ 90 → Grade: A
 Marks ≥ 80 → Grade: B
 Marks ≥ 70 → Grade: C
 Marks ≥ 60 → Grade: D
 Marks < 60 → Grade: F
4. Write a C++ program that takes a number as input to determine and display the day of the week.
Displays "Invalid input" if the number is outside 1–7. Given a number (1–7), determine the
corresponding day of the week:

 1 → Sunday

 2 → Monday

 3 → Tuesday

 4 → Wednesday

 5 → Thursday

 6 → Friday

 7 → Saturday
Nested-if Questions:
1. Write a C++ program to determine the largest of three numbers
2. Write a program to classify a triangle based on its angles:
 Acute Triangle: All angles are < 90°.

 Right Triangle: One angle is exactly 90°.

 Obtuse Triangle: One angle is > 90°

3. Write a C++ program using nested-if to display the grade. If marks are invalid, display "Invalid
marks." A student is graded based on their marks, but the grade is only displayed if marks are valid
(between 0 and 100):

 Marks ≥ 90 → Grade: A

 Marks ≥ 80 → Grade: B

 Marks ≥ 70 → Grade: C

 Marks ≥ 60 → Grade: D

 Marks < 60 → Grade: F

4. Write a C++ program to determine if the person can donate blood. To donate blood, a person must
satisfy the following conditions:

 The age must be 18 or older.

 The weight must be 50 kg or more.

5. Write a program to classify an input number as:


 Even and Positive

 Even and Negative

 Odd and Positive

 Odd and Negative

 Zero
You're developing a program for a mobile phone store that offers discounts based on the
model and brand of the phone selected by the customer. Consider the following scenario:
a) The store offers two brands: "Samsung" and "Apple".
b) Each brand has one model: “Budget".
c) If the customer selects a "Budget" model, they receive a 10% discount.

You're developing a program for a coffee shop that offers discounts based on the size of the
coffee selected by the customer. Consider the following scenario:
a) The coffee shop offers two sizes: "Small" and "Large".
b) If the customer selects a "Large" coffee, they receive a 20% discount.
Write a program to calculate the electricity bill based on units consumed:

 Units <= 100: $5/unit

 Units > 100 but <= 300: $7/unit

 Units > 300: $10/unit

 Fixed charges of $50 to the total

Write a program to simulate an ATM machine:

 If the withdrawal amount is divisible by 100, check if the account balance is sufficient.

 If yes, deduct the amount. Otherwise, display an "Insufficient Balance" message.

 If not divisible by 100, display "Invalid Amount."

Write a program to check if a given year is a leap year:

 A year is a leap year if it is divisible by 4.

 However, if the year is divisible by 100, it must also be divisible by 400 to be a leap year.

Write a program to classify a person into an age group:

 Age < 13: Child

 Age >= 13 and < 20: Teenager

 Age >= 20 and < 60: Adult

 Age >= 60: Senior Citizen

You might also like