All of the work for these problems should be placed in a single .cpp file and submitted directly into BlackBoard. For each of the following problems: Write documentation for each of the functions that...

1 answer below »

All of the work for these problems should be placed in a single .cpp file and submitted directly into BlackBoard.


For each of the following problems:




  1. Write documentation for each of the functions that you write. Indicate what the function does, what the inputs are, and what the function should return.




  2. Describe any assumptions and/or restrictions for your function. If you know that your function cannot cope with certain types of data values, be sure to document them (negatives, floats, etc.)




Problems:




  1. (10 points)Addition. Write a function that accepts twodoubleinput parameters,


    computes the sum of those inputs, and then returns the sum.


    Next, write an overloaded form of this function that accepts two integers, passes the the values to thedoubleform of the function, and then returns the result, implicitly converting to integer.




  2. (20 points)Subtraction. Write a function that accepts twodoubleinput parameters, computes the difference of those inputs by subtraction, and returns the result. You are NOT allowed to use the subtraction operator (−)1. You must produce the final answer by calling the addition function that you wrote as part of the first problem.


    Next, write an overloaded form of this function that accepts two integers, passes the the values to thedoubleform of the function, and then returns the result, implicitly converting to integer.


    Note:I expect that the two above functions should work correctly with whatever numeric data is passed in, whether it be an integer or a floating point number. You should use function overloading for this...


    (continued on next page. . . )




1The ”subtraction” operator implies something of the form ofx−y. You are, however, allowed to use negation (−y)


COMI-1215 Math Functions, Page 2 of 3




  1. (50 points)Multiplication. Write a function that accepts two input parameters, com- putes their product (the result of multiplication), and returns the result. You are not allowed to use the multiplication operator (*) for performing multiplication.2You must implement this as repeated adddition in a loop, building up the answer in an accumula- tor variable.


    Function Usage:For full credit, you can use the + operator for addition. For 10% extra-credit, you can do all of the addition by calling theaddfunction that you created in the first problem.


    Multiplication Data Types:




    • For full credit, your function should work correctly for both inputs being positives, zeroes, or ones. If this is what you choose to do, be sure to use an appropriate data type that prevents negative values.




    • 20% Extra Credit: Add support for negative integers in either (both) input posi- tions.




    • 20% Extra Credit: Add support for a floating-point value (double) in either po- sition (only needs to be one; do not try to attempt both inputs beingdoubles).


      Be sure to use appropriate function overloading if you attempt the extra credit.






  2. (20 points)Exponentiation (Extra-Credit). Write a function that accepts two in- teger input parameters, and computes the result of raising the value of the first input to the value of the second input, and returns the result. You are not allowed to use the multiplication operator (*) for performing multiplication, nor are you allowed to use any built-in C++ functionality that directly produces the exponentiation result.


    Data Types:For full credit, be sure that your function works correctly for both inputs being positives, zeroes, or ones, and also when the second input is negative.


    (continued on next page. . . )




2...with one small exception: you are allowed to use it for computing the absolute value of a number by multiplying it by−1 when the value is negative.


COMI-1215 Math Functions, Page 3 of 3


5. (20 points) In yourmainfunction, write code that executes all of the functions that you have created, making sure that you test those functions with multiple values. Each function call should have a comment above it stating what the expected result should be. Print out the result of each call. What your function computes and what the expected value is should match.


For example, for the multiplication function, you might want to test the following inputs to confirm your code produces the expected results: (2,4), (2,-4), (-4,2), (-4,-2) (4,1), (1, 4), (4, 0), (0, 4), and (4, -1).


Be sure that your testing also properly tests any function overloads that you have created.


There should be no interactive data acquisition from the user. All test values and expected results should be hardcoded into your testing code.

Answered Same DayNov 17, 2021

Answer To: All of the work for these problems should be placed in a single .cpp file and submitted directly...

Anandkumar answered on Nov 18 2021
144 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here