Q241
Open questionstring s1 = "Hello";
string s2 = "World";
string s3 = (s1+s2).substr(5);Select 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
13/13
Page
Pick an option on a question to see the right answer and solution.
Q241
Open questionstring s1 = "Hello";
string s2 = "World";
string s3 = (s1+s2).substr(5);Select an option to see the answer and solution.
Q242
Open questionSelect an option to see the answer and solution.
Q243
Open question#include <iostream>
#include <string>
using namespace std;
class test
{
public:
operator string ()
{
return "Converted";
}
};
int main()
{
test t;
string s = t;
cout << s << endl;
return 0;
}Select an option to see the answer and solution.
Q244
Open question#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string s('a');
cout<<s;
return 0;
}Select an option to see the answer and solution.
Q245
Open questionSelect an option to see the answer and solution.
Q246
Open question#include <iostream>
using namespace std;
class sample;
class sample1
{
int width, height;
public:
int area ()
{
return (width * height);}
void convert (sample a);
};
class sample
{
private:
int side;
public:
void set_side (int a)
{
side = a;
}
friend class sample1;
};
void sample1::convert (sample a)
{
width = a.side;
height = a.side;
}
int main ()
{
sample sqr;
sample1 rect;
sqr.set_side(6);
rect.convert(sqr);
cout << rect.area();
return 0;
}Select an option to see the answer and solution.
Q247
Open questionSelect an option to see the answer and solution.
Q248
Open questionSelect an option to see the answer and solution.
Q249
Open questionSelect an option to see the answer and solution.
Q250
Open question#include <iostream>
using namespace std;
class Rect
{
int x, y;
public:
void set_values (int,int);
int area ()
{
return (x * y);
}
};
void Rect::set_values (int a, int b)
{
x = a;
y = b;
}
int main ()
{
Rect recta, rectb;
recta.set_values (5, 6);
rectb.set_values (7, 6);
cout << "recta area: " << recta.area();
cout << "rectb area: " << rectb.area();
return 0;
}Select an option to see the answer and solution.
Q251
Open question#include <iostream>
#include <string>
using namespace std;
class complex
{
int i;
int j;
public:
complex(){}
complex(int a, int b)
{
i = a;
j = b;
}
complex operator+(complex c)
{
complex temp;
temp.i = this->i + c.i;
temp.j = this->j + c.j;
return temp;
}
void show(){
cout<<"Complex Number: "<<i<<" + i"<<j<<endl;
}
};
int main(int argc, char const *argv[])
{
complex c1(1,2);
complex c2(3,4);
complex c3 = c1 + c2;
c3.show();
return 0;
}Select an option to see the answer and solution.