WorksheetsQuiz6: Functions
Total questions: 10
Worksheet time: 6mins
A value parameter is used if a parameter's data flow is
one-way, out of the function.
one-way, into the function.
two-way, into and out of the function.
a and b above
Which of the following function headings is valid?
What (string val1, string val2)
void What
void What (string val1, string val2)
void What (string val1; string val2)
Consider the function definition:
void DoThis(int beta1, int beta2)
{
beta1 = beta1 + 82;
beta2 = 174;
}
Suppose that the caller has integer variables s3 and s4 whose values are 1 and 1, respectively. What are the values of s3 and s4 after return from the following function call?
DoThis (s3, s4);
s3 = 83, and s4 = 174
s3 = 83, and s4 = 1
s3 = 82, and s4 = 1
s3 = 1, and s4 = 1
Given the function heading
void DoThis(int num, string& gamma, char& g)
which of the following is a valid function prototype for DoThis?
void DoThis (int, string&, char&);
string DoThis (int num, string& gamma, char& g);
char DoThis (int, string&, char&);
void DoThis (int num, string gamma, char g);
Consider the function definition:
void SomeFunction(int beta1, float& beta2)
{
beta1 = beta1 + 75;
beta2 = beta2 + 11.25;
}
Suppose that the caller has variables c3 and c4 whose values are 5 and 1, respectively. What are the values of c3 and c4 after return from the following function call?
SomeFunction (c3, c4);
c3 = 5, and c4 = 12.25
c3 = 75, and c4 = 11.25
c3 = 80, and c4 = 12.25
c3 = 5, and c4 = 1
Which of the following function headings is a void function with value parameters?
void PrintTitle( )
void PrintInfo (float old, float amount, float bal, bool over)
void GetData (float& old, float& amount)
void PrintStars ( )
Which of the following is the most appropriate function prototype for a value-returning function named Area that computes and returns the area of a triangle with width/base and height given?
float Area (float w, float h );
float Area(float width, float height )
Area ( );
void Area (float width, float height);
Given the following function prototype and variable declarations:
char DoThis (int& x, int y);
int d;
float h;
char w;
which of following is a valid function activation?
w = DoThis(int& d, int h);
w = DoThis(h, 18);
w = DoThis(d, d+18);
w = DoThis(int& , int);
The following is the function body of Power function:
{
float result = 1;
while (y>0)
{
result = result * x;
y--;
}
return result;
}
Which of the following is the most appropriate function heading?
void Power (float x, int y)
void Power (float x, int y, float result)
int Power (int x, int y)
float Power(float x, int y)
What is the output of the following code fragment?
int z1, z2;
z1 = 8;
z2 = 2;
if (z2 >= 2)
{
int z1 = 76;
z2 = z2 + z1;
}
cout << z1 << " " << z2 << endl;
(a)
