PL Practice Questions
PL Practice Questions
1. Input details of books (title, author, ISBN, price, and status: issued/available).
2. Allow the user to search for a book by ISBN.
3. Display book details, including its availability status, if found.
CT Pillars Explanation:
1. Decomposition:
Break the problem into smaller tasks:
● Input book details.
● Search for a book by ISBN.
● Display the result.
1. Pattern Recognition:
● Common structure for all books (title, author, ISBN, etc.).
● Iterate over the same pattern for each book.
1. Abstraction:
Use a structure to encapsulate all attributes of a book (title, author, etc.) into a single entity.
2. Algorithm Design:
● Use loops to input and search for books.
● Use conditional statements to handle search results.
#include <stdio.h>
#include <string.h>
struct Book {
char title[100];
char author[50];
char ISBN[20];
float price;
int isIssued;
};
if (strcmp(books[i].ISBN, isbn) == 0) {
int main() {
int n;
scanf("%d", &n);
struct Book books[n];
printf("Title: ");
printf("Author: ");
printf("ISBN: ");
printf("Price: ");
scanf("%f", &books[i].price);
scanf("%d", &books[i].isIssued);
char searchISBN[20];
if (index != -1) {
printf("\nBook Found:\n");
} else {
return 0;
CT Pillars Explanation:
1. Decomposition:
Break the problem into smaller steps:
● Input employee data.
● Calculate the average salary.
● Find the employee with the highest salary.
1. Pattern Recognition:
● All employees have the same attributes (name, ID, salary).
● Iterate over the same pattern for multiple employees.
1. Abstraction:
Use a structure to represent employee attributes.
2. Algorithm Design:
● Use loops to input and process data.
● Use a function to calculate the highest salary.
#include <stdio.h>
#include <string.h>
struct Employee {
int id;
char name[50];
float salary;
};
float total = 0;
total += employees[i].salary;
return total / n;
int index = 0;
index = i;
return index;
int main() {
int n;
scanf("%d", &n);
printf("ID: ");
scanf("%d", &employees[i].id);
printf("Name: ");
printf("Salary: ");
scanf("%f", &employees[i].salary);
return 0;
Decomposition Tasks split into input, average calculation, and finding the highest
salary.
Pattern All employees follow the same structure and processing logic.
Recognition
ATM Simulation
1. Allow the user to perform operations like balance inquiry, cash
withdrawal, cash deposit, and exit.
2. Use a menu-driven program with a switch-case statement.
Voting System
Problem Statement:
Write a program to count votes for three candidates:
1. Input votes for candidates A, B, and C.
2. Count and display the total votes for each candidate.
3. Determine and display the winner.
To assess the risk of diabetes based on age and BMI (Body Mass Index).
The categories are:
● Low Risk (BMI < 25, Age < 45)
● Medium Risk (BMI between 25 and 30, Age between 45 and 60)
● High Risk (BMI > 30, Age > 60)
● Input: Age and BMI.
● Output: Risk category.
Temperature Converter
Problem Statement:
Write a program to convert temperatures between Celsius, Fahrenheit,
and Kelvin. The program should:
● Take input for the temperature value and the unit (Celsius,
Fahrenheit, or Kelvin).
● Convert the temperature to the other two units.
● Display the converted temperatures.