PF Week 3 EX
PF Week 3 EX
Question: Write a program that takes a number as input and checks if it’s positive, negative, or zero.
Display a message for each case.
Solution:
#include <iostream>
int main() {
int number;
if (number > 0) {
} else {
return 0;
Question: Write a program that takes three numbers as input and finds the largest of the three using if-
else statements.
Solution:
#include <iostream>
int main() {
int a, b, c;
cout << "The largest number is: " << a << endl;
cout << "The largest number is: " << b << endl;
} else {
cout << "The largest number is: " << c << endl;
return 0;
Question: Write a program that asks for a student's score and assigns a grade based on the following
criteria:
80 to 89: Grade B
70 to 79: Grade C
60 to 69: Grade D
Solution:
#include <iostream>
int main() {
int score;
cout << "Enter your score: ";
} else {
return 0;
Question: Write a program that takes two numbers and performs addition, subtraction, multiplication,
or division based on user choice using a switch statement.
Solution:
#include <iostream>
int main() {
int choice;
switch (choice) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
if (num2 != 0) {
} else {
break;
default:
return 0;
Solution:
#include <iostream>
int main() {
int year;
} else {
cout << year << " is not a leap year." << endl;
return 0;
}
programs questions for Week 3 concepts, focusing on decision control structures:
1. Positive or Negative: Write a program that checks if a given number is positive, negative, or zero.
2. Even or Odd: Create a program that takes a number as input and determines if it is even or odd.
3. Largest of Three Numbers: Write a program that accepts three numbers and displays the largest
among them.
4. Grade Calculator: Create a program that assigns a grade (A, B, C, D, or F) based on a student's score.
5. Leap Year Checker: Write a program that checks if a given year is a leap year.
6. Voter Eligibility: Develop a program that checks if a person is eligible to vote based on their age (must
be 18 or older).
7. Simple Calculator: Write a program that performs addition, subtraction, multiplication, or division
based on the user's choice.
8. Day of the Week: Create a program that takes a number (1-7) and displays the corresponding day of
the week.
10. Number Comparison: Develop a program that accepts two numbers and displays whether they are
equal, or which one is greater.
11. Discount Calculator: Write a program that calculates a discount based on the amount spent. Apply a
10% discount if the amount is over 1000.
12. Pass or Fail: Create a program that checks if a student has passed or failed based on their score
(passing score is 50).
13. Temperature Converter: Write a program that converts a temperature from Celsius to Fahrenheit or
Fahrenheit to Celsius based on the user's choice.
14. Electricity Bill Calculator: Develop a program that calculates the total bill based on units consumed.
Charge different rates per unit based on consumption.
15. Grade Point Average (GPA): Create a program that assigns a GPA based on a student’s marks using
an `if-else if` ladder.
16. Traffic Light Simulator: Write a program that displays a message (Stop, Ready, Go) based on a traffic
light color (Red, Yellow, Green).
17. Triangle Type Checker: Develop a program that accepts the lengths of three sides and determines if
it forms an equilateral, isosceles, or scalene triangle.
18. Currency Converter: Write a program that converts a given amount from one currency to another
based on user input.
19. Number Range Checker: Create a program that checks if a number is within a specified range (for
example, between 10 and 50).
20. Password Validator: Develop a program that checks if a user-entered password matches a
predefined password and displays an appropriate message.