Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Questions, please help :( For each of the following, indicate whether you co

ID: 3858316 • Letter: C

Question

C++ Questions, please help :(

For each of the following, indicate whether you could use inline-ing or default arguments (or both or neither). (It would be helpful if you explained what you felt would default...) ________ function to generate random values in a specified range _______ function to return true if an event of a given probability has 'happened' ______ function to input data from the user (mm/dd/yy)-adjusting for Y2K issues ________ function to calculate the area of a triangle ________ function to print a specified number of copies of the current documents to the specified printer TRUE/FALSE The compiler must see the function prototype before you call the function. TRUE/FALSE That's why we place the function that definition after main. TRUE/FALSE After all, main is the only function that can call other functions. TRUE/FALSE We cannot have default arguments on the inline function. TRUE/FALSE We cannot have both values and reference arguments on the same function. TRUE/FALSE We cannot have a (pure) reference argument with a default value. TRUE/FALSE We cannot (effectively) give prototypes for inline functions. TRUE/FALSE When a programmer calls a function with default arguments, they can leave out any arguments they don't have a particular value for. TRUE/FALSE Default arguments must go at the beginning of the argument list so that the compiler will know they've been skipped when it sees something like f(, , val) in the call. TRUE/FALSE Only reference arguments may be defaulted to a particular value. TRUE/FALSE Value arguments must be defaulted to a global constant. TRUE/FALSE The default value itself must be placed on all function heads the compiler finds-especially when they are in separate files (like with a function in a library). Why are inline function definitions typically placed in a library interface file with their fellow function's prototypes? What would happened if the symbol used in the #ifndef/#define directives wasn't unique? If a library consisted entirely of inline functions (and/or constants and/or typedefinitions), would it need an implementation file? Why/Why not?

Explanation / Answer


32
The compiler must see the function prototype before you call the function
TRUE (This is a way of telling the compiler what data a function will require, without actually providing the function itself.)

That's why we place the function definition after main
TRUE (For clarity it is generally good style to list all functions that will be used by prototypes at the beginning of the file. Then provide main( ) as the first full function definition, followed by each of the other functions in the order in which the prototypes are listed.)

After all, main is the only function that can call other functions.
FALSE (It's not mandatory that u have to call a function only from main. U can call it from any other function too. But the first call should be from main())

33
We cannot have default arguments on an inline function
FALSE

We cannot have both value and reference arguments on the same function
FALSE

We cannot have a (pure) reference argument with a default value
TRUE. (You can do it for a const reference, but not for a non-const one. This is because C++ does not allow a temporary (the default value in this case) to be bound to non-const reference. but this is of very limited practical use.)

We cannot (effectively) give prototype for inline functions
FALSE (Writing prototype for inline function is a fairly common pattern when writing "header only" code. You have a normal header file with no (or few) implementations and another file that is included but acts like an implementation file and contains all the implementations.)

34

When a programmer calls a function with default arguments, they can leave out any arguments they dont have a particular value for
TRUE

Default arguments must go at the begining of the argument list so that the compiler will know they've been skipped when it sees something like f(,,val) in the call
FALSE (The default arguments must always go at the end of the argument list)

Only reference arguments may be defaulted to a particular value
FALSE (Both value and reference arguments may be defaulted to a particular value)

value arguments must be defaulted to a global constant
FALSE

the default value itself must be placed on all function heads the compiler finds - especially when they are in seperate files (like with a function in a library)
FALSE

35

The definition of an inline function doesn't have to be in a header file but, because of the one definition rule for inline functions, an identical definition for the function must exist in every translation unit that uses it.

The easiest way to achieve this is by putting the definition in a header file.

If you want to put the definition of a function in a single source file then you shouldn't declare it inline. A function not declared inline does not mean that the compiler cannot inline the function.

Whether you should declare a function inline or not is usually a choice that you should make based on which version of the one definition rules it makes most sense for you to follow; adding inline and then being restricted by the subsequent constraints makes little sense.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote