(C language) (1)How do we generally decide on functions that we need to design f
ID: 3665611 • Letter: #
Question
(C language)
(1)How do we generally decide on functions that we need to design for our programs? Explain in your own words?
I know what it means but how should I explain?Any ideas?
and for the two bottom question?did I do it right?
(2) (4 pts – 1 pt for return type, 3 pts for input parameters) Provide the prototype for a function called volume_pyramid()that accepts three double precision input parameters, which represent the values of the length, width, and height of a pyramid. The function computes and returns the volume of the pyramid defined by length (l), width (w), and height (h).
(3) (7 pts – 1 pt for the header, 1 pt for variable declaration(s), 3 pts for computation, 2 pts for return value) Provide the function definition for volume_pyramid(). Also, be sure to provide the function header for volume_pyramid(). Recall, v = (l x w x h) / 3.
output:
quiz3.h test1 function.c X main.C (Global Scope) volume-pyramid(double l, double w | #include "quiz3.h" 2 3 4 double volume-pyramid(double 1, double w, double h) double v e.0; v=(1 * w * h) / 3; printf("Voulme of pyramid = (length * width * height) / 3 = (%1f * %1f * %lf) / 3 %1f ", 1, w, h, v); return V 7Explanation / Answer
1)
we write functions mainly for two reasons
a) To do the same work , at differents parts of the code
b) For easy de bugging purpose
Hence it is always better to use functions when ever it is possible
for deciding on function, you may consider the following things
i) devide the task that have to be done by your program into sub parts
ii) findout the dependency of one task over the other
iii) check what is the information (input data) required to accomplish those tasks
iv) find the result of each task
v) now create a function for each task you found out
vi) use information required for these tasks as input parameters to those functions
vii) impliments the function
viii) return the output of these function to the calling function
the dependencies that you found in step ii will be used to decide on the sequence in which we can call functions
2)
yes , you have done it correct
two small changes i felt is
1) you can remove the printf statement in volume_pyramid function , and place that in main
because, function is only to calculate volume and return it.
2) v=0.0 is not used in the program, you can remove it
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.