Question

This is my Final Multiple Choice section of my Final Exam Please answer ABCD and neatly...

This is my Final Multiple Choice section of my Final Exam Please answer ABCD and neatly please and thank you and all questions are with microsoft visual studio c++.

MULTIPLE CHOICE. Choose ONLY ONE alternative that best completes the statement or answers the question.

1) Which of the following statements are correct? 1) _______

A) char charArray[2][] = {{'a', 'b'}, {'c', 'd'}}; B) char charArray[2][2] = {{'a', 'b'}, {'c', 'd'}};

C) char charArray[][] = {{'a', 'b'}, {'c', 'd'}};D) char charArray[][] = {'a', 'b'};

2) Which of the following function declaration is correct?2) _______

A) int f(int a[][], int rowSize, int columnSize);

B) int f(int a[][3], int rowSize);

C) int f(int[][] a, int rowSize, int columnSize);

D) int f(int a[3][], int rowSize);

3) What is the output of the following code?

#include <iostream>

using namespace std;

int main()

{

int matrix[4][4] =

{{1, 2, 3, 4},

{4, 5, 6, 7},

{8, 9, 10, 11},

{12, 13, 14, 15}};

int sum = 0;

for (int i = 0; i < 4; i++)

cout << matrix[1][i] << " ";

return 0;

} 3) _______

A) 2 5 9 13 B) 1 2 3 4 C) 4 5 6 7 D) 1 3 8 12 E) 3 6 10 14

4) The keyword ________ is required to declare a class. 4) _______

A) static B) private C) class D) friend E) public

5) When invoking a function with a reference object parameter, ________ is passed. 5) _______

A) the object is copied, then the reference of the copied object

B) a copy of the object

C) the reference of the object

D) the contents of the object

6) You should add the static keyword in the place of ? in which of the following function:

#include <iostream>

using namespace std;

class Test

{

public:

? int square(int n)

{

return n * n;

}

? int getAge()

{

return age;

}

private:

int age;

}; 6) _______

A) in the getAge function

B) in the square function

C) in both lthe square function and the getAge function

D) none

7) If you define the swap function as follows:

template<typename T>

void swap(T &var1, T &var2)

{

T temp = var1;

var1 = var2;

var2 = temp;

}

You can invoke swap using ________. 7) _______

A) int v1 = 1; double v2 = 2; swap(v1, v2); B) swap(1, 2)

C) int v1 = 1; int v2 = 2; swap(&v1, &v2);D) int v1 = 1; int v2 = 2; swap(v1, v2);

8) To open a file in c:\example\scores.txt on Windows, you use ________. 8) _______

A) stream.open("scores.txt"); B) stream.open("c:\example\scores.txt");

C) stream.open("\example\scores.txt"); D) stream.open("c:\\

9) What is the output of the following code?

#include <iostream>

#include <fstream>

using namespace std;

int main()

{

ofstream output;

// Create a file

output.open("scores.txt");

// Write two lines

output << "John" << " " << "T" << " " << "Smith"

<< " " << 90 << endl;

output << "Eric" << " " << "K" << " " << "Jones"

<< " " << 85;

output.close();

ifstream input;

// Open a file

input.open("scores.txt");

// Read data

char firstName[80];

char mi;

char lastName[80];

int score;

input >> firstName >> mi >> lastName >> score;

double sum = score;

input >> firstName >> mi >> lastName >> score;

sum += score;

cout << "Total score is " << sum << endl;

input.close();

return 0;

} 9) _______

A) Total score is 90 B) Total score is 175

C) Total score is 0 D) Total score is 85

10) What is the printout of the following code?

#include <iostream>

#include "Rational.h"

using namespace std;

int main()

{

Rational r1(1, 2);

Rational r2(2, 4);

cout << r1.equals(r2);

return 0;

}

10) ______

A) false B) true C) 0 D) 1

11) What is the correct signature for the overloaded >> operator? 11) ______

A) friend istream operator>>(istream &stream, Rational &rational);

B) friend istream &operator>>(istream &stream, Rational &rational);

