For Only TinselWriter !!!

profilewld norah

Problem 1

Recall the function from Homework 4, Problem 1 that gives discounts to frequent shoppers based on their level. As a reminder: A store gives discounts to frequent shoppers based on their past level of purchases; they are either "silver" level, "gold" level, or "platinum" level. Silver level frequent shoppers receive a 15% discount, gold level frequent shoppers receive a 20% discount, and platinum level frequent shoppers receive a 30% discount. All other shoppers receive no discount. Use funct_play2 to develop a C++ function get_discount that, given a string representing the level of frequent shopper, returns the appropriate discount for that level written as a decimal fraction. (It should return a discount of 0 if the shopper level is not one of those noted above.) You are expected to make and use a named constant for each of the three shopping-level discount values, and make sure you provide sufficient examples/tests.

 Submit your resulting get_discount.cpp, get_discount.h, and get_discount_ck_expect.cpp files.

 

Problem 2

THIS FUNCTION DOES NOT REQUIRE an if or switch statement! Recall the function from Homework 4, Problem 2 that used Homework 4, Problem 1's function to determine the discounted total for a purchase by a frequent shopper. Use funct_play2 to develop a C++ function discounted_total that expects the total of a purchase before discount and a string representing the level of frequent shopper, and produces the appropriate discounted total for that purchase. For full credit, your solution must appropriately use your get_discount function from Problem 1 - that is, you'll want to answer y to funct_play2's question: Are there any already-created C++ functions (in the current working directory) which you would like to be able to use within your new function? (type y if so, n if not) your answer: ...and, when it asks, be sure to say that get_discount is a function you want to use in discounted_total. (Hint: you should not need an if statement in this particular function, thanks to get_discount.) Submit your resulting discounted_total.cpp, discounted_total.h, and discounted_total_ck_expect.cpp files.

 

Problem 3

Recall the function from Homework 4, Problem 3 that recommends what outerwear to wear on a given day given the predicted high temperature in Fahrenheit degrees, based on the following: <= 32 - "heavy parka" (32, 45) - "coat" [45, 60) - "light jacket" >= 60 - "no outerwear needed" Use funct_play2 to develop a C++ function what_outerwear that that expects the predicted high temperature in Fahrenheit, and returns the recommended outerwear for that day. For full credit, make sure that you include at least the minimum required examples/tests for this data (hint: including boundary cases!). Submit your resulting what_outerwear.cpp, what_outerwear.h, and what_outerwear_ck_expect.cpp files.

 

Problem 4

Recall the function from Homework 4, Problem 4 regarding pizza consumption and exercise. Use funct_play2 to develop a C++ function workout that determines the number of hours of exercise required to counter the excess fat from eating pizza. workout expects a number that represents daily pizza consumption, in slices, and produces a number, in hours, that represents the amount of exercise time that you need. 

For a daily intake of : You need to work out for : 0 slices 1/2 hour 1 to 4 slices 1 hour >4 slices 1 hour + (1/2 hour per slice above 4) Be sure to include an appropriately complete set of specific examples/tests. Submit your resulting workout.cpp, workout.h, and workout_ck_expect.cpp files.

 

Problem 5

Assume that coins are represented as follows: • 'Q' or 'q' -- quarter • 'D' or 'd' -- dime • 'N' or 'n' -- nickel • 'C' or 'c' or 'P' or 'p' -- cent/penny Use funct_play2 to develop a C++ function get_worth that expects a character representing a coin, and uses a C++ switch statement to return the decimal worth of that coin (for example, a cent/penny is worth 0.01). If it receives any character besides those noted above, it should return a worth of 0.0. Submit your resulting get_worth.cpp, get_worth.h, and get_worth_ck_expect.cpp files.

 

Problem 6

This problem's purpose is to provide more practice with the C++ switch statement. Fun fact: the C++ cmath library has a function pow that expects two double arguments and returns the result of raising the first argument to the power given by the second argument. That is, pow(2.0, 3.0) gives you the result of raising 2.0 to the power 3.0, and so results in 2.0 * 2.0 * 2.0 == 8.0. Consider: a character '+' cannot be actually used to add two numbers together in C++ -- but if you were given that character, and two numbers, you could write logic that would see if the given character was a '+', and if that is so, then it would add those numbers together using a proper + operator. Use the design recipe to develop a C++ function do_op that indeed expects an operator expressed as a character and two numbers, and uses a C++ switch statement to return the result of performing the operator corresponding to that character to those two numbers. It should be able to support: '+' -- add the two numbers '-' -- subtract the two numbers '*' -- multiply the two numbers '/' -- divide the two numbers '^' -- raise the first number to the power of the second number (No, C++ does NOT have a ^ operator. But it does have that pow function mentioned earlier... 8 - ) ) (You may add additional operator-characters if you would like.) It should simply return 0.0 if called with any unsupported/unexpected character as the operator. For example: 

do_op('+', 3.4, 1.6) == 5.0 do_op('-', 5, 2) == 3.0 (although, if necessary, abs(do_op('+', 3.4, 1.6) - 5.0) < 0.01 abs(do_op('-', 5, 2) - 3.0) < 0.01 ... 8-) ) Submit your resulting do_op.cpp, do_op.h, and do_op_ck_expect.cpp files.

 

    • 5 years ago
    • 20
    Answer(0)
    Bids(0)