0% found this document useful (0 votes)
16 views13 pages

PL Practice Questions

Uploaded by

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

PL Practice Questions

Uploaded by

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

Problem Statement: Library Book Management

Goal: Create a program to manage books in a library using structures.

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;

};

int searchByISBN(struct Book books[], int n, char isbn[]) {

for (int i = 0; i < n; i++) {

if (strcmp(books[i].ISBN, isbn) == 0) {

return i; // Return the index of the book if found

return -1; // Return -1 if not found

int main() {

int n;

printf("Enter the number of books: ");

scanf("%d", &n);
struct Book books[n];

for (int i = 0; i < n; i++) {

printf("\nEnter details for book %d:\n", i + 1);

printf("Title: ");

scanf(" %[^\n]", books[i].title);

printf("Author: ");

scanf(" %[^\n]", books[i].author);

printf("ISBN: ");

scanf(" %[^\n]", books[i].ISBN);

printf("Price: ");

scanf("%f", &books[i].price);

printf("Is the book issued? (1 for Yes, 0 for No): ");

scanf("%d", &books[i].isIssued);

char searchISBN[20];

printf("\nEnter ISBN to search for a book: ");

scanf(" %[^\n]", searchISBN);

int index = searchByISBN(books, n, searchISBN);

if (index != -1) {

printf("\nBook Found:\n");

printf("Title: %s\n", books[index].title);

printf("Author: %s\n", books[index].author);

printf("ISBN: %s\n", books[index].ISBN);

printf("Price: %.2f\n", books[index].price);

printf("Status: %s\n", books[index].isIssued ? "Issued" : "Available");

} else {

printf("\nBook not found.\n");

return 0;

Mapping CT Pillars to Code

CT Pillar Application in Code

Separated tasks into input, search, and


Decomposition
display functionalities.

Used a loop to handle similar data structures


Pattern Recognition
(books).

Represented each book with a structure


Abstraction
containing all attributes.
Implemented search functionality with a
Algorithm Design
loop and strcmp to compare ISBN values.

Problem Statement 2: Employee Management System

Goal: Write a program to manage employee data using structures.

1. Input employee details (name, ID, and salary).


2. Calculate and display the average salary.
3. Find the employee with the highest salary.

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 calculateAverageSalary(struct Employee employees[], int n) {

float total = 0;

for (int i = 0; i < n; i++) {

total += employees[i].salary;

return total / n;

int findHighestSalary(struct Employee employees[], int n) {

int index = 0;

for (int i = 1; i < n; i++) {


if (employees[i].salary > employees[index].salary) {

index = i;

return index;

int main() {

int n;

printf("Enter the number of employees: ");

scanf("%d", &n);

struct Employee employees[n];

for (int i = 0; i < n; i++) {

printf("\nEnter details for employee %d:\n", i + 1);

printf("ID: ");

scanf("%d", &employees[i].id);

printf("Name: ");

scanf(" %[^\n]", employees[i].name);

printf("Salary: ");

scanf("%f", &employees[i].salary);

float averageSalary = calculateAverageSalary(employees, n);

printf("\nAverage Salary: %.2f\n", averageSalary);

int highestIndex = findHighestSalary(employees, n);

printf("\nEmployee with the highest salary:\n");

printf("ID: %d\n", employees[highestIndex].id);

printf("Name: %s\n", employees[highestIndex].name);

printf("Salary: %.2f\n", employees[highestIndex].salary);

return 0;

Mapping CT Pillars to Code

CT Pillar Application in Code

Decomposition Tasks split into input, average calculation, and finding the highest
salary.

Pattern All employees follow the same structure and processing logic.
Recognition

Abstraction Used structures to encapsulate employee attributes.


Algorithm Design Designed functions for calculating the average and finding the highest
salary.

Election Voting System


Problem Statement:

Design a program for an election voting system to manage voter registration,


candidate voting, and result calculation.

Student Grades Management System


Goal: Create a C program to manage student grades.
● Input: Accept input for student names and grades.
● Output: Calculate and display the average, highest, and lowest
grades.

Character Frequency Counter


Goal: Write a C program to count the frequency of each character in a
string.
● Input: A string entered by the user (e.g., "hello world").
● Output: Display the frequency of each character in the string.

Electricity Bill Calculator


Write a C program to calculate the electricity bill based on the number of
units consumed using a given billing structure.

To Calculate the Areas of Different Shapes


Goal: To calculate the areas of a circle, rectangle, and triangle using
proper C concept for each shape.

Manage Student Details and Calculate Average Marks


to input data for students, calculate their average marks, and display
details of those with average marks above 75.

Employee Salary Management


1. Input details of 5 employees (name, ID, basic salary, and bonus).
2. Calculate gross salary as basic + bonus for each employee.
3. Display details of employees with a gross salary above $5000.

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.

Grocery Store Billing System


1. Allow the user to input purchased items (name, quantity, price).
2. Calculate the total bill amount.
3. Display the bill summary.

Student Attendance Tracker


1. Input attendance details of students (name and number of classes
attended).
2. Calculate attendance percentage.
3. Display whether a student is eligible to sit for exams (attendance
>= 75%).

Parking Lot Management


1. Keep track of cars parked in a parking lot (entry and exit).
2. Handle the given below operations:
a. Car enters.
b. Car exits.
c. Display available slots.

Inventory Management System


1. Add items (name, quantity, price).
2. Update stock when an item is sold.
3. Display current stock.

Restaurant Order System


1. Display a menu of items with prices.
2. Allow customers to place orders by item number and quantity.
3. Calculate and display the total bill.

Traffic Light Simulation


1. Input a color (red, yellow, green).
2. Display the corresponding action (stop, ready, go)

Employee Payroll Management


1. Input basic salary, HRA, and allowances.
2. Calculate gross salary as: gross = basic + HRA + allowances.
3. Deduct a fixed tax percentage and display the net salary

Hospital Management: Patient Records


1. Input patient details (name, age, diagnosis).
2. Search for a patient by name.
3. Display patient details if found.

Vehicle Fuel Efficiency Calculator


1. Input distance traveled and fuel used.
2. Calculate and display efficiency as: efficiency = distance / fuel.

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.

Heart Rate Monitor


To check if a person's heart rate is normal, fast, or slow based on the
number of beats per minute.
● Input: Heart rate (beats per minute).
● Output: Heart rate status (Normal, Fast, or Slow).
Inventory Management: Stock Checker
to manage the inventory of items. The program should check if an item
is in stock or out of stock based on its quantity.
● Input: Item name, stock quantity, required quantity.
● Output: Stock availability message.

E-commerce Domain: Discount Calculator


Problem Statement:

to calculate the discount on a product based on the price and discount


rate.
● Input: Price of the product, discount rate.
● Output: Discount amount, final price.
Student Performance Analysis
Problem Statement:

to calculate the average marks of a student and determine their grade.

● Input: Marks of subjects (Math, English, Science).


● Output: Average marks and grade.

Invoice Generation System


Problem Statement:
to generate an invoice for purchased items. The program should:
● Input the number of items purchased.
● For each item, input the item name, quantity, and price.
● Display the total cost of the items and the overall invoice.

Diabetes Risk Assessment Based on Age and BMI


Problem Statement:

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.

Calorie Intake Tracker


Problem Statement:

to track the daily calorie intake and classify the intake


to track the daily calorie intake and classify the intake as:
● Low (Less than 1500 calories)
● Moderate (1500 to 2500 calories)
● High (More than 2500 calories)
● Input: Total daily calorie intake.
● Output: Calorie intake category.

Loan Eligibility Checker


Problem Statement:

Write a program to check loan eligibility based on a user's input. The


program should check the following conditions:
● The applicant must be at least 21 years old.
● The applicant must have a minimum monthly income of $2000.
● The applicant must not have a bad credit history.

Bank Statement Generator


Problem Statement:
Write a program to generate a bank statement with transaction details.
The program should allow deposit, withdrawal, and print balance after
each transaction.
● Input: Transaction type (deposit/withdrawal), amount.
● Output: Updated balance after each transaction.

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.

Library Fine Calculation System


Problem Statement:
Design a system that calculates fines for overdue books in a library. The
program should:
● Input the number of days a book is overdue.
● Calculate a fine of Rs.10 per day for overdue books.
● Display the total fine for the overdue book.

Online Exam System


Design a program for an online exam system that allows users to attempt
a test and get a result. The program should:
● Input questions and multiple choice answers.
● Allow users to select answers and calculate the score.
● Display the user’s score after completing the test.
Restaurant Ordering System
Problem Statement:
Design a program for a restaurant to manage orders. The program
should:
● Input the details of the ordered items (name, quantity, price).
● Calculate the total cost of the order.
● Display the order summary and total cost.

Employee Attendance System


Problem Statement:
Design a program to manage employee attendance. The program should:
● Input the attendance for each employee (ID and days present).
● Calculate the percentage of days present for each employee.
● Display employee details along with the percentage of attendance

Bus Ticket Reservation System


Problem Statement:
Create a bus ticket reservation system where the user can:
● Input details about the trip (departure, destination, price).
● Reserve a seat on the bus.
● Display the reservation details.

Movie Ticket Booking System


Problem Statement:
Create a movie ticket booking system where the user can:
● Input movie details (name, show time, price per ticket).
● Input the number of tickets to be booked.
● Calculate and display the total cost of the tickets.

E-commerce Cart System


Problem Statement:
Design a program for an e-commerce platform to manage a
shopping cart. The program should:
Input the item details (item name, price, quantity) for each product
added to the cart.
Calculate the total cost of the cart.
Apply a discount (if applicable) and display the final amount.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy