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

Write the proper syntax for a void function declaration (Use generic names such

ID: 3532517 • Letter: W

Question

Write the proper syntax for a void function declaration (Use generic names such as function_name, parameter_list, delclaration_1, executable_statement_l etc.) Write the proper syntax for a void function definition (Use generic names such as function_name, parameter_list, delclaration_l, executable_statement_l etc.) Make note of the proper use for the return statement. What is the call-by-reference parameter and what does it do? Show an example of how to use this parameter by writing a generic function declaration that uses the call-by-reference parameter. Define precondition and postcondition in your own words. How is overloading possible? Why is it useful? Sally wants to track her ice cream sales through the week. On Mondays, Wednesdays, and Fridays she sells 2 flavors of ice cream (chocolate & vanilla), but on Tuesdays and Thursdays she sells three flavors of ice cream (chocolate, vanilla, and strawberry). Write two overloaded functions that take input from Sally and shows the number of people that bought the respective flavor and outputs it in a nice chart ( Synthesis).

Explanation / Answer

1. void function_name (parameter list);


2. void function_name (parameter list)

{

declaration_1;

declaration_2;


executable_statement_1;

executable_statement_2;

}

3.The return statement terminates the execution of a function and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can also return a value to the calling function.

The value of expression, if present, is returned to the calling function. If expression is omitted, the return value of the function is undefined. The expression, if present, is converted to the type returned by the function. If the function was declared with return type void, a return statement containing an expression generates a warning and the expression is not evaluated.

If no return statement appears in a function definition, control automatically returns to the calling function after the last statement of the called function is executed. In this case, the return value of the called function is undefined. If a return value is not required, declare the function to have void return type; otherwise, the default return type is int.

4. A variable of a reference type does not contain its data directly; it contains a reference to its data. When you pass a reference-type parameter by value, it is possible to change the data pointed to by the reference, such as the value of a class member. However, you cannot change the value of the reference itself; that is, you cannot use the same reference to allocate memory for a new class and have it persist outside the block. To do that, pass the parameter using the ref or out keyword.

##include <stdio.h>


void call_by_reference(int *y) {

printf("Inside call_by_reference y = %d before adding 10. ", *y);

(*y) += 10;

printf("Inside call_by_reference y = %d after adding 10. ", *y);

}


int main() {

int b=10;

printf("b = %d before function call_by_reference. ", b);

call_by_reference(&b);

printf("b = %d after function call_by_reference. ", b);

return 0;

}


5.

Pre-conditions are the things that must be true before a method is called. The method tells clients "this is what I expect from you".

Post-conditions are the things that must be true after the method is complete. The method tells clients "this is what I promise to do for you".



6..

The overloaded function must differ either by the arity or data types.

The same function name is used for various instances of function call.



It is a classification of static polymorphism in which a function call is resolved using the 'best match technique ', i.e., the function is resolved depending upon the argument list. Method overloading is usually associated with statically-typed programming languages which enforce type checking in function calls. When overloading a method, you are really just making a number of different methods that happen to have the same name. It is resolved at compile time which of these methods are used.


7.#include <iostream>

void icecreame(int c,int v)

{

ch=ch+c;

va=va+v;

}

void icecreame(int c,int v,int s)

{

ch=ch+c;

va=va+v;

st=st+s;

}

void main()

{

int ch,va,st;

int d=1;

while(d==1)

{

scanf("%d%d%d",&ch,&va,&st);


void icecreame(4,5);

void icecreame(6,7,8);

printf("to break press 0");

scanf("%d",&d);

}


printf("chocolate=%d",ch);

printf("vanilla=%d",va);

printf("straberry=%d",st);

}