C) friend istream &operator>>(istream &stream, const Rational &rational);

D) friend istream operator>>(istream &stream, const Rational &rational);

12) What is the correct signature for the overloaded unary operator +? 12) ______

A) Rational Rational::operator(+)(const Rational &r)

B) Rational Rational::operator+()

C) Rational Rational::operator+(const Rational &r)

D) Rational Rational::operator<+>(const Rational &r)

13) To know whether the I/O operation succeeded, you use the function ________. 13) ______

A) stream.bad()

B) stream.good()

C) stream.fail()

D) stream.eof()

E) stream.clear()

14) To know whether it is the end of a file, you use the function ________. 14) ______

A) stream.fail()

B) stream.bad()

C) stream.clear()

D) stream.good()

E) stream.eof()

15) Are the constructors inherited by the derived class? 15) ______

A) Yes B) No

16) Are the destructors inherited by the derived class? 16) ______

A) Yes B) No

17) What is the printout of the following code?

#include <iostream>

using namespace std;

class C

{

public:

string toString()

{

return "C";

}

};

class B: public C

{

string toString()

{

return "B";

}

};

class A: public B

{

string toString()

{

return "A";

}

};

void displayObject(C *p)

{

cout << p->toString();

}

int main()

{

displayObject(&A());

displayObject(&B());

displayObject(&C());

return 0;

} 17) ______

A) ABC B) AAAC) CCC D) CBAE) BBB

18) What is the printout of the following code?

#include <iostream>

using namespace std;

class C

{

public:

virtual string toString()

{

return "C";

}

};

class B: public C

{

string toString()

{

return "B";

}

};

class A: public B

{

string toString()

{

return "A";

}

};

void displayObject(C *p)

{

cout << p->toString();

}

int main()

{

displayObject(&A());

displayObject(&B());

displayObject(&C());

return 0;

} 18) ______

A) BBB B) ABC C) CCC D) CBAE) AAA

19) What is the printout of the following code?

#include <iostream>

using namespace std;

class C

{

public:

string toString()

{

return "C";

}

};

class B: public C

{

string toString()

{

return "B";

}

};

class A: public B

{

virtual string toString()

{

return "A";

}

};

void displayObject(C *p)

{

cout << p->toString();

}

int main()

{

displayObject(&A());

displayObject(&B());

displayObject(&C());

return 0;

} 19) ______

A) BBB B) CCC C) CBA D) ABC E) AAA

20) If you enter 1 0, what is the output of the following code?

#include <iostream>

using namespace std;

int main()

{

// Read two intergers

cout << "Enter two integers: ";

int number1, number2;

cin >> number1 >> number2;

try

{

if (number2 == 0)

throw number1;

cout << number1 << " / " << number2 << " is "

<< (number1 / number2) << endl;

cout << "C" << endl;

}

catch (int e)

{

cout << "A" << endl;

}

cout << "B" << endl;

return 0;

} 20) ______

A) C B) AB C) A D) B

21) Suppose Exception2 is derived from Exception1. Analyze the following code.

try {

statement1;

statement2;

statement3;

}

catch (Exception1 ex1)

{

}

catch (Exception2 ex2)

{

}

21) ______

A) The program has a runtime error because these two catch blocks are in wrong order.

B) The program has a syntax error because these two catch blocks are in wrong order.

C) If an exception of the Exeception2 type occurs, this exception is caught by the first catch block.

D) If an exception of the Exeception2 type occurs, this exception is caught by the second catch block.

22) Which of the following statements are true? 22) ______

A) A custom exception class must always be derived from class exception.

B) A custom exception class must always be derived from a derived class of class exception.

C) A custom exception class is just like a regular class.

D) A custom exception class must always be derived from class runtime_error.

23) If you are not interested in the contents of an exception object, the catch block parameter may be omitted. 23)

______

A) True B) False

24) What is wrong in the following code?

vector<int> v;

v[0] = 2.5;

24) ______

A) The program has a runtime error because there are no elements in the vector.

