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. ToClosestPrime

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 thats
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 1174==113.
If the argument is 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(92) 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 functions 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 purchase 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 arguments value should be increased by 2, the dime
arguments value should be increased by 1, the nickel arguments
value should be increased by 1, and the penny arguments 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 arguments value should be
increased by 1, the quarter arguments value should be increased
by 3, the dime arguments value should be increased by 1, the
nickel arguments value should be increased by 1, and the penny
arguments value should be increased by 3. 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 program2functions.h
- All function implementations must be written in a file named
program2functions.cc
flags =-std=c++17- Wall -
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_2

Step: 3

blur-text-image_3

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

Learn Mysql The Easy Way A Beginner Friendly Guide

Authors: Kiet Huynh

1st Edition

B0CNY7143T, 979-8869761545

More Books

Students also viewed these Databases questions

Question

What rights does the city management have in this case?

Answered: 1 week ago