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

C programming questions. 1. Why do functions have prototypes? 2. What is the pur

ID: 3752109 • Letter: C

Question

C programming questions.

1. Why do functions have prototypes?

2. What is the purpose of a formal parameter?

3. What is the purpose of an actual parameter?

4. What is the NOT principle? Why is it important?

5. Why would you use a formal parameter to get data into a function when you could use a symbolic constant instead? Explain.

6. List the advantages and disadvantages of cohesive functions.

7. If given the choice between writing your own function or using a library function, can you think of situations where it would be preferable to write your own?

8. Why would you want to use a void function? Give some examples.

9. What are the advantages of top-down design?

10. Do cohesive functions promote or discourage code reuse? Explain your answer.

11. Explain in your own words what is meant by procedural abstraction.

12. A light year is a unit of astronomical distance that measures how far light can travel in one year, defined as 365.25 days, which is about 9.4507 x 1012, or about 5.878 trillion miles. A parsec is a unit of astronomical distance, equal to about 3.26 light years. One parsec corresponds to the distance at which the mean radius of the earth's orbit subtends an angle of one second of arc. Since the numbers grow so large so quickly, it's often easier for astronomers to work with parsecs, and convert them back to light years, or even miles, when needed. Write a function to convert parsecs to light years.

Explanation / Answer

Answer 1:

Functions have prototype to serve the following purposes:

Therefore, function prototype specifies the input/output interlace to the function i.e. what to give to the function and what to expect from the function.

Answer 2: Purpose of formal parameter:

The formal parameters are often used to refer to the variable as found in the function definition. When a method is called, the formal parameter is temporarily "bound" to the actual parameter. The method uses the formal parameter to stand for the actual value that the caller wants to be used. Formal parameters are bound to an actual value only as long as their method is active. When a method returns to its caller, the formal parameters no longer contain any values.

Answer 3: Purpose of actual parameter:

Actual parameter refers to the actual input supplied at function call. Actual parameters contain the values that are passed to a procedure and receive results.

Answer 5:

We would use a formal parameter to get data into a function in place of symbolic constant because we use symbolic constant only when the value would not change throughout the program.

Answer 8:

We would like to use void functions when we do not want to return a value after the function executes. A void function performs a task, and then control returns back to the caller--but, it does not return a value. We may or may not use the return statement, as there is no return value. Even without the return statement, control will return to the caller automatically at the end of the function.

Example: We would use void function to print a header/footer to a screen or file.

Answer 9: Advantage of top-down design approach:


Please give thumbsup, if you like it. Thanks.