B) The program has a syntax error because there are no elements in the vector.

C) The program has a syntax error because you cannot assign a double value to v[0].

D) The program has a runtime error because you cannot assign a double value to v[0].

25) Which of the following is an abstract function? 25) ______

A) virtual double getArea(); B) virtual double getArea();

C) double getArea() = 0;D) virtual double getArea() = 0;

26) Suppose class A is derived from B and both A and B have no-arg constructors. To invoke B's constructor from A, use

________. 26) ______

A) A(): { B(); ... } B) B(): { A(); ... } C) B(): A() { ... } D) A(): B() { ... }

27) Suppose that statement2 throws an exception of type Exception2 in the following statement:

try {

statement1;

statement2;

statement3;

}

catch (Exception1 ex1)

{

}

catch (Exception2 ex2)

{

}

catch (Exception3 ex3)

{

Statement4;

throw;

}

statement5;

Which statements are executed after statement2 is executed? 27) ______

A) statement5

B) statement4

C) statement1

D) statement2

E) statement3

28) If a parameter is a reference variable, this parameter becomes an alias for the original variable. This is referred to as

________. 28) ______

A) pass by reference B) function invocation

C) pass by name D) pass by value

29) Each time a function is invoked, the system stores parameters and local variables in an area of memory, known as

________, which stores elements in last-in first-out fashion. 29) ______

A) storage area B) a stack C) a heap D) an array

30) Analyze the following code:

#include <iostream>

using namespace std;

int xfunction(int n, long t)

{

cout << "int";

return n;

}

long xfunction(long n)

{

cout << "long";

return n;

}

int main()

{

cout << xfunction(5);

}

30) ______

A) The program runs fine but displays nothing.

B) The program displays int followed by 5.

C) The program displays long followed by 5.

D) The program does not compile because the compiler cannot distinguish which xfunction to invoke.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hello i am answering your question hope this will be helpful to you kindly give a thumbs up if it helps you and if you have any doubt regarding the solution do comment.as per the HomeworkLib policy i am bounded to do 1 question of for sub part of the same question so i will answer accordingly for you  1 ,2 , 3 , 4 as you have mentioned.

Answer 1 ) The Answer will be Option B (char charArray[2][2] = {{'a', 'b'}, {'c', 'd'}};)As other have wrong syntax.

Answer 2) The Correct Option is B) int f(int a[][3], int rowSize);

Answer 3) The Output will be C) 4 5 6 7 (As in Cout we are printing 2nd Row)

Answer 4) the correct option is  C) class (class Keyword is used to represent a class)

Happy to help :)

