What is the first line of output when this program is run

Assignment Help C/C++ Programming
Reference no: EM131299007

For problems 1 and 2 consider the following program:

#include <iostream>

using namespace std;

void test(int &a, int &b, int c);

int main()

{

int a = 9, b = 8, c = 7;

test(c, a, b);

cout << a << " " << b << " " << c << endl;

}

void test(int &a, int &b, int c)

{

cout << a << " " << b << " " << c << endl;

a = 91; b = 92; c = a + b;

}

1. What is the first line of output when this program is run?

a. 9 8 7

b. 7 9 8

c. 8 9 7

d. 7 8 9

e. None of the above.

2. What is the second line of output when this program is run?

a. 91 92 183

b. 91 92 7

c. 92 8 92

d. 92 183 91

e. None of the above.

For problems 3 and 4 consider the following program:

#include <iostream>

using namespace std;

void test(int &a, int &b, int c);

int main()

{

int a = 9, b = 8, c = 7;

test(c, c, c);

cout << a << " " << b << " " << c << endl;

}

void test(int &a, int &b, int c)

{

a = 91; b = 92; c = a + b;

cout << a << " " << b << " " << c << endl;

}

3. What is the first line of output when this program is run?

a. 91 92 183

b. 91 92 184

c. 91 91 182

d. 92 92 184

e. None of the above.

4. What is the second line of output when this program is run?

a. 9 8 92

b. 9 8 91

c. 9 92 7

d. 9 92 183

e. None of the above.

5. What is the output of the following program? (In the choices given below, "?" is used to indicate that the output is unknown.)

#include <iostream>

using namespace std;

void test();

int d;

int main()

{

d = 6;

cout << d << " ";

test();

cout << d << " ";

}

void test()

{

cout << d << " ";

d = 97;

cout << d << " ";

}

a. 6 ? 97 6

b. 6 97 97 6

c. 6 6 97 97

d. 6 6 97 6

e. None of the above.

6. Given the function prototype

void Fix(int&, double);

which of the following is an appropriate function call? (someInt is of type int, and somedouble is of type double.)

a. Fix(24, 6.85);

b. somedouble = 0.3 * Fix(someInt, 6.85);

c. Fix(someInt + 5, somedouble);

d. a and c above

e. None of the above.

7. Given the function definition

void Twist(int a, int& b)

{

int c;

c = a + 2;

a = a * 3;

b = c + a;

}

What is the output of the following code fragment that invokes Twist? (All variables are of type int.)

r = 1;

s = 2;

t = 3;

Twist(t, s);

cout << r << ' ' << s << ' ' << t << endl;

a. 1 14 3

b. 1 10 3

c. 5 14 3

d. 1 14 9

e. None of the above.

8. Consider the function definition

void Demo(int intVal, double& doubleVal)

{

intVal = intVal * 2;

doubleVal = double(intVal) + 3.5;

}

Suppose that the caller has variables myInt and mydouble whose values are 20 and 4.8, respectively. What are the values of myInt and mydouble after return from the following function call?

Demo(myInt, mydouble);

a. myInt = 20 and mydouble = 43.5

b. myInt = 40 and mydouble = 4.8

c. myInt = 20 and mydouble = 4.8

d. myInt = 40 and mydouble = 43.5

e. None of the above.

9. Consider the function definition

void Demo(int& intVal, double doubleVal)

{

intVal = intVal * 2;

doubleVal = double(intVal) + 3.5;

}

Suppose that the caller has variables myInt and mydouble whose values are 20 and 4.8, respectively. What are the values of myInt and mydouble after return from the following function call?

Demo(myInt, mydouble);

a. myInt = 20 and mydouble = 43.5

b. myInt = 40 and mydouble = 4.8

c. myInt = 20 and mydouble = 4.8

d. myInt = 40 and mydouble = 43.5

e. None of the above.

10. Consider the function definition

void DoThis(int& alpha, int beta)

{

int temp;

alpha = alpha + 100;

temp = beta;

beta = 999;

}

Suppose that the caller has integer variables gamma and delta whose values are 10 and 20, respectively. What are the values of gamma and delta

after return from the following function call?

DoThis(gamma, delta);

a. gamma = 10 and delta = 20

b. gamma = 110 and delta = 20

c. gamma = 10 and delta = 999

d. gamma = 110 and delta = 999

e. None of the above.

11. What is the output of the following program?

#include <iostream>

using namespace std;

void Try(int&, int);

int x;

int y;

int z;

int main()

{

x = 1;

y = 2;

z = 3;

Try(y, x);

cout << x << ' ' << y << ' ' << z << endl;

}

void Try(int& a, int b)

{

int x;

x = a + 2;

a = a * 3;

b = x + a;

}

a. 10 6 3

b. 10 2 3

c. 1 2 3

d. 1 6 3

e. None of the above.

12. Given the function definition

int Mystery(double someVal)

{

if (someVal > 2.0)

return 3 * int(someVal);

else

return 0;

}

what is the value of the expression Mystery(4.2) ?

a. 12

b. 12.0

c. 0

