Answered step by step
Verified Expert Solution
Link Copied!

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(10); should return 1 since 11 is the closest prime to 10, and 10+1==11.
The function call ToclosestPrime(117); should return -4 since 113 is the closest prime to 117, and 117-4==113.
If the argument if equidistant between two primes, the function should return a positive integer. For example, ToclosestPrime(9); should return 2 since the closest primes to 9 are 7(9-2) and 11(9+2).
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 comma-separated 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 (2,3); should output nothing
PrintPrimesBetween (2,3, true); should output "2,3"
PrintPrimesBetween (4,17); should output "5,7,11,13"
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 -1.
For example:
LargestPrimesequence(4) should return -1
LargestPrimeSequence(17) should return 17
LargestPrimeSequence(248) should return 2
LargestPrimesequence(801302) should return 13
LargestPrimesequence(293794) should return 937
LargestPrimeSequence(31131) should return 311
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 "$
d.cc"
For example, the function call
PrintAsDollarsAndCents(2708); should output $27.08 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 8 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 2-9 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 2-9 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 bills/coins possible to pay for the items, and change should be returned using the fewest bills/coin.
For example, if the purchase to be made costs $17.82 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 1, the value of twenty dollar bill argument should be reduced by 1. In this example, the change returned will be $2.18. So the one dollar bill argument's value should be increased by 2, the dime argument's value should be increased by 1, the nickel argument's value should be increased by 1, and the penny argument's value should be increased by 3. All other argument values in this example will remain unchanged.
If multiple options to make the purchase would require the same number of bills/coins, the purchase should be made using the smaller denomination of bills/coins.
For example, if the purchase to be made costs $8.07 and the value of the variables sent for the second argument and third arguments are both greater than or equal to 1(there are $20 bills and $10 bills available), the value of ten dollar bill argument should be reduced by 1 and the value of twenty dollar bill argument should remain unchanged. In this example, the change returned will be $1.93. So the one dollar bill argument's value should be increased by 1, the quarter argument's value should be increased by 3, the dime argument's value should be increased by 1, the nickel argument's value should be increased by 1, and the penny argument's value should be increased by 3. All other argument values i
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

When does benefi t realization start?

Answered: 1 week ago

Question

Describe the appropriate use of supplementary parts of a letter.

Answered: 1 week ago