Question: Question 5 #include using namespace std; char v_operator; int main() { cout < < Enter your preferred operator < < endl; cin >>

Question 5

#include

using namespace std;

char v_operator;

int main()

{

cout << " Enter your preferred operator "

<< endl;

cin >> v_operator;

switch(v_operator)

{

case '+':

cout << " addition " << endl; break;

case '-':

cout << " subtraction " << endl; break;

case '*':

cout << " multiplication " << endl; break;

case '/':

cout << " division " << endl; break;

case '%':

cout << " modulo " << endl; break;

default:

cout << " unknown operator " << endl;

}

return 0;

}

This code right above can be best rewritten using which of the following control structure?

a.

continue

b.

for loop

c.

while loop

d.

if else

Question 6

What is the equivalent of default when rewriting the code above, question 6, with if else statements?

a.

if else

b.

else

c.

if

d.

break

Question 7

#include

using namespace std;

class Ratio { public: void assign(int, int);

double convert();

void invert();

void print();

private: int num, den; };

int main()

{ Ratio x; x.assign(22,7);

cout << "x = "; x.print();

cout << " = " << x.convert() << endl;

x.invert();

cout << "1/x = ";

x.print();

cout << endl;

}

void Ratio::assign(int numerator, int denominator) { num = numerator; den = denominator; }

double Ratio::convert() { return double(num)/den; }

void Ratio::invert() { int temp = num; num = den; den = temp; }

void Ratio::print() { cout << num << '/' << den; }

For this code right above, what is the object?

a.

num

b.

x

c.

ratio

d.

class

Question 8

#include

using namespace std;

class Ratio { public: void assign(int, int);

double convert();

void invert();

void print();

private: int num, den; };

int main()

{ Ratio x; x.assign(22,7);

cout << "x = "; x.print();

cout << " = " << x.convert() << endl;

x.invert();

cout << "1/x = ";

x.print();

cout << endl;

}

void Ratio::assign(int numerator, int denominator) { num = numerator; den = denominator; }

double Ratio::convert() { return double(num)/den; }

void Ratio::invert() { int temp = num; num = den; den = temp; }

void Ratio::print() { cout << num << '/' << den; }

For this code right above, how many members (data or functions) are there?

a.

0

b.

2

c.

4

d.

6

Question 9

#include

using namespace std;

class Ratio { public: void assign(int, int);

double convert();

void invert();

void print();

private: int num, den; };

int main()

{ Ratio x; x.assign(22,7);

cout << "x = "; x.print();

cout << " = " << x.convert() << endl;

x.invert();

cout << "1/x = ";

x.print();

cout << endl;

}

void Ratio::assign(int numerator, int denominator) { num = numerator; den = denominator; }

double Ratio::convert() { return double(num)/den; }

void Ratio::invert() { int temp = num; num = den; den = temp; }

void Ratio::print() { cout << num << '/' << den; }

For this code, how to print 22 +7 ?

a.

cout << x.num + x.den << endl; and change public to private

b.

cout << x.num + x.den << endl; and change private to public

c.

cout << num +den << endl;

d.

cin >> x.num + x.den

Question 10

Consider the following three lines:

int a =5;

int &b = a;

b = 7;

What is a?

a.

5

b.

0

c.

7

d.

12

Question 11

Consider the following function: int myfunc(int a, int b =3) {return a+b;}

What is myfunc(4)?

a.

3

b.

7

c.

Returns an Error Message

d.

4

Question 12

Consider the following function: int myfunc(int a, int b =3) {return a+b;}

What is myfunc(4, 5)?

a.

Returns an Error Message

b.

9

c.

8

d.

7

Question 13

In which function will you encounter the following lines:

for(int i = 2; i<=sqrt; i++)

{if (n%i == 0)

return true;

else

return false;}

a.

testingFactorial

b.

testing_Even_odd

c.

testingPallindrome

d.

testingPrime

Question 14

Consider the statement: float a[7] = { 22.2, 44.4, 66.6 }; What is a[[3]

a.

66.6

b.

0

c.

7

d.

44.4

Question 15

Consider the following. What is v[3] after running this program:

float& component(float* v, int k) { return v[k-1]; }

int main()

{

float v[4];

for (int k = 1; k <= 4;k++)

component(v,k) = 1.0/k;

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

cout << "v[" << i << "] = " <endl;

}

a.

1.0

b.

0.5

c.

0.25

d.

033

Question 16

vectornum;

num.push_back(1);

num.push_back(2);

num.push_back(3);

num.push_back(4);

Select 2 expressions equivalent to 4 in this code:

a.

num.at(4)

b.

num.back()

c.

num.last()

d.

num[3]

Question 17

In a class, the default access specifier of member functions is:

a.

private

b.

public

c.

local

d.

global

Question 18

Consider the expression Game.start(), where Game is a class. What is start?

a.

access specifier

b.

member function

c.

prototype

d.

data member

Question 19

You want to print from -3 up to 4. Which ones of these control structure will you utilize? Select 2 best answers.

a.

for loop

b.

while loop

c.

if else

d.

switch case

Question 20

What is the following instruction doing? Int nCount [ ] = {1, 2, 3};

a.

declare and initialize an array of 3 elements

b.

declare an array of 2 elements

c.

declare a vector of 2 elements

d.

create a 1 by 2 by 3 array

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!