Logic Exercises
Logic Exercises
Logic Exercises
LAB EXERCISES
1. Design a program that determines if the supply letter is a vowel or a
consonant. Your program must be able to accept either uppercase or
lowercase letters.
2. Create a program that will accept three unique integers and print the
highest integer.
3. Create a program that will accept three unique integers and display the
numbers in ascending order.
4. Write a program that accepts three numbers. If there are equal
numbers, print the product of the equal numbers, otherwise print the
average of the three numbers.
5. Write an if-else statement that outputs the word Passed provided the
value of his exam is greater than or equal to 60 and the number of
programs done is greater than or equal to 10. Otherwise, the if-else
statement outputs the word Failed.
6. A college student who registers for 21 units or more is considered a
fulltime student. The tuition fee is 10,000.a part time student is
charged 300 per unit for tuition. Given the number of units a student is
registering calculate and print his tuition fee based on the basis of the
given criteria.
7. An employees weekly working hours is 40. If an employee exceeds 40
hours, it is considered overtime. Create a program that will accept the
number of hours worked by employee and his/her hourly rate and print
the gross pay and overtime pay rendered, if theres no OT pay to print,
print only the gross pay. To compute for the gross pay of an employee,
multiply the number of hours worked by his/her hourly rate plus his/her
OT pay. The overtime hours rendered should be computed by using
1.50% of his hourly rate.
8. Mary Kettleson wants a program that calculates and displays her
annual bonus, given her annual sales amount. Many receives a 20%
bonus when her annual sales are at least $15,000; otherwise she
receives a 1.5% bonus.
9. Create a program that will determine the toll charge given the
following formula:
Toll charge = vehicle type * kms(based on ticket type)
Vehicle ID Vehicle Type
Charge/km Ticket Type Kms
1
Car
P .50
1
10 kms
2
Light Truck
P.75
2
20 kms
3
bus
P1.00
3
30 kms
4
heavy truck
P5.00
10.
Mr. Jacoby teaches Math at Kindlon High School. He wants a
program that displays a message based on a letter grade he enters.
The valid letter grades and their corresponding messages are shown
below. If the letter grade is not valid, the program should display
Invalid grade.
Letter Grade
Message
A or a
Excellent
B or b
Above Average
C or c
Average
D or d
Below Average
11.
A program should display the message Great Score when a
students test score is at least 90. When the test score is 70 through
89, the program should display the message Good Score!. When the
test score is 0 through 69, the program should display Retake the
test. Note that the perfect score is 100. For all other test scores,
display Invalid test score.
12.
The sales manager at Alden Company wants a program that
displays a price based on a product ID she enters. The valid product
IDs and their corresponding prices are shown below. If the product ID is
not valid, print Invalid Product ID. Message.
Product ID
Price
1
50.55
2
12.35
3
11.46
4
87.95
5
71.64
6
102.33
13.
Create a program that will compute the real estate tax, given the
following formulas:
a. If value of real estate is less than 250, 001.00, tax is 5% of the
real estate value.
b. If value of real estate is between 250, 001.00 to 500,000.00, tax
is 10% of the real estate value.
c. If more than 500,000.00 tax is 15 % of the real estate value.
14.
Professor wants a program that allows him to enter a students
project and test scores. The professor assigns three projects and two
tests. Each project is worth 50 points, and each test is worth 100
points. The program should calculate and display the total points the
student earned on the projects and tests. It should also display the
student grade based on the total points earned. Shown below is the
grading scale that Professor Chang uses when assigning grades.
Total Points Earned
315-350
280-314
245-279
210-244
Below 210
Grade
A
B
C
D
F
Sample Output:
Project and test scores: 45, 40, 41, 96, 89
Total Points earned: 311, B
15.
Write a program that displays Illinois when the state code is 1,
Kentucky when the state code is 2, New Hampshire when its 3,
Vermont, when its 4, and Massachusetts when its 5. If the state
code is not 1 through 5, the program should display the message
Unknown State message.
16.
Write a program that reads in the taxpayers net income and
computes the state income tax due on his net income. The program
computes tax according to the following rate schedule:
a. No tax is paid on the first 15,000 of net income.
b. A tax of 5% is assessed on each dollar of net income from
$15,001 to $25,000.
c. A tax of 12% is assessed on each dollar of net income over
$25,000.
17.
Employees of ABC Electric Corp. are given raise as follows.
Salesperson(15%), Linemen(10%), Engineers(8%). Write a program
that reads in the current weekly salary and then calculate the
employees new weekly salary based on their job category.
18.
Write a program that computes and assesses the TF of student in
one trimester based on the given mode of payment below.
Plan(key)
Discount or Interest
Cash(1)
10% Discount
Two Installments(2)
5% Discount
Three Installments(3)
5% Interest
19.
Implement the following decision table using the nested-if
statement. Assume that point average is within the range 0.0 through
4.0
Grade Point Average
Transcript Message
0.0 0.99
Failed Semester
1.0 - 1.99
On Probation
2.0 2.99
(No Message)
3.0 3.99
Deans List for Semester
4.0 4.99
Highest Honors for Semester
20.
Implement the following decision table using a multiplealternative statement. Assume that wind speed is given as integer.
Wind Speed ( mph)
category
Below 25
Not a strong wind
25 38
Strong Wind
39 54
Gale
55 72
Whole Gale
Above 72
Hurricane
21.
Jennifer Yardley is the owner of Golf Pro, a US company that sells
golf equipment both domestically and abroad. She wants a program