IMCG F6/2 ISLAMABAD
LAB 4
SUBMITTED BY:
VARISHA AHMED
SUBMITTED TO:
SIR SAGHIR
Q.No. 01: Write a program to calculate the electricity bill based on the following
rates:
• If units <= 100: 5 per unit
• If units > 100 and <= 300: 7 per unit for the additional units
• If units > 300: 10 per unit for the additional units
• Input: Number of electricity units consumed.
• Logic: Use if-else statements to calculate the bill based on the consumption slab.
• Expected Output Example:
Input: 250 units → Output: 1600
Q.No. 02: Write a program to calculate the tax payable based on income.
• Input: Income from the user.
• Logic: Use if-else statements to categorize the income:
o Income less than Rs.10,000 → 0% tax
o Income between Rs.10,000 and Rs.30,000 → 10% tax
o Income between Rs.30,000 and Rs.100,000 → 20% tax
o Income above Rs.100,000 → 30% tax
• Expected Output Example:
Input: Rs.25,000 → Output: Tax Payable = Rs.2,500
Q.No.04: Write a program to calculate the electricity bill based on units consumed.
• Input: Units consumed.
• Logic: Use if-else statements to calculate the bill:
o Units < 100 → No charge.
o Units between 100 and 200 → 1.50/unit
o Units between 200 and 500 → 3.50/unit
o Units above 500 → 5.50/unit
• After calculating the base amount, use a switch statement to add a surcharge based on
customer type:
o Domestic → 5% surcharge
o Commercial → 10% surcharge
• Expected Output Example:
Input: 350 units (Domestic) → Output: Base bill = Rs.700, Surcharge = Rs.35, Total bill =
Rs.735
Q.No.05: Write a program to simulate a grading system where students receive grades based
on their total score, and the grading scheme changes based on their course type (Science, Arts,
or Commerce).
• Input: Total score and course type.
• Logic:
o For Science: A for 90+, B for 80-89, C for 70-79, and so on.
o For Arts: A for 85+, B for 75-84, C for 65-74, and so on.
o For Commerce: Similar but with slightly different ranges.
• Use nested if-else and switch to handle the grading logic.
• Expected Output Example:
Input: 87, Science → Output: Grade B
Input: 67, Arts → Output: Grade C
#include <iostream>
using namespace std;
int main() {
int score;
char courseType;
char grade;
cout << "Enter the total score: ";
cin >> score;
cout << "Enter the course type (S for Science, A for Arts, C for Commerce): ";
cin >> courseType;
switch (courseType)
{
case 'S': // Science
if (score >= 90) {
grade = 'A';
} else if (score >= 80) {
grade = 'B';
} else if (score >= 70) {
grade = 'C';
} else if (score >= 60) {
grade = 'D';
} else {
grade = 'F';
}
break;
case 'A': // Arts
if (score >= 85) {
grade = 'A';
} else if (score >= 75) {
grade = 'B';
} else if (score >= 65) {
grade = 'C';
} else if (score >= 55) {
grade = 'D';
} else {
grade = 'F';
}
break;
case 'C': // Commerce
if (score >= 88) {
grade = 'A';
} else if (score >= 78) {
grade = 'B';
} else if (score >= 68) {
grade = 'C';
} else if (score >= 58) {
grade = 'D';
} else {
grade = 'F';
}
break;
default:
cout << "Invalid course type entered!" << endl;
return 1; // Exit the program if invalid course type
}
cout << "Grade: " << grade << endl;
return 0;
}
OUTPUT
Code of the Problem using nested if
Program 1
Code of the Problem using switch statement
Program 2