Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program which contains various functions in it that do various things. See descriptions on the next several pages for info on each function's



Write a program which contains various functions in it that do various things. See descriptions on the next several pages for info on each function's specifications. Requirements: 1. As per usual, be sure to leave some comments (in your code, for each problem) on how certain complex / unique parts of your program work. 2. You'll must complete all THREE problems listed below and all of these functions must exist within the same source file. 3. Be sure to follow the instructions outlined for each function exactly as described. This includes small things such as using the right data types for your parameters, the spelling of each functions' name, having the correct return types, etc. 4. Do NOT use any external / existing functions found in the C++ standard library (or anywhere else for that matter) in any of your code. All these problems can be completed by utilizing all the basic coding concepts we've learned throughout the course. For example, don't use the "pow()" function found in the library. You can of course still use for printing stuff to output, where appropriate. Tips: 1. Your main method does NOT need to have any code in it. Ideally, you would use it for testing purposes to see if the output / return results of some function calls (with various arguments) works out as expected. What's important for this assignment is that all the function definitions you created are formatted correctly and work as expected / described in these instructions. 2. The problems are ordered from easiest-to-hardest with Question #1 being the easiest and Question #3 [debatable] being the hardest. 3. You DON'T need to create prototypes for any of these functions, though if you want to that's fine.



1. Absolute value function (4 points) Create a function, named "absolute", which has one integer parameter and returns (NOT print) what the absolute value of said parameter is. Also, create an overloaded function which has a 'double' parameter instead. For examples: o The function call of "absolute(-3);" would return 3, not -3 o "absolute(4);" returns 4 since the absolute value of a positive number is itself o "absolute(-5.6);" would return 5.6 o "absolute(78.9);" would return 78.9 o etc.



2. Binomial coefficient function (6 points) Create a function, named "binomialCoefficient", that takes two integer parameters (which you can assume will always be non-negative) labeled 'n' and 'r', in that respective order, and returns (NOT print) what the binomial coefficient between these two factors is. NOTE: Even though this concept may have been glossed over (or maybe even skipped) in Chapter 3, don't worry about overflow occurring; using the integer data type for a problem like this is [realistically] not ideal but for our sake is serviceable. For examples: o "binomialCoefficient(7, 2);" should return 21 o "binomialCoefficient(6, 2);" should return 15 o "binomialCoefficient(3, 1);" should return 3 o "binomialCoefficient(10, 10);" should return 1 o "binomialCoefficient(9, 0);" should return 1 o etc. If you're not sure how to calculate this, here's a link that briefly showcases how this value is found: http://www.mathwords.com/b/binomial_coefficients.htm. NOTE: You can assume that the argument for 'n' will never be less than 'r'. IMPORTANT RULE: You CANNOT solve this problem using recursion, otherwise you will be penalized for plagiarism. In other words, you cannot have the function call upon itself. NOTE: Recursion is an advanced coding technique that we'll never go over since we won't ever need to use in class. TIP: I recommend that you create a helper function which focuses on calculating / returning the factorial of a given number, this way the only real work that would need to be done in the binomial function is basic math on the three, needed factorial values. Once again, if you're not sure how to calculate this, then check out this link: http://www.mathwords.com/f/factorial.htm




3. Printing a graph function (8 points) Create a VOID function, named "printGraph", that takes one integer parameter and prints (NOT return) what a typical Cartesian graph, given said argument acting as a 'size', would be (as seen in examples below). REQUIREMENT: Do not have anything outputted if the argument is less than 1. TIP: Ideally, this should work for any given size though (for testing purposes) you can assume the value will never be greater than 7. Although ... ... make sure that you don't just hardcode a bunch of "if" / cout statements (since doing so will cost you [some] credit) as you should use typical loop logic to go through each "row / column" to see which character(s) should be printed. TIP: Have your loop(s) iterate from [-size to +size], this way you'll know that the important spaces to watch out for are the moments when your loop counter is at zero.





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

Payroll Accounting 2016

Authors: Bernard J. Bieg, Judith Toland

26th edition

978-1305665910, 1305665910, 1337072648, 978-1337072649

More Books

Students also viewed these Computer Network questions