PF Assignment 4
PF Assignment 4
b.
2. Short Questions 10
a. Write a nested loop that displays 10 rows of ‘#’ characters. There should be 15
‘#’ characters in each row.
b. Write a for loop that displays the following set of numbers: 0, 10, 20, 30, 40,
50 . . . 1000.
3. Write a program that uses a loop to display the characters for the ASCII codes 0 through 10
127. Display 16 characters on each line.
5. Write a program that uses a loop to display Pattern A below, followed by another loop 10
that displays Pattern B.
6. Write a program that produces a bar chart showing the population growth of 10
Prairieville, a small town in the Midwest, at 20-year intervals during the past 100 years.
The program should collect the population figures (rounded to the nearest 1,000
people) for 1900, 1920, 1940, 1960, 1980, and 2000 from a user. Ensure that the user
input values greater than 1,000 people. For each year it should display a bar consisting
of one asterisk for each 1,000 people. Here is an example of how the chart might begin:
7. Write a program that displays a weekly payroll report. A loop in the program should 15
ask the user for the employee number, gross pay, state tax, federal tax, and FICA
withholdings. The loop will terminate when 0 is entered for the employee number.
After the data is entered, the program should display totals for gross pay, state tax,
federal tax, FICA withholdings, and net pay.
Input Validation: Do not accept negative numbers for any of the items entered. Do not
accept values for state, federal, or FICA withholdings that are greater than the gross
pay. If the sum state tax + federal tax + FICA withholdings for any employee is greater
than gross pay, print an error message and ask the user to reenter the data for that
employee.
Input Validation: Do not accept a negative number for speed and do not accept any
value less than 1 for time traveled.
9 Write a program that uses nested loops to collect data and calculate the average 15
rainfall over a period of years. The program should first ask for the number of years.
The outer loop will iterate once each year. The inner loop will iterate twelve times,
once for each month. Each iteration of the inner loop will ask the user for the inches of
rainfall for that month. After all iterations, the program should display the number of
months, the total inches of rainfall, and the average rainfall per month for the entire
period.
Input Validation: Do not accept a number less than 1 for the number of years. Do not
accept negative numbers for the monthly rainfall.