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 paramete rs , and default arguments by implementing the functions described
Purpose Demonstrate the ability to write reusable functions and appropriately use value parameters, reference paramete rs 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 thats
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 is 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 functions 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 purchase 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 arguments value should be increased by the dime
arguments value should be increased by the nickel arguments
value should be increased by and the penny arguments 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 arguments value should be
increased by the quarter arguments value should be increased
by the dime arguments value should be increased by the
nickel arguments value should be increased by and the penny
arguments value should be increased by All other argument
values in this example will remain unchanged.
Additional examples are provided in the sample tests in
testMakePurchase.cc included in the zip file attached to the
assignment. Additional Specifications All function prototypes must be contained in a file named programfunctions.h All function implementations must be written in a file named
programfunctions.cc Initial Testing
Initial tests for the functions are attached to the assignmen
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