Professional Documents
Culture Documents
m
er as
8.8
co
eH w
Your program should define and call a function:
Function MilesToLaps(float userMiles) returns float
o.
userLaps
rs e
ou urc
Function MilesToLaps(float userMiles) returns float userLaps
// convert miles to laps
o
userLaps = userMiles*4
aC s
vi y re
https://www.coursehero.com/file/74973496/PRG211-Wk5-LAB-Assigmentpdf/
Define that function in a program whose inputs are the car's miles/gallon and
the gas dollars/gallon (both floats). Output the gas cost for 10 miles, 50 miles,
and 400 miles, by calling your DrivingCost function three times.
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. In the DrivingCost function, use the variables in the following
order to calculate the cost: drivenMiles, milesPerGallon, dollarsPerGallon.
m
er as
Function DrivingCost(float drivenMiles,float milesPerGallon,float dollarsPerGallon) returns float
co
eH w
dollarAmount
o.
dollarAmount = (drivenMiles/milesPerGallon)*dollarsPerGallon
rs e
ou urc
Function Main() returns nothing
float milesPerGallon
o
float dollarsPerGallon
aC s
https://www.coursehero.com/file/74973496/PRG211-Wk5-LAB-Assigmentpdf/
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
sh is
Th
https://www.coursehero.com/file/74973496/PRG211-Wk5-LAB-Assigmentpdf/
11.3 User-Defined Functions: Step
counter
A pedometer treats walking 2,000 steps as walking 1 mile. Write a program
whose input is the number of steps, and whose output is the miles walked. If
the input is 5345, the output is 2.6725.
Your program should define and call a function:
Function StepsToMiles(integer userSteps) returns float
numMiles
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
sh is
Th
https://www.coursehero.com/file/74973496/PRG211-Wk5-LAB-Assigmentpdf/
11.4 User-Defined Functions: Leap year
A year in the modern Gregorian Calendar consists of 365 days. In reality, the
earth takes longer to rotate around the sun. To account for the difference in
time, every 4 years, a leap year takes place. A leap year is when a year has
366 days: An extra day, February 29th. The requirements for a given year to
be a leap year are:
1) The year must be divisible by 4
2) If the year is a century year (1700, 1800, etc.), the year must be evenly
divisible by 400
Some example leap years are 1600, 1712, and 2016.
m
er as
Write a program that takes in a year and determines whether that year is a
co
leap year. If the input is 1712, the output is: 1712 is a leap year. If the input is
eH w
1913, the output is: 1913 is not a leap year.
o.
rs e
Your program must define and call a function:
ou urc
Function OutputLeapYear(integer inputYear) returns
nothing
The function should output whether the input year is a leap year or not.
o
aC s
vi y re
ed d
ar stu
sh is
Th
https://www.coursehero.com/file/74973496/PRG211-Wk5-LAB-Assigmentpdf/
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
sh is
Th
https://www.coursehero.com/file/74973496/PRG211-Wk5-LAB-Assigmentpdf/
largest: 15
smallest: 3
Your program should define and call two functions:
Function LargestNumber(integer num1, integer num2,
integer num3) returns integer largestNum
Function SmallestNumber(integer num1, integer num2,
integer num3) returns integer smallestNum
The function LargestNumber should return the largest number of the three
input values. The function SmallestNumber should return the smallest number
of the three input values.
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
sh is
Th
https://www.coursehero.com/file/74973496/PRG211-Wk5-LAB-Assigmentpdf/
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
Write a program that first gets a list of six integers from input. The first five
ar stu
values are the integer list. The last value is the upper threshold. Then output
all integers less than or equal to the threshold value.
sh is
50 60 75
For coding simplicity, follow every output value by a space, including the last
one.
Such functionality is common on sites like Amazon, where a user can filter
results.
Your program should define and use a function:
https://www.coursehero.com/file/74973496/PRG211-Wk5-LAB-Assigmentpdf/
Function outputIntsLessThanOrEqualToThreshold(integer
array(?) userVals, integer upperThreshold) returns
nothing
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
sh is
Th
https://www.coursehero.com/file/74973496/PRG211-Wk5-LAB-Assigmentpdf/