d. 0.0

e. Nothing--the function call is invalid.

13. Given the function definition

int Trans(int alpha, int beta)

{

if (alpha > beta)

return alpha + 10;

else

return 2 * beta;

}

what is printed by the following code?

cout << Trans(5, Trans(9, 4)) << endl;

a. 15

b. 38

c. 16

d. 19

e. 8

14. Given the function definition

bool IsZip(double somedouble)

{

return (somedouble == 0.0);

}

what is the value of the expression IsZip(2.4)?

a. 0.0

b. true

c. 2.4

d. false

e. "somedouble == 0.0"

15. Given the function prototype

bool IsGreater(int, int);

which of the following statements use valid (i.e. syntactically correct) calls to the IsGreater function? (The data types of the variables are suggested by their names.)

a. someBoolean = IsGreater(someInt, 8);

b. if (IsGreater(5, someInt))

intCounter++;

c. while (IsGreater(inputInt, 23))

cin >> inputInt;

d. b and c above

e. a, b, and c above

16. What happens if a value-returning function with the prototype double Average(int, int, int);

is called by using the following statement? (alpha and beta are int variables.)

Average(alpha, 34, beta);

a. The compiler issues a syntax error message.

b. The function is executed, and the function value is discarded.

c. The function is executed, and the function value is assigned to alpha.

d. The function is not executed, and the program halts with a run time error message.

e. None of the above.

17. The function heading

double TenToThePower(int n)

is for a function that returns 10.0 raised to any integer power. Which of the following statements stores into somedouble the value 10.0 raised to the power someInt?

a. TenToThePower(somedouble, someInt);

b. TenToThePower(someInt);

c. TenToThePower(someInt) = somedouble;

d. somedouble = TenToThePower(someInt);

e. someInt = TenToThePower(somedouble);

18. The function heading

double TenToThePower(int n)

is for a function that returns 10.0 raised to any integer power. Which of the following statements represents an appropriate use of the TenToThePower function?

a. somedouble = 4.96 * TenToThePower(8) + 2.5;

b. TenToThePower(6);

c. if (TenToThePower(someInt) > somedouble)

beta = 3;

d. a and b above

e. a and c above

19. Given the function prototype

int Top(int, int);

which of the following statements contain valid calls to the Top function?

a. someInt = 4 + Top(oneInt, anotherInt);

b. cin >> Top(oneInt, anotherInt);

c. cout << Top(5, Top(3, 4));

d. a and c above

e. a, b, and c above

20. This question demonstrates the hazards of side effects. Given the

function definition

int Power(int& base, int& exp)

{

int product = 1;

while (exp >= 1)

{

product = product * base;

exp--;

}

return product;

}

what is the output of the following code? (All variables are of type int.)

n = 2;

pow = 3;

result = Power(n, pow);

cout << n << " to the power " << pow << " is " << result;

a. 2 to the power 3 is 8

b. 2 to the power 0 is 8

c. 0 to the power 0 is 0

d. 2 to the power 3 is 1

e. None of the above.

21. Given the class declaration

class MyClass {

public:

...

void Func();

private:

int n;

};

what notation does the body of Func use to assign the value 3 to the private data member n?

a. n = 3;

b. MyClass.n = 3;

c. int n = 3;

d. someObject.n = 3;

e. It can't be done--n is private.

22. Given the class declaration

class X {

public:

void F( int );

private:

int n;

};

which line(s) of the following client code cause(s) a compile-time error?

X alpha; // Line 1

alpha.F(); // Line 2

alpha.n = 42; // Line 3

a. line 1

b. line 2

c. line 3

d. lines 1 and 2

e. lines 2 and 3

23. Consider the class declaration

class MyClass {

public:

...

MyClass();

// Postcondition:

// Private data initialized to zero

MyClass(int n);

// Postcondition:

// Private data initialized to n

private:

int priv;

};

and client code

MyClass gamma(5);

After gamma is created, what is the value of gamma.priv?

a. 0

b. 5

c. n

d. Unknown, but the declaration of gamma is valid.

e. The declaration of gamma is invalid.

For problems 24 through 27, consider the following class declaration:

class rectangle {

public:

// member function prototypes have been omitted

private:

int length;

int width;

};

24. Which of the following is the best function header for a member function named doubleSize() that takes no arguments and returns a rectangle object whose length and width are twice those of the calling object. The function must not modify the calling object!

a. rectangle rectangle::doubleSize()

b. rectangle rectangle::doubleSize() const

c. void rectangle::doubleSize()

d. void rectangle::doubleSize() const

e. None of the above.

25. Which of the following is the correct body of the doubleSize() function described in problem 4?

a. length = length * 2;

width = width * 2;

b. rectangle temp;

temp.length = length * 2;

temp.width = width * 2;

return temp;

c. rectangle temp;

length = length * 2;

width = width * 2;

return temp;

d. rectangle temp;

temp.length = temp.length * 2;

temp.width * temp.width * 2;

return temp;

e. None of the above.

