Solved Questions (1 to 10)
Q1. Electricity Bill Calculation (C Program)
This program calculates the total electricity bill based on the following conditions:
- First 200 units @ Rs. 0.80 per unit
- Next 100 units @ Rs. 0.90 per unit
- Above 300 units @ Rs. 1.00 per unit
- Minimum meter charge is Rs. 100
- Surcharge of 15% if bill exceeds Rs. 400
#include <stdio.h>
int main() {
int units;
float total_bill = 0;
printf("Enter number of units consumed: ");
scanf("%d", &units);
if (units <= 200)
total_bill = units * 0.8;
else if (units <= 300)
total_bill = 200 * 0.8 + (units - 200) * 0.9;
else
total_bill = 200 * 0.8 + 100 * 0.9 + (units - 300) * 1.0;
total_bill += 100;
if (total_bill > 400)
total_bill += 0.15 * total_bill;
printf("Total Electricity Bill = Rs. %.2f\n", total_bill);
return 0;
}
Q2. Array Sorting Program
Solved Questions (1 to 10)
A simple C program to accept and sort numbers using one-dimensional arrays.
#include <stdio.h>
int main() {
int arr[10], n, temp;
printf("Enter number of elements: ");
scanf("%d", &n);
printf("Enter %d elements:\n", n);
for (int i = 0; i < n; i++)
scanf("%d", &arr[i]);
for (int i = 0; i < n-1; i++) {
for (int j = i+1; j < n; j++) {
if (arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
printf("Sorted Array:\n");
for (int i = 0; i < n; i++)
printf("%d ", arr[i]);
return 0;
}
Q3. Functions with Return Type and Parameters
A program showing function with return type and parameters.
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
void greet() {
printf("Hello World!\n");
Solved Questions (1 to 10)
int main() {
int x = 5, y = 10;
printf("Sum = %d\n", add(x, y));
greet();
return 0;
}
Q4. Pointers - Sum and Mean
Using pointers to calculate the sum and mean of array elements.
#include <stdio.h>
int main() {
int arr[5], sum = 0;
float mean;
int *ptr;
printf("Enter 5 numbers: ");
for (int i = 0; i < 5; i++)
scanf("%d", &arr[i]);
ptr = arr;
for (int i = 0; i < 5; i++)
sum += *(ptr + i);
mean = sum / 5.0;
printf("Sum = %d, Mean = %.2f\n", sum, mean);
return 0;
}
Q5. Structure to Store Student Marks
Using structure to store marks of students and print names above and below average.
Solved Questions (1 to 10)
#include <stdio.h>
struct Student {
char name[50];
float marks;
};
int main() {
struct Student s[5];
int n;
float avg = 0;
printf("Enter number of students: ");
scanf("%d", &n);
for (int i = 0; i < n; i++) {
printf("Enter name and marks for student %d: ", i + 1);
scanf("%s %f", s[i].name, &s[i].marks);
avg += s[i].marks;
}
avg /= n;
printf("\nAverage Marks = %.2f\n", avg);
printf("Above average:\n");
for (int i = 0; i < n; i++) {
if (s[i].marks > avg)
printf("%s\n", s[i].name);
}
printf("Below average:\n");
for (int i = 0; i < n; i++) {
if (s[i].marks < avg)
printf("%s\n", s[i].name);
}
return 0;
}
Q6. Structured vs OOP
Structured programming uses top-down approach, OOP uses bottom-up. Examples: C (structured), C++
(OOP).
Solved Questions (1 to 10)
Structured vs OOP:
- Focus on procedures vs objects
- Functions separate from data vs encapsulated in class
- No inheritance vs inheritance supported
Q7. Bookshop Inventory Management
C++ program using class to manage book inventory, search, and buy books.
// Full C++ code from earlier response (shortened here)
Q8. Friend Function
Friend function example demonstrating access to private members.
// Full C++ friend function example code from earlier response
Q9. Bank System with Inheritance
Program demonstrating use of base class Bank and derived class Savings.
// Full C++ Bank System example code
Q10. Polymorphism and Templates
Solved Questions (1 to 10)
(i) Example of runtime polymorphism using virtual functions.
(ii) Template to find minimum of two values.
(iii) Template for matrix input/output.
// Full C++ polymorphism and template code examples