0% found this document useful (0 votes)
2 views

PF Assignment 4

This document outlines Assignment 4 for CS 1436.004/006, due on October 25, 2024. It includes various programming tasks such as identifying errors, writing loops, and creating programs for ASCII display, temperature conversion, population growth charts, payroll reports, vehicle distance calculation, and rainfall averages. Each task has specific requirements and input validation criteria.

Uploaded by

abhinavbinu2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

PF Assignment 4

This document outlines Assignment 4 for CS 1436.004/006, due on October 25, 2024. It includes various programming tasks such as identifying errors, writing loops, and creating programs for ASCII display, temperature conversion, population growth charts, payroll reports, vehicle distance calculation, and rainfall averages. Each task has specific requirements and input validation criteria.

Uploaded by

abhinavbinu2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CS 1436.

004/006– Programming Fundamentals


Fall 2024
Assignment 4
Date: October 17, 2024
Due: October 25, 2024 @ 11:59PM

1. Identify the errors and explain the reasons. 5


a.

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.

c. Convert the following for loop to a while loop:


for (int x = 50; x > 0; x−−)
{
cout << x << " seconds to go.\n";
}

d. Convert the following do-while loop to a while loop:


char sure;
do
{
cout << "Are you sure you want to quit? ";
cin >> sure;
} while (sure != 'Y' && sure != 'N');

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.

4. write a program that converts a Celsius temperature to Fahrenheit. Program should 10


use a loop to display a table of the Celsius temperatures 0–20, and their Fahrenheit
equivalents.

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:

PRAIRIEVILLE POPULATION GROWTH


(each * represents 1,000 people)
1900 **
1920 ****
1940 *****

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.

8. The distance a vehicle travels can be calculated as follows: 15


distance = speed * time
For example, if a train travels 40 miles per hour for 3 hours, the distance traveled is 120
miles.
Write a program that asks the user for the speed of a vehicle (in miles per hour) and
how many hours it has traveled. The program should then use a loop to display the
distance the vehicle has traveled for each hour of that time period.
Here is an example of the output:
What is the speed of the vehicle in mph? 40
How many hours has it traveled? 3
Hour Distance Traveled
--------------------------------
1 40
2 80
3 120

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.

You might also like