Question

C++ programming 6-1: User Defined Functions I the C++ cmath library contains several math-related functions. for...

C++ programming

6-1: User Defined Functions I

the C++ cmath library contains several math-related functions. for a general listing of functions contained within this library, review your text or visit Cplusplus.com

(http://www.cplusplus.com/reference/cilbrary/cmath/)

if you had the option to redesign the math library, what other functions would you add to it? for example, do you think a max function or average function might be useful? give a list of at least three functions you think are worth adding to the math collection. provide a description of each new additional function, including what it does, what parameters it takes, and its return value.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • Below are the 3 functions that are very useful but are not inbuilt in math library:
  1. nCr(int n, int r): this function is used to calculate combinations when we have to find r unordered outcomes from n available possibilities which takes n and r as the parameters and returns value of nCr i.e, (fact(n)/(fact(r)*fact(n-r)) with return type as int, or long long depending upon the result we get as the result can be very large.
  2. nPr(int n, int r):this function is used to calculate total number of permutations when we have to choose r objects from a set of n items which takes n and r as the parameters and returns value of nPr i.e, (fact(n)/fact(n-r)) with return type as int, or long long depending upon the result we get as the result can be very large.
  3. power(int base,int exponent,int modulo): this function is used to calculate (base(exponent)) %mod , this method is called modular exponentiation but is not a inbuilt function in c++ math library (in python it is) , it calculates the value in O(log (exponent)) so the time complexity is also very less, and it is used very often. The return type of this function also could be int or long long int depending upon the results as it can also be large.
  • fact() in function 1 and 2 is function to calculate factorial of a number, so it can also be added to math library but it is not as important as it is easy to implement.
  • Function 1 and 2 mentioned are used oftenly in math problems where we have to put some efforts in buildin the code for that and the function 3 is very important as it is very helpful in solving probabilty problems.
  • Also the functions added in the math library should be of best time complexity so that to produce optimal result everytime and they are worth using it.
  • average function or max function is not useful in a library as it takes only one line of code to calculate these so why use from a library , the function that should be added should be of huge lines of code and difficult to code at a competitive platform where time is the constraint.

So if you have any queries regarding the above explanation please ask in the comment section and if it seems helpful enough then please upvote , thanks.

Add a comment
Know the answer?
Add Answer to:
C++ programming 6-1: User Defined Functions I the C++ cmath library contains several math-related functions. for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Modify the C++ program you created in assignment 1 by using 'user defined' functions. You are...

    Modify the C++ program you created in assignment 1 by using 'user defined' functions. You are to create 3 functions: 1. A function to return the perimeter of a rectangle. This function shall be passed 2 parameters as doubles; the width and the length of the rectangle. Name this function and all parameters appropriately. This function shall return a value of type double, which is the perimeter. 2. A function to return the area of a rectangle. This function shall...

  • SOLVE USING C!!! Project objective: Conditional statements, loops, reading from file, user defined functions. **Submit source...

    SOLVE USING C!!! Project objective: Conditional statements, loops, reading from file, user defined functions. **Submit source code (LargeProg1.c) through Canvas One source code file(unformatted text) will be submitted Here is INCOMPLETE code to get started: LargeProg1.c The file name must match the assignment The code should be tested and run on a Microsoft compiler before it is uploaded onto Canvas The code must be submitted on time in order to receive credit (11:59PM on the due date) Late submissions will...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

  • This problem demonstrates the use of import module. The Python programming language has many strengths, but...

    This problem demonstrates the use of import module. The Python programming language has many strengths, but one of its best is the availability to use many existing modules for various tasks, and you do not need to be an experienced computer programmer to start using these modules. We have given you some incomplete code; note that the very first line of that code contains an import statement as follows: import math This statement enables your program to use a math...

  • PYTHON PROGRAMMING NEED HELP ASAP You will write an application to manage music collections -- a music collection is a l...

    PYTHON PROGRAMMING NEED HELP ASAP You will write an application to manage music collections -- a music collection is a list of albums. The named tuples used for Albums and Songs are defined below, and an example of a music collection is given. (DO NOT HARDCODE THE VALUES FOR MUSIC!) Album = namedtuple('Album', 'id artist title year songs') Song = namedtuple('Song', 'track title length play_count') MUSIC = [ Album("1", "Peter Gabriel", "Up", 2002, [Song(1, "Darkness", 411, 5), Song(2, "Growing Up",...

  • Develop a system flowchart and then write a menu-driven C++ program that uses user-defined functions arrays,...

    Develop a system flowchart and then write a menu-driven C++ program that uses user-defined functions arrays, and a random number generator. Upon program execution, the screen will be cleared and the menu shown below will appear at the top of the screen and centered. The menu items are explained below. Help Smallest Quit H or h ( for Help ) option will invoke a function named help() which will display a help screen. The help screen(s) should guide the user...

  • Question: C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to prov......

    Question: C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to prov... C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to provide practice programming using structs and pointers. Your program will accept user input and store it in a dynamic array of structs. First, you will define a structure to describe a item to be bought. Your program will prompt the user for the initial size of the array. It will...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • Please note that I cannot use the string library function and that it must be coded...

    Please note that I cannot use the string library function and that it must be coded in C89, thank you! Formatting: Make sure that you follow the precise recommendations for the output content and formatting: for example, do not change the text in the first problem from “Please enter a string of maximum 30 characters:” to “Enter string: ”. Your assignment will be auto-graded and any changes in formatting will result in a loss in the grade. 2.Comments: Header comments...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT