Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Purpose - Demonstrate the ability to write reusable functions and appropriately use value parameters, reference parameters, and default arguments by implementing the functions described below.
Purpose Demonstrate the ability to write reusable functions and appropriately use value parameters, reference parameters, and default arguments by implementing the functions described below.
ToclosestPrime This function takes an integer argument and returns an integer representing the signed distance to the prime number that's closest to that integer.
For example, ToclosestPrime; should return since is the closest prime to and
The function call ToclosestPrime; should return since is the closest prime to and
If the argument if equidistant between two primes, the function should return a positive integer. For example, ToclosestPrime; should return since the closest primes to are and
PrintPrimesBetween This function takes integers for the lower and upper bounds of a range of values, and a bool for whether or not the inputs of the range are included, as arguments. The bool parameter should have a default argument of false.
The function should output a commaseparated list of all of the prime numbers in the range to the standard output device using cout The function should output no leading or trailing whitespace on the list.
For example:
PrintPrimesBetween ; should output nothing
PrintPrimesBetween true; should output
PrintPrimesBetween ; should output
LargestPrimeSequence This function takes an integer argument and returns the largest prime number seen as a sequence of digits in the argument. If no sequence of digits in the number is a prime, the function should return
For example:
LargestPrimesequence should return
LargestPrimeSequence should return
LargestPrimeSequence should return
LargestPrimesequence should return
LargestPrimesequence should return
LargestPrimeSequence should return
PrintAsDollarsAndCents This function takes an integer argument for a monetary amount in cents, and outputs the amount to the standard output device using cout in the dollars and cents format $
dcc
For example, the function call
PrintAsDollarsAndCents; should output $ to the standard output device.
No whitespace should be output by this function.
MakePurchase This function will take a purchase cost, in cents, as the first argument. The function's next arguments are variables holding the number of twenty dollar bills, ten dollar bills, five dollar bills, one dollar bills, quarters, dimes, nickels, and pennies available to make the purchase.
If arguments do not provide sufficient money to make the purchase, those arguments should be unchanged by the function call, and the function should return false.
If arguments do provide sufficient money to make the purchase, those arguments should be modified to pay for the purchase and receive the correct change, and the function should return true. The pulchase should be made using the fewest billscoins possible to pay for the items, and change should be returned using the fewest billscoin
For example, if the purchase to be made costs $ and the value of the variable sent for the second argument which holds the number of twenty dollar bills is greater than or equal to the value of twenty dollar bill argument should be reduced by In this example, the change returned will be $ So the one dollar bill argument's value should be increased by the dime argument's value should be increased by the nickel argument's value should be increased by and the penny argument's value should be increased by All other argument values in this example will remain unchanged.
If multiple options to make the purchase would require the same number of billscoins the purchase should be made using the smaller denomination of billscoins
For example, if the purchase to be made costs $ and the value of the variables sent for the second argument and third arguments are both greater than or equal to there are $ bills and $ bills available the value of ten dollar bill argument should be reduced by and the value of twenty dollar bill argument should remain unchanged. In this example, the change returned will be $ So the one dollar bill argument's value should be increased by the quarter argument's value should be increased by the dime argument's value should be increased by the nickel argument's value should be increased by and the penny argument's value should be increased by All other argument values i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started