1) Examine the following function header, the write an example call to the funct
ID: 3556879 • Letter: 1
Question
1) Examine the following function header, the write an example call to the function.
void showValue(int quantity)
2) The following statement calls a function named half. The half function returns a value that is half that of the arguement. Write the function.
result = half(number);
3) A program contains the following function.
int cube(int num)
{
return num * num * num;
}
Write a statement that passes the value 4 to this funtion and assigns its return value to the variable result.
4) write a function named timeTen that accepts an arguemtn. When the function is called, it should display the product of its argument multiplied times 10.
5) A program contains the following function.
void display(int arg1, double arg2, char arg3)
{
cout << "Here are the values: "
<< arg1 << " " ,, arg2 << " "
<< arg3 << endl;
}
Write a statemetnt that calls the procedure and passes the following cariables to it:
int age;
double income;
char initials;
6) Write a function named getNumber that uses a reference parameter variable to accept an integer argument. The function should prompt the user to enter a number in the range of 1 through 100.. The input should be validated and stored in the parameter varialbe.
Explanation / Answer
Dear,
1.
int quantity=5;
showValue(quantity);
or
showValue(16);
2.
int half(int num)
{
return num/2;
}
3.
The function accepts a number of type int as a parameter and returns the cube value of that number. The function definition follows:
// cube function definition
int cube(int num)
{
// calculate and return the cube of num
return num * num * num;
} // end of cube function
This function returns an integer as its return-value. So, the type of a variable which is used to store the return-value should be an integer (int).
The specified name of the variable to store the return-value of the function is result. The specified value to pass as an argument to the cube function is 4.
Hence, the statement to call the cube function with a value 4 as its argument and store the return-value of the function in the variable result of type int is as follows:
int result = cube(4);
4.
void timesTen(int x)
{
cout<<(x*10)<<endl;
}//end
5. display(age,income,initial); is the functional call.
6.
void getNumber(int &num)
{
cout << "Enter a number in the range 1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.