Name: Pawan D Sencha
Roll Number: [Link].U4ARE25034
1. Electricity Bill Calculator
#include <iostream>
using namespace std;
// Function to calculate the electricity bill based on units consumed
float calculateBill(int units) {
if (units <= 100) {
return units * 5.0; // Assume rate 1 is 5 per unit
} else {
return (100 * 5.0) + ((units - 100) * 7.0); // Assume next slab rate is 7
int main() {
int units;
cout << "Enter units consumed: ";
cin >> units;
float totalBill = calculateBill(units);
cout << "Total bill amount: " << totalBill << endl;
return 0;
Output
Enter units consumed: 150
Total bill amount: 850
Code Execution Successful
2. Student Grade Evaluator
#include <iostream>
using namespace std;
void evaluateGrade(int m1, int m2, int m3, int m4, int m5) {
float avg = (m1 + m2 + m3 + m4 + m5) / 5.0;
cout << "Average: " << avg << " -> Grade: ";
if (avg >= 90) cout << "A";
else if (avg >= 75) cout << "B";
else if (avg >= 50) cout << "C";
else cout << "Fail";
cout << endl;
int main() {
int s1, s2, s3, s4, s5;
cout << "Enter marks of 5 subjects: ";
cin >> s1 >> s2 >> s3 >> s4 >> s5;
evaluateGrade(s1, s2, s3, s4, s5);
return 0;
Output
Enter marks of 5 subjects: 85 90 78 82 80
Average: 83 -> Grade: B
Code Execution Successful
3. Simple Calculator using Functions
#include <iostream>
using namespace std;
float calculate(float num1, float num2, char op) {
switch (op) {
case '+': return num1 + num2;
case '-': return num1 - num2;
case '*': return num1 * num2;
case '/':
if (num2 != 0) return num1 / num2;
else { cout << "Error: Division by zero! "; return 0; }
default: cout << "Invalid operator! "; return 0;
int main() {
float a, b;
char op;
cout << "Enter two numbers and operator (e.g., 5 3 +): ";
cin >> a >> b >> op;
cout << "Result: " << calculate(a, b, op) << endl;
return 0;
Output
Enter two numbers and operator (e.g., 5 3 +): 10 4 *
Result: 40
Code Execution Successful
4. ATM Withdrawal Simulation
#include <iostream>
using namespace std;
void withdraw(float &balance, float amount) {
if (amount <= balance) {
balance -= amount;
cout << "Updated balance: " << balance << endl;
} else {
cout << "Error: Insufficient funds!" << endl;
int main() {
float balance = 5000.0, withdraw_amount;
cout << "Current Balance: " << balance << endl;
cout << "Enter amount to withdraw: ";
cin >> withdraw_amount;
withdraw(balance, withdraw_amount);
return 0;
Output
Current Balance: 5000
Enter amount to withdraw: 1200
Updated balance: 3800
Code Execution Successful
5. Temperature Category
#include <iostream>
using namespace std;
void classifyTemperature(float temp) {
if (temp < 20) {
cout << "Category: Cold" << endl;
} else if (temp >= 20 && temp <= 30) {
cout << "Category: Warm" << endl;
} else {
cout << "Category: Hot" << endl;
int main() {
float temp;
cout << "Enter temperature value: ";
cin >> temp;
classifyTemperature(temp);
return 0;
Output
Enter temperature value: 24.5
Category: Warm
Code Execution Successful
6. Factorial using Function
#include <iostream>
using namespace std;
long long fact(int n) {
if (n <= 1) return 1;
return n * fact(n - 1);
int main() {
int n;
cout << "Enter a number: ";
cin >> n;
cout << "Factorial: " << fact(n) << endl;
return 0;
Output
Enter a number: 5
Factorial: 120
Code Execution Successful
(Hint used: fact(n) = n * fact(n-1) )
7. Even-Odd Counter
#include <iostream>
using namespace std;
void countEvenOdd(int arr[], int size) {
int even_count = 0, odd_count = 0;
for (int i = 0; i < size; i++) {
if (arr[i] % 2 == 0) {
even_count++;
} else {
odd_count++;
cout << "Even count: " << even_count << " Odd count: " << odd_count << endl;
int main() {
int size;
cout << "Enter array size: ";
cin >> size;
int arr[size];
cout << "Enter elements: ";
for (int i = 0; i < size; i++) {
cin >> arr[i];
countEvenOdd(arr, size);
return 0;
Output
Enter array size: 6
Enter elements: 12 7 9 4 20 11
Even count: 3 Odd count: 3
Code Execution Successful
8. Leap Year Checker
#include <iostream>
using namespace std;
void checkLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
cout << year << " is a Leap Year" << endl;
} else {
cout << year << " is Not a Leap Year" << endl;
int main() {
int year;
cout << "Enter year: ";
cin >> year;
checkLeapYear(year);
return 0;
Output
Enter year: 2024
2024 is a Leap Year
Code Execution Successful
(Hint used: Divisible by 4 and not 100 unless 400 )
9. Distance Converter
#include <iostream>
using namespace std;
void convertDistance(float km) {
float meters = km * 1000;
float cm = meters * 100;
cout << km << " km = " << meters << " meters and " << cm << " cm." << endl;
int main() {
float km;
cout << "Enter distance in km: ";
cin >> km;
convertDistance(km);
return 0;
Output
Enter distance in km: 2.5
2.5 km = 2500 meters and 250000 cm.
Code Execution Successful
10. Salary Bonus Calculator
C++
#include <iostream>
using namespace std;
void calculateFinalSalary(float salary, int years) {
float final_salary = salary;
if (years >= 5) {
final_salary += (salary * 0.10);
}
cout << "Final salary: " << final_salary << endl;
int main() {
float salary;
int years;
cout << "Enter salary and years of experience: ";
cin >> salary >> years;
calculateFinalSalary(salary, years);
return 0;
Output
Enter salary and years of experience: 50000 6
Final salary: 55000
Code Execution Successful