Use case based programming exercises
📝 Use‑Case based exercises for programmers
1. Café Billing System
- Scenario: A cafĂ© sells coffee at ₹120 per cup and tea at ₹80 per cup.
- Task: Write a program that asks the customer how many coffees and teas they ordered, then prints the total bill.
- Hint: Identify variables for quantities, unit prices, and total amount. Use arithmetic operators.
2. Student Result Checker
- Scenario: A student’s exam score is entered.
- Task: Print “Pass” if marks ≥ 50, otherwise “Fail”.
- Hint: Use relational operators and an
if-elsestatement.
3. Traffic Signal Decision
- Scenario: A traffic light shows either Red, Yellow, or Green.
- Task: Based on the input, print “Stop”, “Get Ready”, or “Go”.
- Hint: Use conditional statements (
if-elseorswitch).
4. Discount Eligibility
- Scenario: A shop gives a 10% discount if the purchase amount is more than ₹1000.
- Task: Ask the user for purchase amount and print final price after discount if eligible.
- Hint: Use relational operators and arithmetic.
5. Even Numbers Printer
- Scenario: A teacher wants to display all even numbers between 1 and 20.
- Task: Write a program using a loop to print them.
- Hint: Use
forloop and modulus operator%.
6. Multiplication Table Generator
- Scenario: A student wants to learn multiplication tables.
- Task: Ask for a number and print its table up to 10.
- Hint: Use
forloop and multiplication.
7. Voting Eligibility
- Scenario: Government portal checks if a person can vote.
- Task: Input age, print “Eligible” if age ≥ 18, else “Not Eligible”.
- Hint: Use conditional statements.
8. Largest of Three Numbers
- Scenario: A math quiz asks the student to find the largest of three given numbers.
- Task: Write a program to print the largest number.
- Hint: Use nested
if-else.
9. Simple Login System
- Scenario: A system checks username and password.
- Task: If both match predefined values, print “Login Successful”, else “Access Denied”.
- Hint: Use logical operators (
&&) and conditional statements.
10. Sum of First N Natural Numbers
- Scenario: A student wants to calculate the sum of first N numbers.
- Task: Input N and print the sum.
- Hint: Use a loop and accumulator variable.
11. Library Fine Calculator
- Scenario: A library charges ₹2 per day for late returns.
- Task: Input the number of days late and calculate the fine. If fine > ₹50, print “Membership Suspended”.
- Hint: Variables → daysLate, fine. Use arithmetic + conditional.
12. Temperature Converter
- Scenario: A weather app needs to convert Celsius to Fahrenheit.
- Task: Input temperature in Celsius and print Fahrenheit. Formula:
F = (C * 9/5) + 32. - Hint: Variables → celsius, fahrenheit. Use arithmetic.
13. Bus Ticket Booking
- Scenario: A bus ticket costs ₹500. If passenger age < 12, they get 50% discount.
- Task: Input age and print ticket price.
- Hint: Variables → age, price. Use conditional.
14. Bank Interest Calculator
- Scenario: A bank gives 5% annual interest.
- Task: Input principal and years, calculate final amount. Formula:
Amount = Principal + (Principal * Rate * Years) / 100. - Hint: Variables → principal, years, amount. Use arithmetic.
15. Odd Number Printer
- Scenario: A math teacher wants all odd numbers between 1 and 30.
- Task: Write a program using a loop to print them.
- Hint: Use
forloop and%operator.
16. Grade Point Average (GPA) Calculator
- Scenario: A student has marks in 5 subjects.
- Task: Input marks, calculate average, and print grade (A/B/C/F).
- Hint: Variables → marks[], average. Use loop + conditional.
17. Simple ATM Withdrawal
- Scenario: ATM allows withdrawal only if balance ≥ amount.
- Task: Input balance and withdrawal amount. Print “Transaction Successful” or “Insufficient Balance”.
- Hint: Variables → balance, withdrawAmount. Use conditional.
18. Electricity Bill Calculator
- Scenario: Electricity board charges ₹5 per unit. If units > 100, extra surcharge of ₹200.
- Task: Input units consumed and print bill.
- Hint: Variables → units, bill. Use arithmetic + conditional.
19. Palindrome Checker
- Scenario: A word is palindrome if it reads same forward and backward.
- Task: Input a string and check if it’s palindrome.
- Hint: Variables → word, reversedWord. Use loop/string methods + conditional.
20. Simple Quiz Game
- Scenario: A quiz asks 3 questions. Each correct answer gives 10 points.
- Task: Input answers, calculate score, and print result.
- Hint: Variables → score, answer. Use conditional + loop.
21. Cinema Ticket Counter
- Scenario: A cinema charges ₹250 per ticket. If more than 5 tickets are booked, give 20% discount.
- Task: Input number of tickets and print total cost.
22. Water Bill Calculator
- Scenario: Water board charges ₹10 per unit. If usage > 500 units, add ₹1000 surcharge.
- Task: Input units and print bill.
23. BMI Calculator
- Scenario: Health app calculates BMI = weight / (height * height).
- Task: Input weight (kg) and height (m), print BMI and category (Underweight/Normal/Overweight).
24. Taxi Fare Estimator
- Scenario: Taxi charges ₹50 base fare + ₹20 per km.
- Task: Input distance and print fare.
25. Leap Year Checker
- Scenario: Calendar app checks if a year is leap year.
- Task: Input year, print “Leap Year” or “Not Leap Year”.
26. Simple Calculator
- Scenario: User enters two numbers and an operator (+, -, *, /).
- Task: Perform operation and print result.
27. Hotel Room Booking
- Scenario: Hotel charges ₹2000 per night. If stay ≥ 7 nights, give 1 night free.
- Task: Input nights and print total cost.
28. Speed Limit Checker
- Scenario: Road speed limit is 60 km/h.
- Task: Input speed, print “Over Speeding” if > 60, else “Safe Driving”.
29. Currency Converter
- Scenario: Convert USD to INR (1 USD = ₹83).
- Task: Input USD amount and print INR.
30. Parking Lot Fee
- Scenario: Parking charges ₹30 per hour. If parked > 5 hours, flat ₹200.
- Task: Input hours and print fee.
31. Factorial Calculator
- Scenario: Math app calculates factorial of a number.
- Task: Input N and print factorial using loop.
32. Prime Number Checker
- Scenario: Teacher wants to check if a number is prime.
- Task: Input number, print “Prime” or “Not Prime”.
33. Shopping Cart Total
- Scenario: A cart has 3 items with given prices.
- Task: Input quantities, calculate total bill.
34. Attendance Percentage
- Scenario: College requires 75% attendance.
- Task: Input total classes and attended classes, print percentage and eligibility.
35. Simple Interest Calculator
- Scenario: Formula: SI = (P * R * T) / 100.
- Task: Input principal, rate, time, print interest.
36. Reverse Number
- Scenario: A puzzle asks to reverse digits of a number.
- Task: Input number, print reversed number.
37. Armstrong Number Checker
- Scenario: A number is Armstrong if sum of cubes of digits = number.
- Task: Input number, check Armstrong.
38. Grade Distribution
- Scenario: School wants to classify marks: ≥90 A, ≥75 B, ≥50 C, else F.
- Task: Input marks and print grade.
39. Restaurant Bill Splitter
- Scenario: Friends share bill equally.
- Task: Input total bill and number of friends, print share per person.
40. Fibonacci Series Generator
- Scenario: Math app prints first N Fibonacci numbers.
- Task: Input N and print series.
41. Online Shopping Cart with Discount Codes
- Scenario: An e‑commerce site allows customers to add 5 items to their cart. If the total exceeds ₹5000, apply a 15% discount. If a promo code
"SAVE100"is entered, subtract ₹100 additionally. - Task: Input prices of 5 items and optional promo code, then print final bill.
- Concepts: Arrays, loops, conditionals, string comparison.
42. Student Marks Analyzer
- Scenario: A class has 10 students. Each student’s marks are entered. The program should calculate:
- Highest marks
- Lowest marks
- Average marks
- Task: Input marks into an array and print results.
- Concepts: Arrays, loops, min/max logic, arithmetic.
43. Bank Transaction System
- Scenario: A bank account starts with ₹10,000. User can perform multiple transactions (deposit or withdraw). If withdrawal > balance, print “Insufficient Funds”. After all transactions, print final balance.
- Task: Input number of transactions, then process each one.
- Concepts: Loops, conditionals, running totals.
44. Word Frequency Counter
- Scenario: A text analyzer counts how many times each word appears in a sentence.
- Task: Input a sentence, split into words, and print frequency of each word.
- Concepts: Strings, arrays, loops, conditionals.
45. Simple Library Management
- Scenario: A library has 5 books stored in an array. User can:
- Search for a book by title
- Borrow a book (mark as unavailable)
- Return a book (mark as available)
- Task: Implement menu‑driven program for these actions.
- Concepts: Arrays, strings, loops, conditionals, menu system.
46. Salary Slip Generator
- Scenario: A company pays a basic salary. If HRA = 20% of basic and DA = 10% of basic, calculate gross salary. If gross > ₹50,000, deduct 10% tax.
- Task: Input basic salary, calculate gross and net salary.
- Concepts: Arithmetic, conditionals, multiple variables.
47. Number Guessing Game
- Scenario: System has a secret number (say 25). User keeps guessing until correct. Print “Too High” or “Too Low” until match.
- Task: Implement guessing loop until correct number is entered.
- Concepts: Loops, conditionals, user input validation.
48. Simple Banking PIN Check
- Scenario: ATM allows 3 attempts to enter correct PIN. If correct, print “Access Granted”, else “Card Blocked”.
- Task: Input PIN attempts, check validity.
- Concepts: Loops, conditionals, counters.
49. Restaurant Order System
- Scenario: A restaurant menu has 3 items:
- 1 → Pizza ₹300
- 2 → Burger ₹150
- 3 → Juice ₹80
- Task: User selects item number and quantity, program prints bill.
- Concepts: Switch case, arithmetic, conditionals.
- 1 → Pizza ₹300
- 2 → Burger ₹150
- 3 → Juice ₹80
50. Loan Eligibility Checker
- Scenario: Bank checks loan eligibility:
- Age ≥ 21
- Salary ≥ ₹25,000
- No existing loan (boolean flag)
- Task: Input age, salary, loan status. Print “Eligible” or “Not Eligible”.
- Concepts: Relational + logical operators, conditionals.
- Age ≥ 21
- Salary ≥ ₹25,000
- No existing loan (boolean flag)
Comments
Post a Comment