Laboratory #3 Solution

$30.00

Category:

Description

NOTE:

 

  • Please submit only C++ source files (*.cpp) to Blackboard.

 

  • Please put your name, project description, and date on the top of your file as a comment.
  • PLEASE WORK ALONE. If cheating is found, you will get ZERO.

 

1. (Lastname_Lab3_p1.cpp. 10 points) Write a program that converts gallons to
liters. The program should display gallons from 10 to 20 in 1-gallon increments
and the corresponding liter equivalents. Use the relationship that 1 gallon of liquid
is equivalent to 3.785 liters.
2. (Lastname_Lab3_p2.cpp. 20 points) Write a program that calculates and
displays the amount of money available in a bank account that initially has $1000
deposited in it and that earns interest at the rate of 8 percent a year. Your program
should display the amount available at the end of each year for a period of 10
years. Use the relationship that the money available at the end of each year equals
the amount of money in the account at the start of the year plus 0.08 times the
amount available at the start of the year.
3. (Lastname_Lab3_p3.cpp. 20 points) Modify the program written for the program
2 to prompt the user for the amount of money initially deposited, the interest rate
to be used, and the number of years to be displayed.
4. (Lastname_Lab3_p4.cpp. 20 points) Write a program that prints the following
diamond shape. You may use output statements that print either a single asterisk
(*) or a single blank. Maximize your use of repetition with nested for structure)
and minimize the number of output statements.
*
***
*****
*******
*********
*******
*****
***
*
5. (Lastname_Lab4_p5.cpp. 30 points) Develop a program that will determine the
gross pay for each of several employees. The company pays “straight-time” for
the first 40 hours worked by each employee and pays “time-and-a-half” for all

hours worked in excess of 40 hours. You are given a list of the employee’s of the company, the number of hours each employee worked last week, and the hourly

 

rate of each employee. Your program should input this information for each employee, and should determine and display the employee’s gross pay. (Hint: use while loop, terminate the program when the number of hours is -1.)

 

Sample outputs (prompt in Italic, user input underlined, result output in bold):

 

Enter hours worked (-1 to end): 39

Enter hourly rate of the worker: 10

 

Salary is $390

 

Enter hours worked (-1 to end): 41

Enter hourly rate of the worker: 10

 

Salary is $415

 

Enter hours worked (-1 to end): -1

 

End of the program.

 

 

 

 

  1. (OPTIONAL. Lastname_Lab3_p6.cpp. 30 points) (Pythagorean Triples) A right triangle can have sides that are all integers. The set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the relationship that the sum of the square of two of the sides is equal to the square of the hypotenuse. Find all Pythagorean triples for side1, side2 and the hypotenuse all no larger than 1000. Use a triple-nested for-loop that tries all (This is an example of “brute force” computing. You will learn in more advanced computer science courses that there are many interesting problems for which there is no known algorithmic approach other than using sheer brute force.)

error: Content is protected !!