26. Which of the following is the best function header for a member function named hasSmallerAreaThan() that takes a single rectangle object argument and returns true if the calling object has a smaller area than the argument, false otherwise. The function must modify neither the argument nor the calling object!

a. bool rectangle::hasSmallerAreaThan(const rectangle& r) const;

b. bool rectangle::hasSmallerAreaThan(rectangle r) const;

c. bool rectangle::hasSmallerAreaThan(rectangle r);

d. bool rectangle::hasSmallerAreaThan(const rectangle& r);

e. None of the above.

27. Which of the following is the correct body of the hasSmallerAreaThan() function described in problem 6?

a. if (length * width < r.length * r.width) return true;

b. return length < r.length && width < r.width;

c. return area1 < area2;

d. return length * width < r.length * r.width;

e. None of the above.

28. Suppose that the class declaration of someclass includes the following function prototype:

bool lessthan(someclass s);

Which of the following tests in the client code correctly compares two

class objects alpha and beta?

a. if (alpha < beta)

b. if (alpha.lessthan(beta))

c. if (lessthan(alpha, beta))

d. if (lessthan(beta))

e. if (lessthan(alpha).beta)

29. Given the declarations

int status[10];

int i;

which of the following loops correctly zeros out the status array?

a. for (i = 0; i <= 10; i++)

status[i] = 0;

b. for (i = 0; i < 10; i++)

status[i] = 0;

c. for (i = 1; i <= 10; i++)

status[i] = 0;

d. for (i = 1; i < 10; i++)

status[i] = 0;

e. for (i = 1; i <= 11; i++)

status[i] = 0;

30. After execution of the code fragment

int arr[5];

int i;

for (i = 0; i < 5; i++) {

arr[i] = i + 2;

if (i >= 3)

arr[i-1] = arr[i] + 3;

}

what is contained in arr[1]?

a. 2

b. 3

c. 7

d. 8

e. none of the above

31. After execution of the code fragment

int arr[5];

int i;

for (i = 0; i < 5; i++) {

arr[i] = i + 2;

if (i >= 3)

arr[i-1] = arr[i] + 3;

}

what is contained in arr[3]?

a. 5

b. 3

c. 8

d. 9

e. none of the above

32. Given a 5000-element, one-dimensional array beta, which of the code fragments below could be used to print out the values of beta[0], beta[2], beta[4], and so forth? (All variables are of type int.)

a. for (i = 0; i < 5000; i = i + 2)

cout << beta[i] << endl;

b. for (i = 0; i < 2500; i++)

cout << beta[2*i] << endl;

c. for (i = 0; i < 2500; i++)

cout << beta[i]*2 << endl;

d. a and b above

e. a, b, and c above

33. Which of the following cannot be used to input values into a 3-element int array named alpha?

a. cin >> alpha[0] >> alpha[1] >> alpha[2];

b. cin >> alpha;

c. for (i = 0; i < 3; i++)

cin >> alpha[i];

d. cin >> alpha[0];

cin >> alpha[1];

cin >> alpha[2];

e. Any of these could be used.

34. Given the program fragment

char alpha[200];

char beta[200];

...

Copy(alpha, beta);//Copy all components of beta into alpha

which of the following is the best function heading for the Copy function?

a. void Copy(char arr1[], char arr2[] )

b. void Copy(const char arr1[], char arr2[] )

c. void Copy(char arr1[], const char arr2[] )

d. void Copy(const char arr1[], const char arr2[] )

Reference no: EM131299007

Questions Cloud

Calculate the series resistance of the 30 nh inductors : Calculate the series resistance of the 30-nH inductors studied in Examples 2 and 3 at 900 MHz. Assume μ = 4π X 10-7 H/m.
Comfortable working under the compensation system : If you were hired by a company such as Antle, would you feel comfortable working under the compensation system it has in place? Why or why not? Depending on your response, outline what features of the compensation system would make you the happies..
Is his famous 60 home runs in 1927 an outlier : Make a stemplot of these data. Is the distribution roughly symmetric, clearly skewed, or neither? About how many home runs did Ruth hit in a typical year? Is his famous 60 home runs in 1927 an outlier?
Describe the main features of the distribution : Because the total population in 2075 is much larger than the 1950 population, comparing percentages in each age group is clearer than comparing counts. Make a table of the percentage of the total population in each age group for both 1950 and 2075..
What is the first line of output when this program is run : What is the first line of output when this program is run? What is the second line of output when this program is run? What is the first line of output when this program is run?
Compared with counterpart in a single ended inductor : Compared with its counterpart in a single-ended inductor, given Equation, this value is higher by a factor of 160/9 ≈ 18.
Types of conflict in the workplace : Let's take a look at some other types of conflict in the workplace. Workplace violence by some is considered a conflict and others classify it as workplace violence.
Briefly describe the shape of the distribution : The only brand with a different makeup was Eat Slim Veal Hot Dogs. Which point on your stemplot do you think represents this brand?
What would be your levels of expectancy : Think about the ideal job that you would like to have. Describe this job, the kind of manager you would like to report to, and the kind of organization you would be working in. Answer the following questions: 1. What would be your levels of expect..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd