0% found this document useful (0 votes)
39 views2 pages

Conditional Programming Exercises

The document provides 26 programming exercises involving basic calculations, conditional statements, and formatting output. The exercises cover computing midterm grades, sums and averages, areas of shapes, unit conversions, and conditional logic to determine discounts, bonuses, grades, and temperature classifications based on input values. Learners are asked to write programs to solve the various math and conditional programming problems.

Uploaded by

Jan Earol Rasco
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)
39 views2 pages

Conditional Programming Exercises

The document provides 26 programming exercises involving basic calculations, conditional statements, and formatting output. The exercises cover computing midterm grades, sums and averages, areas of shapes, unit conversions, and conditional logic to determine discounts, bonuses, grades, and temperature classifications based on input values. Learners are asked to write programs to solve the various math and conditional programming problems.

Uploaded by

Jan Earol Rasco
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

Programming Exercises

1. Make a program that will compute for the midterm grade of a student. The midterm grade is
equal to one-third of the prelim exam and two-thirds of the midterm exam. Print the midterm
grade.
2. Construct a program that will compute and the print the sum and average of 3 numbers.
3. Create a program that will compute and display the Area of a rectangle using the formula
Area = Length x Width
4. Construct a flowchart that will convert and display an inputted number in inches (in.) to its
equivalent number in feet (ft). Hint 1 ft = 12 inches.
5. Make a program that accepts a number in kilowatts then display its equivalent in watts.
Hint: 1 watt = 0.001 kilowatt
6. Make a program that accepts a value for radius (R) and compute the corresponding area of a
circle. Print the value of the radius and the computed area. Use the formula Area = Pi x R2.
7. Create a program that accepts a number in square meter (m2) and display its equivalent number
in hectares (has). Hint: 1000 m2 = 1 ha
8. Read 2 records in a computer. The first record will contain unit price and the second record will
contain quantity. Make a program that will compute and display the amount by multiplying the
unit price and quantity.
9. Create a program that converts a Fahrenheit measure to a Celsius measure (C = 5/9 x (F-32)
10. Write a program that asks the user to enter the radius of a circle and then computes for its area.
Recall that the formula to compute for the area is AREA = Pi x R2 , where R is the radius. The
output must be similar to the one below

The area of the circle with radius 2 cm is 12.56 cm2

CONDITIONAL STATEMENT / SWITCH STATEMENT

11. Given two numbers X and Y, make a program to determine the difference between X and Y.
if X – Y is negative, compute R = X + Y; if X – Y is zero, compute R = 2X + 2Y; and if X – Y is
positive, compute R = X * Y;
12. Write a program that will determine and display the largest number among 3 numbers being
inputted.
13. Make a program that displays 3 inputted numbers in ascending order.
14. Create a program that asks for the amount purchased by the customer. If the customer
purchases more than 2,000 then a 5% discount is given. Display the net amount to be paid by
the customer and the discount.
15. Construct a program to determine the equivalent grade of each student in a class as follows:
a. Read in the student’s name, class standing, midterm grade, and the final exam
ratings.
b. Determine the final grade of the student by the formula: final grade = 0.30 of
midterm grade + 0.10 of class standing + 0.60 of final exam.
c. Determine the equivalent grade for the numerical value obtained by the following
grading marks:
98-100 = 4.00
95-97 = 3.75
92-94 = 3.50
89-91 = 3.25
86-88 = 3.00
83-85 = 2.75
80-82 = 2.50
77-79 = 2.25
74-76 = 2.00
71-73 = 1.75
68-70 = 1.50
64-67 = 1.25
60-63 = 1.00
Below 60 = 0.00
16. Write a program that finds the smallest among the five integers inputted by the user.
17. Write a program that computes the grade of a student using the formula:
Grade = 40% major exam + 30% average of 2 long exams + 30% average of 3 short quizzes.

Display the average of two long exams, average of 3 short quizzes and the grade of the student.
Display also a message whether the student passed or failed. Passing is 75%

18. Write a program that asks the user for the hours worked for the week and the hourly rate. The
basic salary is computed as:
Salary = hours worked * hourly rate

Bonuses are given:


No. of hours > 45 Bonus of 500 pesos
No. of hours > 40 and <=45 Bonus of 250 pesos
No. of hours >35 and <=40 bonus of 150 pesos

Display the basic salary, bonus and the total salary (basic salary + bonus) for the week.

19. Abena Company gives year-end bonus to its employees based on their number of years of
service and their salary, using the following:
Years of Service Bonus
1 10% of salary
2 to 5 20% of salary
6 to 10 50% of salary
11 and above 75% of salary

20. Write a program that accepts five numbers from the user and displays the highest and the
lowest number. Assume that there are no duplicate values.
21. Write a program that accepts three numbers from the user and displays the values from the
lowest to highest. Assume that there are no duplicate values.
22. Write a program that accepts three numbers from the user and displays the values from the
highest to lowest. Assume that there are no duplicate values.
23. Write a program segment that will ask the user if he/she wants to compute the perimeter of the
area of a triangle. If the perimeter is wanted, ask the measure of the three sides and compute
for the perimeter. If the area is wanted, ask for the measures of the base and height and
compute for the area. Display the computed value.
24. Write a program that will display “IT’S COLD!” if the temperature is less than 20, “IT’S HOT!” if
the temperature is greater than 30, “COOL CLIMATE!” otherwise.
25. Write a program that gives a discount of 100 pesos to a customer if the shirt bought is XL and
the price is greater than 500 pesos; a discount of 50 pesos if the shirt bought is L and the price is
greater than 400.
26. Write a program that will read a date (month, day and year) in integer form and display the date
in standard format.
Sample run:
Enter month: 9
Enter day: 24
Enter year: 1977

September 24, 1977

Common questions

Powered by AI

A program to compute both the area and perimeter of a triangle can be structured by prompting the user to choose which calculation to perform. If the perimeter is desired, request input for the three side lengths and compute the perimeter by summing these values. If the area is chosen, request the base and height measurements, then compute the area using the formula (1/2 * base * height). This structure requires clear user input instructions to select the desired calculation type and provide accurate measurements. Using a switch or conditional statement to separate these branches ensures the program is logically organized and user-friendly .

To effectively implement a conditional statement for determining the largest among three inputs, you should use a nested if-else approach. Compare the first two values; if the first is greater, compare it with the third to finalize the result. If the second is greater, compare it with the third for the largest value. Key considerations include proper variable initialization, handling inputs with equal values gracefully using additional checks, and ensuring the logic flow covers all scenarios without redundancy. Edge cases like all inputs being equal or two being equal with a third distinct value should be accounted for to ensure robustness .

To create a program that calculates the sum and average of three numbers, a functional programming approach can be used, emphasizing modularity and reusability. This can be achieved by defining separate functions: one for calculating the sum and another for calculating the average. The sum function would accept three numbers as parameters, compute their sum, and return the result. The average function would call the sum function, divide the result by three, and return the average. This structure allows for reusability, as these functions can be used independently in different parts of the program or in other programs requiring similar calculations .

A grading program can incorporate both numerical and symbolic grades by using a mapping data structure, like a dictionary, where numerical grades are keys, and symbolic grades (e.g., 'A', 'B', etc.) are the values. The program calculates the numerical final grade using defined formulas, then matches it against the key in the dictionary to retrieve and display the corresponding symbolic grade. This approach facilitates easy maintenance and updates, allowing changes in grading criteria to be made centrally within the data structure, preserving program logic and ensuring adaptability across different educational standards .

To design a program that converts kilowatts to watts, start with defining a clear input/output procedure where users input a value in kilowatts. The program will then multiply the input by 1000 (since 1 kilowatt = 1000 watts) and display the result. Unit conversion impacts software design by necessitating attention to detail in handling decimal values, ensuring precision in conversion factors, and implementing error checks for invalid inputs. Additionally, it requires designing an intuitive user interface that minimizes input errors and clearly communicates results, which is crucial for predictable program behavior .

To ensure accurate conversion from inches to feet in a flowchart design, start by outlining an input/output structure. Key components include: 1) Start symbol to mark the flowchart's beginning. 2) Input process to gather the number of inches. 3) A processing step to divide the number of inches by 12 to convert it to feet, using the formula 1 foot = 12 inches. 4) A decision symbol to check for any invalid input (e.g., negative values) and redirect to error handling if necessary. 5) An output process to display the feet value. 6) An End symbol to indicate the flowchart's completion. Clear labeling and proper sequencing improve clarity and ensure the logical flow .

