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

#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

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

#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

#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

#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

Consider the following three lines:

int a =5;

int &b = a;

b = 7;

What is a?

a.

5

b.

0

c.

7

d.

12

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

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

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

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

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

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]

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

a.

private

b.

public

c.

local

d.

global

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

a.

access specifier

b.

member function

c.

prototype

d.

data member

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

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!