Add a comment
Know the answer?
Add Answer to:
This is my Final Multiple Choice section of my Final Exam Please answer ABCD and neatly...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In the following code, it gets hung up at    cout << "Number1 * Number2 =...

    In the following code, it gets hung up at    cout << "Number1 * Number2 = " << number1 * number2 << endl; giving an error of "no math for operator<<" what am i doing wrong? Thank you #include <iostream> #include <cctype> #include <cstdlib> using namespace std; class Rational //class for rational numbers (1/2, 5/9, ect..) {    public:        Rational(int numerator, int denominator);        Rational(int numberator);        Rational(); //default        friend istream& operator >>(istream& ins,...

  • 61. The following program is accepted by the compiler:         int sum( int x, int y...

    61. The following program is accepted by the compiler:         int sum( int x, int y )         {             int result;             result = x + y;            }                            T__   F__ 62. The following implementation is accepted by the compiler:         void product()         {             int a; int b; int c; int result;             cout << "Enter three integers: ";             cin >> a >> b >> c;             result = a * b * c;            ...

  • Please zoom in so the pictures become high resolution. I need three files, FlashDrive.cpp, FlashDrive.h and...

    Please zoom in so the pictures become high resolution. I need three files, FlashDrive.cpp, FlashDrive.h and user_main.cpp. The programming language is C++. I will provide the Sample Test Driver Code as well as the codes given so far in text below. Sample Testing Driver Code: cs52::FlashDrive empty; cs52::FlashDrive drive1(10, 0, false); cs52::FlashDrive drive2(20, 0, false); drive1.plugIn(); drive1.formatDrive(); drive1.writeData(5); drive1.pullOut(); drive2.plugIn(); drive2.formatDrive(); drive2.writeData(2); drive2.pullOut(); cs52::FlashDrive combined = drive1 + drive2; // std::cout << "this drive's filled to " << combined.getUsed( )...

  • Please use C++ and add comments to make it easier to read. Do the following: 1)...

    Please use C++ and add comments to make it easier to read. Do the following: 1) Add a constructor with two parameters, one for the numerator, one for the denominator. If the parameter for the denominator is 0, set the denominator to 1 2) Add a function that overloads the < operator 3) Add a function that overloads the * operator 4) Modify the operator<< function so that if the numerator is equal to the denominator it just prints 1...

  • NEED ASAP PLEASE HELP Task: --------------------------------------------------------------------------------------...

    NEED ASAP PLEASE HELP Task: --------------------------------------------------------------------------------------------------------------------------------- Tasks to complete: ---------------------------------------------------------------------------------------------------------------------------------------- given code: ----------------------------------------------------------------------------------------------------------------------------------------------- main.cpp #include <iostream> #include <iomanip> #include "fractionType.h" using namespace std; int main() { fractionType num1(5, 6); fractionType num2; fractionType num3; cout << fixed; cout << showpoint; cout << setprecision(2); cout << "Num1 = " << num1 << endl; cout << "Num2 = " << num2 << endl; cout << "Enter the fraction in the form a / b: "; cin >> num2; cout << endl; cout <<...

  • Do the following: 1) Add a constructor with two parameters, one for the numerator, one for...

    Do the following: 1) Add a constructor with two parameters, one for the numerator, one for the denominator. If the parameter for the denominator is 0, set the denominator to 1 2) Add a function that overloads the < operator 3) Add a function that overloads the * operator 4) Modify the operator<< function so that if the numerator is equal to the denominator it just prints 1 5) Modify the operator>> function so that after it reads the denominator...

  • --C++-- --spc16-7.cpp-- // Chapter 16, Programming Challenge 7: TestScores class #include <iostream> #include "TestScores.h" #include "NegativeScore.h"...

    --C++-- --spc16-7.cpp-- // Chapter 16, Programming Challenge 7: TestScores class #include <iostream> #include "TestScores.h" #include "NegativeScore.h" using namespace std; int main() { // Constant for the number of test scores const int NUM_SCORES = 5;       try    {        // Create an array of valid scores.        int myScores[NUM_SCORES] = { 88, 90, 93, 87, 99 };        // Create a TestScores object.        //TestScores myTestScores(myScores, NUM_SCORES); // optional constructor        TestScores myTestScores(myScores);...

  • Need help with a multiple inheritance work Question Compile and run the file. If you find...

    Need help with a multiple inheritance work Question Compile and run the file. If you find any compilation errors,explain their reason as comments in the code. Then fix the errors such that the program compiles and runs. Explain the motivation of your modifications in the code and their effects on the execution inheritance.cpp file #include<iostream> using namespace std; class A { int x; public: void setX(int i) {x = i;} void print() { cout << x; } }; class B:...

  • The following program contains the definition of a class called List, a class called Date and...

    The following program contains the definition of a class called List, a class called Date and a main program. Create a template out of the List class so that it can contain not just integers which is how it is now, but any data type, including user defined data types, such as objects of Date class. The main program is given so that you will know what to test your template with. It first creates a List of integers and...

  • Having to repost this as the last answer wasn't functional. Please help In the following program...

    Having to repost this as the last answer wasn't functional. Please help In the following program written in C++, I am having an issue that I cannot get the reducdedForm function in the Rational.cpp file to work. I cant figure out how to get this to work correctly, so the program will take what a user enters for fractions, and does the appropriate arithmetic to the two fractions and simplifies the answer. Rational.h class Rational { private: int num; int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT