Q161
Open questionSelect an option to see the answer and solution.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
251
Questions
9/13
Page
Pick an option on a question to see the right answer and solution.
Q161
Open questionSelect an option to see the answer and solution.
Q162
Open questionSelect an option to see the answer and solution.
Q163
Open questionSelect an option to see the answer and solution.
Q164
Open questionSelect an option to see the answer and solution.
Q165
Open question#include <iostream>
using namespace std;
int main()
{
double arr[] = {5.0, 6.0, 7.0, 8.0};
double *p = (arr+2);
cout << *p << endl;
cout << arr << endl;
cout << *(arr+3) << endl;
cout << *(arr) << endl;
cout << *arr+9 << endl;
return 0;
}Select an option to see the answer and solution.
Q166
Open question#include <iostream>
#include <string>
using namespace std;
class B
{
int b;
public:
B(){}
B(int i){
b = i;
}
int show(){
return b;
}
};
class C
{
B b;
public:
C(int i){
b = B(i);
}
friend void show(){
C c(10);
cout<<"value of b is: "<<c.b.show()<<endl;
}
};
int main(int argc, char const *argv[])
{
C c(1);
c.show();
return 0;
}Select an option to see the answer and solution.
Q167
Open questionway 1:
string s;
s = s + 'a';
way 2:
string s;
s.push_back('a');Select an option to see the answer and solution.
Q168
Open question#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
string s1 = "Hello";
string s2 = "World";
string s3 = s1 + " " + s2;
cout<<s3;
return 0;
}Select an option to see the answer and solution.
Q169
Open questionSelect an option to see the answer and solution.
Q170
Open questionSelect an option to see the answer and solution.
Q171
Open question#include <iostream>
#include <string>
using namespace std;
class Box
{
int capacity;
public:
Box(int cap){
capacity = cap;
}
friend void show();
};
void Box::show()
{
Box b(10);
cout<<"Value of capacity is: "<<b.capacity<<endl;
}
int main(int argc, char const *argv[])
{
show();
return 0;
}Select an option to see the answer and solution.
Q172
Open question#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("steve jobs is legend");
string::iterator it;
str.erase (str.begin()+ 5, str.end()-7);
cout << str << endl;
return 0;
}Select an option to see the answer and solution.
Q173
Open question#include <iostream>
using namespace std;
class A
{
public:
int x;
A(int n = 0) : x(n) {};
int& operator[](int n)
{
cout << "0" ;
return x;
}
int operator[](int n) const
{
cout << "1" ;
return x;
}
};
void foo(const A& a)
{
int z = a[2];
}
int main()
{
A a(7);
a[3] = 8;
int z = a[2];
foo(a);
return 0;
}Select an option to see the answer and solution.
Q174
Open question#include <iostream>
using namespace std;
class Box
{
double width;
public:
friend void printWidth( Box box );
void setWidth( double wid );
};
void Box::setWidth( double wid )
{
width = wid;
}
void printWidth( Box box )
{
box.width = box.width * 2;
cout << "Width of box : " << box.width << endl;
}
int main( )
{
Box box;
box.setWidth(10.0);
printWidth( box );
return 0;
}Select an option to see the answer and solution.
Q175
Open question#include <iostream>
using namespace std;
class Complex
{
private:
float real;
float imag;
public:
Complex():real(0), imag(0){}
Complex operator ()(float re, float im)
{
real += re;
imag += im;
return *this;
}
Complex operator() (float re)
{
real += re;
return *this;
}
void display()
{
cout << "(" << real << "," << imag << ")" << endl;
}
};
int main()
{
Complex c1, c2;
c2 = c1(3.2, 5.3);
c1(6.5, 2.7);
c2(1.9);
cout << "c2=";c1.display();
cout << "c2=";c2.display();
return 0;
}Select an option to see the answer and solution.
Q176
Open question#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex<double> c1(4.0, 3.0);
complex<float> c2(polar(5.0, 0.75));
cout << (c1 += sqrt(c1)) << endl;
return 0;
}Select an option to see the answer and solution.
Q177
Open questionSelect an option to see the answer and solution.
Q178
Open question#include <iostream>
#include <string>
using namespace std;
class Box
{
int capacity;
Box(){}
Box(double capacity){
this->capacity = capacity;
}
};
int main(int argc, char const *argv[])
{
Box b1(10);
Box b2 = Box(14);
return 0;
}Select an option to see the answer and solution.
Q179
Open question#include <iostream>
#include <string>
using namespace std;
class B
{
int b;
public:
B(){}
B(int i){
b = i;
}
int show(){
return b;
}
};
class C
{
B b;
public:
C(int i){
b = B(i);
}
friend void show(){
C c(10);
cout<<"value of b is: "<<c.b.show()<<endl;
}
};
int main(int argc, char const *argv[])
{
show();
return 0;
}Select an option to see the answer and solution.
Q180
Open question#include <iostream>
#include <string>
using namespace std;
class Box{
int capacity;
public:
Box(){}
Box(double capacity){
this->capacity = capacity;
}
};
int main(int argc, char const *argv[])
{
Box b1(10);
Box b2 = Box(14);
if(b1 == b2){
cout<<"Equal";
}
else{
cout<<"Not Equal";
}
return 0;
}Select an option to see the answer and solution.