Description
Lab 3.1 Formatted Output Hello World!
Write a program the outputs ‘Hello World!’
Lab 3.2 Formatted output: No parking sign.
Write a program that prints a formatted “No parking” sign. Note the first line has two leading spaces.
NO PARKING
1:00 – 5:00 a.m.
Lab 3.3 House real estate summary
Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two inputs, current price and last month’s price (both integers). Then, output a summary listing the price, the change since last month, and the estimated monthly mortgage computed as (currentPrice * 0.045) / 12.
Ex: If the input is 200000 210000, the output is:
This house is $200000. The change is $-10000 since last month.
The estimated monthly mortgage is $750.0.
Note: Getting the precise spacing, punctuation, and newlines exactly right is a key point of this assignment. Such precision is an important part of programming.
Lab 3.4 Caffeine levels
A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-life of about 6 hours in humans. Given caffeine amount (in mg) as input, output the caffeine level after 6, 12, and 18 hours.
Ex: If the input is 100, the output is:
After 6 hours: 50.0 mg
After 12 hours: 25.0 mg
After 18 hours: 12.5 mg
Note: A cup of coffee has about 100 mg. A soda has about 40 mg. An “energy” drink (a misnomer) has between 100 mg and 200 mg.
Lab 3.5 Divide by x.
Write a program using integers userNum and x as input, and output userNum divided by x four times.
Ex: If the input is 2000 2, the output is:
1000 500 250 125
Note: In Coral, integer division discards fractions. Ex: 6 / 4 is 1 (the 0.5 is discarded).
Lab 3.6 Driving costs.
Driving is expensive. Write a program with a car’s miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles.
Ex: If the input is 20.0 3.1599, the output is:
1.57995 7.89975 63.198
Note: Small expression differences can yield small floating-point output differences due to computer rounding. Ex: (a + b)/3.0 is the same as a/3.0 + b/3.0 but output may differ slightly. Because our system tests programs by comparing output, please obey the following when writing your expression for this problem. First use the dollars/gallon and miles/gallon values to calculate the dollars/mile. Then use the dollars/mile value to determine the cost per 10, 50, and 400 miles.
Note: Real per-mile cost would also include maintenance and depreciation.
Lab 3.7 Simple statistics.
Part 1
Given 3 integers, output their average and their product, using integer arithmetic.
Ex: If the input is 10 20 5, the output is:
11 1000
Note: Integer division discards the fraction. Hence the average of 10 20 5 is output as 11, not 11.666666666666666.
Submit the above for grading. Your program will fail the test cases (which is expected), until you complete part 2 below but check that you are getting the correct average and product using integer division.
Part 2
Also output the average and product, using floating-point arithmetic.
Ex: If the input is 10 20 5, the output is:
11 1000
11.666666666666666 1000.0
Lab 3.8 Using math functions
Given three floating-point numbers x, y, and z, output x to the power of y, x to the power of (y to the power of z), the absolute value of x, and the square root of (xy to the power of z).
Ex: If the input is 5.0 6.5 3.2, the output is:
34938.56214843421 1.2995143401732918e+279 5.0 262.42993783925596
Hint: Coral has built-in math functions (discussed elsewhere) that may be used.
Function Behavior Example
SquareRoot(x) Square root of x SquareRoot(9.0) evaluates to 3.0.
RaiseToPower(x, y) Raise x to power y: RaiseToPower(6.0, 2.0) evaluates to 36.0.
AbsoluteValue(x) Absolute value of x AbsoluteValue(-99.5) evaluates to 99.5.
Reviews
There are no reviews yet.