100% found this document useful (1 vote)
203 views

Tutorial Sheet 3

The document provides 20 examples of pseudocode problems involving basic mathematical and logical operations like calculating averages, factorials, sums, etc. It asks the reader to write pseudocode to solve each problem, including taking user input, performing calculations, and outputting results. Various variables, formulas, and error checking are also discussed for some of the problems.
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
100% found this document useful (1 vote)
203 views

Tutorial Sheet 3

The document provides 20 examples of pseudocode problems involving basic mathematical and logical operations like calculating averages, factorials, sums, etc. It asks the reader to write pseudocode to solve each problem, including taking user input, performing calculations, and outputting results. Various variables, formulas, and error checking are also discussed for some of the problems.
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/ 10

1.

Write pseudocode for each example (a through e) making sure your pseudocode
is structured but accomplishes the same tasks as the flowchart segment.
a.

b.
c.
d.
e.

2. What is output by each of the pseudocode segments in the Figure below?


3. Design the logic for a program that outputs every number from 1 through
20.

4. Design the logic for a program that outputs every number from 1 through
20 along with its value doubled and tripled.
5. Design the logic for a program that outputs every even number from 2
through 100. 5. Design the logic for a program that outputs numbers in
reverse order from 25 down to 0.
6. Design the logic for a program that allows a user to enter a number.
Display the sum of every number from 1 through the entered number.
7. Prompt for and input a saleswoman’s sales for the month (in dollars) and
her commission rate (as a percentage). Output her commission for that
month. Note that you will need to convert the percentage to a decimal.
You will need the following variables:
SalesAmount CommissionRate CommissionedEarne You will need the
following formula: CommissionedEarned = SalesAmount *
(CommissionRate/100)

8. The manager of the Super Supermarket would like to be able to compare


the unit price for products sold there. To do this, the program should input
the name and price of an item per pound and its weights in pounds and
ounces. Then it should determine and display the unit price (the price per
ounce) of that item and the total cost of the amount purchased. You will
need the following variables:

ItemName Pounds Ounces


PoundPrice TotalPrice UnitPrice
You will need the following formulas:
UnitPrice = PoundPrice/16 TotalPrice = PoundPrice * (Pounds +
Ounces/16)

9. The owners of the Super Supermarket would like to have a program that
computes the monthly gross pay of their employees as well as the
employee’s net pay. The input for this program is an employee ID number,
hourly rate of pay, and the number of regular and overtime hours worked.
Gross pay is the sum of the wages earned from regular hours and overtime
hours; overtime is paid at 1.5 times the regular rate. Net pay is gross pay
minus deductions. Assume that deductions are taken for tax withholding
(30 percent of gross pay) and parking ($10 per month). You will need the
following variables:

EmployeeID HourlyRate RegHours OvertimeHours


GrossPay Tax Parking NetPay

You will need the following formulas:


GrossPay = (RegularHours * HourlyRate) + (OvertimeHours *
(HourlyRate *1.5)) NetPay = GrossPay – (GrossPay * Tax) – Parking

10 Shannon and Jasmine bowl as a tem. Each of them bowls three grames
in a tournament. They would like to know their individual averages for
their three games and the team average. Allow the user to input the
scores for each player. Output Shannon’s average, Jasmine’s average,
and the team’s average. You will need the following variables:

Score1 Score2 Score3 avgjasmine SumShannon


sumJasmine avgShannon teamAvg
You will need the following formula:
teamAvg = (avgShannon + avgJasmin)/2

10. Kim wants to buy a car. Help Kim compute the monthly payment on a
loan, given the loan amount, the annual percentage rate of interest, and
the number of montly payments. The program should allow Kim to input
the loan amount, the interest rate, and how many payments she wants to
make. It should then compute and display the monthly payment.

You will need the following variables:


Payment
MonthlyRate
LoanAmt
NumberMonths
InterestRate

You will need the following formulas:


MonthlyRate = InterestRate /1200

Note: when the user enters InterestRate as a percentage, it must be


divided by 100 to make it a decimal (i.e., 18% = 18/100 = 0.18). The
InterestRate offered by car dealers is an annual rate so this must be
divided by 12 to get the
MonthlyRate. The formula given above combines the two steps (i.e.,
annual rate of 18% = 18/100 =0.18 and then the monthly rate is
0.18/12 = 0.015 or 18/(100*12) = 18/1200.
Payment = LoanAmt * MonthlyRate * (1 + MontlyRate)^NumberMonths
/ ((1 + MonthlyRate)^NumberMonths -1)

NOTE: The formula must be entered carefully, exactly as shown.

11. Input a number entered by the user and display “Positive” if it is greater
than zero, “Negative” if it is less than zero, and “Zero” if it is equal to zero.
12. Develop a menu-driven program that inputs two numbers and, at the
user’s option, finds their sum, difference, product, or quotient.
13. Input a number (X) and create a program that allows the user to select
finding the area (Area) of one of the following:

a. The area of a square with side X, Area = X * X


b. The area of a circle with radius X, Area = 3.14 * X^2
c. The area of an equilateral triangle with side X, Area = Sqrt(3)/4 * X
^2

Note: Because X represents a dimension, we require that X > 0. Be


sure to include this requirement in your program.

14. Consider the equation Ax2 + B = 0.


If B/A < 0, this equation has two solutions. The solutions are:
o X1 = Sqrt(-B/A)
o X2 = -Sqrt(-
B/A)
• If B/A = 0, this equation has one solution which is X = 0
• If B/A > 0, this equation has no real number solutions
Write a program to have the user input any number for the coefficients,
A and B, for this equation, If A=0, terminate the program. Otherwise,
solve the equation.

15. Compute the income tax due on taxable income entered by the user,
given the data as shown in the following table. Be sure to include error
checking to make sure the user does not enter a negative number. Assume
all entries are integer values.

Taxable Income Tax Due

From To
$0 $49,999 $0 + 5% of amount over $0
$50,000 $99,999 $2,500 + 7% of amount over
$50,000
$100,000 …. $6,000 + 9% of amount over
$100,000

16. Write a program that allows the user to input a total dollar amount for
an online shopping order and computes and outputs the shipping cost
based on the following schedule:

Order Total Ship within USA Ship to Canada


Less than $50.00 $6.00 $8.00
$50.01 - $100.00 $9.00 $12.00
$100.01 - $150.00 $12.00 $15.00
Over $150.00 Free Free

17. Write a program that allows the user to enter his or her name. The
program should out put a username for entry into a website. The user
should be prompted to enter a first name, middle initial, and last name. If
the user does not have a middle initial, the entry should be “none”. In this
case, the output will be a username that concatenates the first and last
names with a dot between them. If the user has a middle initial, the output
username should be in form first.middle_initial.last. For example, a user
whose name is Harold Nguyen
would have Harold.Nguyen for his username and a user whose name is
Maria Anna Lopez would have Maria.A.Lopez for a username.

18. Find the sum of the squares of the integers from 1 to MySquare, where
MySquare is input by the user. Be sure to check that the user enters a
positive integer.

19. Input a list of people’s ages from the user (terminated by 0) and find
the average age. Be sure to check that the user enters only positive
numbers.

20. The number N factorial, denoted by N!, is defined to be the product of


the first N positive integers:

N! = 1 X 2 X 3 X …. X N

For example:
5! = 1 X 2 X 3 X 4 X 5 = 120
7! = 1 X 2 X 3 X 4 X 5 X 6 X 7 = 5,040

Find N!, where N is a positive integer input by the user. (Hint: Initialize
a Product to 1 and user a loop to multiply that product by successive
integers.) Be sure to check that the user enters a positive integer.

You might also like