Question 5 #include<iostream> using namespace std; char v_operator; int main() {
ID: 3839760 • Letter: Q
Question
Question 5
#include<iostream>
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?
continue
for loop
while loop
d.
if else
Question 6
What is the equivalent of default when rewriting the code above, question 6, with if else statements?
if else
else
if
break
Question 7
#include <iostream>
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?
num
x
ratio
class
Question 8
#include <iostream>
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?
0
2
4
6
Question 9
#include <iostream>
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 ?
cout << x.num + x.den << endl; and change public to private
cout << x.num + x.den << endl; and change private to public
cout << num +den << endl;
cin >> x.num + x.den
Question 10
Consider the following three lines:
int a =5;
int &b = a;
b = 7;
What is a?
5
0
7
12
Question 11
Consider the following function: int myfunc(int a, int b =3) {return a+b;}
What is myfunc(4)?
3
7
Returns an Error Message
4
Question 12
Consider the following function: int myfunc(int a, int b =3) {return a+b;}
What is myfunc(4, 5)?
Returns an Error Message
9
8
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;}
testingFactorial
testing_Even_odd
testingPallindrome
testingPrime
Question 14
Consider the statement: float a[7] = { 22.2, 44.4, 66.6 }; What is a[[3]
66.6
0
7
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 << "] = " <<v[i] <<="" <span="" class="mceItemHiddenSpellWord">endl;
}
1.0
0.5
0.25
033
Question 16
vector<int>num;
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:
num.at(4)
num.back()
num.last()
num[3]
Question 17
In a class, the default access specifier of member functions is:
private
public
local
global
Question 18
Consider the expression Game.start(), where Game is a class. What is start?
access specifier
member function
prototype
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.
for loop
while loop
if else
switch case
Question 20
What is the following instruction doing? Int nCount [ ] = {1, 2, 3};
declare and initialize an array of 3 elements
declare an array of 2 elements
declare a vector of 2 elements
create a 1 by 2 by 3 array
a.continue
b.for loop
c.while loop
d.
if else
Explanation / Answer
Question 5
Answer:d.if else
Question 6
Answer:b.else
Question 7
Answer: b.x
Question 8
Answer: c. 4
Question 9
Answer: b. cout << x.num + x.den << endl; and change private to public
Question 10
Answer: c. 7
Question 11
Answer: b. 7
Question 12
Answer: b. 9
Question 13
Answer: b. testing_Even_odd
Question 14
Answer: b. 0
Question 15
Answer: c. 0.25
Question 16
Answer: b.num.back()
d. num[3]
Question 17
Answer: a. private
Question 18
Answer:b. member function
Question 19
Answer:
a.
for loop
b.
while loop
Question 20
Answer:
a. declare and initialize an array of 3 elements
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.