Test 2 Practice Form A - Engineering Problem Solving with C++ | ENGE 2314, Exams of Statistics

Test 2 Practice Form A Material Type: Exam; Professor: Walker; Class: Engrg Prob Solving: C++; Subject: Engineering Education; University: Virginia Polytechnic Institute And State University; Term: Fall 2006;

Typology: Exams

Pre 2010

Uploaded on 12/05/2006

kharaalderia
kharaalderia 🇺🇸

2 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ENGE 2314 OLD TEST 2 For study Form A Page 1 of 9
1. Examine the following prototype and choose the most true answer:
ostream& operator<< (ostream&, const Box&);
1. The prototype refers to an overloaded definition of the << operator that is
defined in the class named “const”.
2. The corresponding function definition of the above prototype returns
nothing.
3. If the corresponding function definition attempts to alter the values of the
private data members of the Box object, the code will not compile.
4. The prototype has a syntax error.
5. The keyword const is the name of a built-in data type
6. The parameters are being passed to the function by value.
7. Statements (1) and (2) are correct
8. Statements (2) and (3) are correct
9. Statements (3) and (5) are correct
10. Statements (1) and (3) are correct
2. Which two-statement sequence is equivalent to this three-statement sequence?
x = y * 10; y = y + 1; z = z * (y + 5);
(1) x = y + 1 * 10; z *= y * 5;
(2) x = y + 1 * 10; z = ++y + 5 * z;
(3) x = ++y * 10; z *= y + 5;
(4) x = ++y * 10; z = ++x - 1;
(5) x = y++ * 10; z *= y + 5;
(6) x = y++ * 10; z = ++y + 5;
(7) y = z + 1 * 10; x = z-- * y + 5;
(8) y = z + 1 * 10; x = ++y + 5 * --z;
(9) y *= 10 + x ++ 10; z *= y + 5;
(10) y *= 10 + x ++ 10; z = y++ + 5 * z;
3. What output is displayed by this statement if the value of x is -33.963?
(# designates a space, . designates a period)
cout << setiosflags(ios::fixed|ios::showpoint)
<< setprecision(2) << setw(10) << x << endl;
(1) ###-33.963
(2) -33.963###
(3) ##-33.96##
(4) -...33.963
(5) -....33.96
(6) -33.96####
(7) -33.######
(8) ######-33.
(9) ####-33.96
(10) ...-33.96
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Test 2 Practice Form A - Engineering Problem Solving with C++ | ENGE 2314 and more Exams Statistics in PDF only on Docsity!

  1. Examine the following prototype and choose the most true answer: ostream& operator<< (ostream&, const Box&); 1. The prototype refers to an overloaded definition of the << operator that is defined in the class named “const”. 2. The corresponding function definition of the above prototype returns nothing. 3. If the corresponding function definition attempts to alter the values of the private data members of the Box object, the code will not compile. 4. The prototype has a syntax error. 5. The keyword const is the name of a built-in data type 6. The parameters are being passed to the function by value. 7. Statements (1) and (2) are correct 8. Statements (2) and (3) are correct 9. Statements (3) and (5) are correct 10. Statements (1) and (3) are correct
  2. Which two-statement sequence is equivalent to this three-statement sequence?

x = y * 10; y = y + 1; z = z * (y + 5); (1) x = y + 1 * 10; z *= y * 5; (2) x = y + 1 * 10; z = ++y + 5 * z; (3) x = ++y * 10; z *= y + 5; (4) x = ++y * 10; z = ++x - 1; (5) x = y++ * 10; z *= y + 5; (6) x = y++ * 10; z = ++y + 5; (7) y = z + 1 * 10; x = z-- * y + 5; (8) y = z + 1 * 10; x = ++y + 5 * --z; (9) y *= 10 + x ++ 10; z *= y + 5; (10) y *= 10 + x ++ 10; z = y++ + 5 * z;

  1. What output is displayed by this statement if the value of x is -33.963? (# designates a space,. designates a period) cout << setiosflags(ios::fixed|ios::showpoint) << setprecision(2) << setw(10) << x << endl; (1) ###-33. (2) -33.963### (3) ##-33.96## (4) -...33. (5) -....33.
  1. How many lines of output will be displayed by the following program fragment?

for (int i=0; i<5; i++) for (int j=0; j<i; ++j) cout << i << j << endl; (1) 4 (2) 5 (3) 6 (4) 9 (5) 10

  1. Which statement is most true? (1) The local variable of a function is not visible in a separate function existing outside the definition of the function declaring the local variable. (2) The statement double sum (double x, y); is a valid prototype. (3) Function prototypes are always required for all functions that are defined. (4) Statements (1) and (2) are true. (5) Statements (2) and (3) are true. (6) Statements (1) and (3) are true. (7) Statements (1), (2), and (3) are true. (8) All the above statements are false.
  2. A function that does not return a value to the calling statement, is commonly referred to as a(n) function. (1) dummy (2) empty (3) holding (4) null (5) placebo

(6) pointless (7) prototype (8) returnless (9) valueless (10) void

  1. The method of passing the storage location of a variable as an argument to a function, is called pass-by-. (1) copy (2) image (3) indirection (4) guide (5) prototype

(6) proxy (7) reference (8) storage (9) value (10) wire

  1. What is the output of this program?

#include #include using namespace std; void doSomething ( int& green, int brown ) { int red = 5; brown = 2 + red; green = red * brown; }

int main () { int blue = 1; int pink = 2; doSomething ( pink, blue ); cout <<setw(4) << blue << setw(4) << pink << endl; return 0; } (1) 1 2 (2) 1 7 (3) 1 35 (4) 2 2 (5) 2 7

  1. Which statement is most true? (1) The following two lines in the same program will cause a compile error: int MyFunc (int x) { return (double) x; } double MyFunc (int x) { return (double) x; } (2) The following two lines in the same program will cause a compile error: int MyFunc (double x) { return (int) x; } double MyFunc (double x) { return (double) x; } (3) The following two lines in the same program will cause a compile error: int MyFunc (double x) { return (int) x; } double MyFunc (int x) { return (double) x; } (4) Statements (1) and (2) are true. (5) Statements (2) and (3) are true. (6) Statements (1) and (3) are true. (7) Statements (1), (2), and (3) are true. (8) All the above statements are false.
  1. A programmer wrote an operator overloading function to overload the * operator in a certain class. The name of this function must be: (1) ostream& (2) operator* (3) ostream& operator* (4) operator(ostream&) (5) istream& (6) istream& operator (7) istream& operator* (istream&, object name &) (8) ostream& operator* (ostream&, object name &) (9) operator*(istream&) (10) none of the above
  2. A class Myclass has a member function Free that takes no parameters, returns an integer value, and can not modify any of the private data members. Which of the following would be the most correct function prototype for the Free member function in the class declaration?

(1) int Free() const; (2) const int Myclass::Free(); (3) int Myclass::Free() const; (4) Myclass::int Free(); (5) const int Free() const; (6) void Free() const; (7) const int Free(); (8) none of the above

  1. Suppose you wrote a class named Box and instantiated two objects of this class called Redbox and Bluebox. Now you want to create another object of this class by adding these two boxes. The best way to add this functionality would be to:

(1) Define new data members (2) Write a member function, AddBoxes, for adding the data members (3) Write an operator overloading member function for the “+” operator (4) Create a larger object by calling the constructor function of class Box and initializing the data members appropriately for the new size box (5) Define a new class, Double_Box, and initialize it with the sum of Redbox and Bluebox (6) You don’t have to do anything, in the driver program you can just write “Box Thirdbox = Redbox + Bluebox;” (7) None of the above

  1. The following driver program generates a compile time error because: (remember to use class definition above question 16) int main() { Hokies X, Y; //Line 1 X.K = 8.0; //Line 2 return 0; }
  2. Two objects, X and Y, are instantiated on the same line
  3. The return value should be 8 instead of 0
  4. The data member K is a private data member
  5. Both statements 2 and 3 above are valid causes of compilation errors
  6. Both statements 1 and 2 above are valid causes of compilation errors
  7. Both statements 1 and 3 above are valid causes of compilation errors
  8. What does this C++ program display? #include using namespace std; int function (int& b, int c) { int a = 1; b = 2; c = 3; return 4; } int main () { int a = 10, b = 11, c = 12, d = 13; d = function ( b, c ); cout << a << " "; cout << b << " "; cout << c << " "; cout << d << endl; return 0; } (1) 1 2 3 4 (2) 1 2 12 4 (3) 1 11 12 13 (4) 1 11 3 13 (5) 10 2 3 4
  1. What does this C++ program display?

#include #include using namespace std; int test2 (int y) { return 0; } int test2 (double yy) { return (int) sqrt(yy); } double TEST2 (int y) { return 0.0; } double TEST2 (double yy) { return sqrt(yy); } int main () { int y = 4; double yy = 9.0; cout << test2 (16) << endl; return 0; } (1) No output. (2) 0 (3) 0. (4) 2 (5) 2.

(10) Program will not compile.

Consider the following class declaration for answering questions 22 – 24:

class Someclass // Line 1 { // Line 2 public: // Line 3 void Func1(int n);// Line 4 int Func2()const; // Line 5 int Someclass(); // Line 6 private: // Line 7 int privateint; // Line 8 }; // Line 9

  1. The line that causes a compile error is:
  1. Line 1 2) Line 4 3) Line 6 4) Line 8
  2. Line 4 and 6 6) Line 4 and 8 7) Line 6 and 8 8) No compile error
  1. The purpose of function Func1 is to set the value of the private data member. The definition of this member function would best be:
  1. int Func1(int a) { privateint = a;}

  2. void Func1(int ) { privateint = int;}

  3. void Func1(int b) { privateint = a;}

  4. int Func1(int n) { n = privateint;}

  5. void Func1(int k) { privateint = k;}