Implementing a bonus calculation system based on years of service requires consideration of fairness, clarity, and consistency. The system should clearly define bonus percentages for specific year ranges and ensure they reflect organizational goals such as encouraging long-term employee retention. It should avoid potential bias by uniformly applying criteria across the workforce. This impacts employee motivation by fostering loyalty and providing tangible rewards for tenure. However, it may demotivate newer employees if not complemented by other incentives. Mitigating this requires a balanced approach, incorporating performance-based bonuses alongside tenure-based rewards to motivate all employees .

Advantages of a percentage-based grading system include clear, consistent evaluation across different assessments, allowing students to understand how each component influences their final grade. However, potential pitfalls include issues with subjective assessment weighting and students focusing disproportionately on certain aspects. These pitfalls can be mitigated by ensuring transparency in the grading criteria and providing detailed feedback. Furthermore, balancing the weighting of each assessment component (e.g., balancing exams and projects) can prevent skewness in the final evaluation .

To design a program that determines and applies a discount based on purchase value, you should use conditional statements to check the purchase conditions. The program should have logical flow such as: 1) input the purchase amount, 2) check if it exceeds 2,000 units, 3) apply a 5% discount if the condition is met, otherwise, no discount is applied. Considerations for ensuring accuracy include thorough testing for boundary conditions (e.g., exactly 2,000 units) and ensuring that the calculation of the discount and the display of net amount are performed precisely. Careful handling of floating-point arithmetic and proper user prompts are also necessary to ensure accurate results .

To find the largest among three inputted numbers, a simple comparison algorithm can be used. The algorithm compares the first number with the second and assigns the greater value to a temporary maximum variable. It then compares the current maximum with the third number and updates the maximum variable if the third number is larger. This algorithm is efficient in terms of time complexity, as it completes in constant time O(1), performing just two main comparisons regardless of input size. The simplicity of this approach ensures a low overhead, thus maintaining efficiency .

You might also like