Question: 4. Given the following program segments, each case you need to predict the outputs from the program. a) void Any(int x, int & y) {

4. Given the following program segments, each case you need to predict the outputs from the program.

a)

void Any(int x, int & y)

{

x += 2;

y -= 2;

}

int main()

{

int a, b;

a = 5;

b = 10;

Any(a, b);

cout << a = << a << , b = << b << endl;

}

What will be the display?

b) Consider the following functions:

int secret(int x)

{

int i, j;

i = 2 * x;

if (i > 10)

j = x / 2;

else

j = x / 3;

return j - 1;

}

int another(int a, int b)

{

int i, j;

j = 0;

for (i = a; i <= b; i++)

j = j + i;

return j;

}

What is the output of each of the following program segments? Assume

that x, y, and k are int variables.

i) x = 10;

cout << secret(x) << endl;

ii) x = 5; y = 8;

cout << another(x, y) << endl;

5.

Finding Errors:

Each of the following function has errors. Locate as many errors as you can:

void Total(int value1, value2, value3) {

return value1 + value2 + value3;

}

double Average(int value1, int value2, int value3);

{

double average ;

average = (value1 + value2 + value3)/3;

}

void Area(int length, int width)

{

area = length * width;

return area;

Void functions do not return values

}

void GetValue(int value&)

{

cout << Enter a value: ;

cin >> value;

}

int Fx(int a, int b)

{

int sum, diff;

sum = a + b;

diff = a b;

return sum;

return diff;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!