#include<iostream> using namespace std; char v_operator; int main() { cout << \"
ID: 3839751 • Letter: #
Question
#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
if else
What is the equivalent of default when rewriting the code above, question 6, with if else statements?
if else
else
if
break
#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
#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
#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
Consider the following three lines:
int a =5;
int &b = a;
b = 7;
What is a?
5
0
7
12
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
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
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
Consider the statement: float a[7] = { 22.2, 44.4, 66.6 }; What is a[[3]
66.6
0
7
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 << "] = " <<v[i] <<="" <span="" class="mceItemHiddenSpellWord">endl;
}
1.0
0.5
0.25
033
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]
In a class, the default access specifier of member functions is:
private
public
local
global
Consider the expression Game.start(), where Game is a class. What is start?
access specifier
member function
prototype
data member
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
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
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 <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?
a.num
b.x
c.ratio
d.class
#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?
a.0
b.2
c.4
d.6
#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 ?
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
Explanation / Answer
1. if else - this block can be used to control which operators is preferred or selected.
2. else is equivalenet to default.
3. x is the object of class Ratio
4. 6 - 4functions and 2 data members.
5. b ) cout << x.num + x.den << endl; and change private to public - by making it public they can be accesed directly.
6. 5 as a's value is not changed and in the second last line it is at right side.
7. 7 is the answer
8. 9 - value 3 will be overridden by 5.
9. testingFactorial - the function is used to check if it hasfactors.
10. 0 , as array starts form 0 and right now only values have till position 2.
11. 0.25 i.e. 1/4 is 0.25
12. num[3] - push back is used to insert element at last. here 4th element will be inserted in position 3 as position starts from 0.
13.a)private... default access specifier for data members and functions is private.
14) member function - -Game.start() is statement used to call the start function of Game object.
15) a) for loop and while loop is used to print numbers from -3 to 4 as we need some loop structure here and they are the best choice.
16) a) declare and initialize array of 3 elements .. i.e. array nCount is declared and initialized with 3 values 1,2 and 3.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.