Classes And Objects In C Plus Plus - Study Mode

[#186] Which of the following is correct way of concatenating two string objects in C++? way 1:
string s1 = "hello"
string s2 = "world"
string s3 = s1 + s2
way 2:
string s1 = "hello"
string s2 = "world"
string s3 = s1.append(s2)
way 3:
string s1 = "hello"
string s2 = "world"
string s3 = strcat(s1,s2)
Correct Answer

(A) 1 and 2

[#187] What will be the output of the following C++ code? #include <iostream>
using namespace std
class sample
{
private:
int a, b
public:
void test()
{
a = 100
b = 200
}
friend int compute(sample e1)
}
int compute(sample e1)
{
return int(e1.a + e1.b) - 5
}
int main()
{
sample e
e.test()
cout << compute(e)
return 0
}
Correct Answer

(D) 295

[#188] What will be the output of the following C++ code? #include <iostream>
#include <complex>
using namespace std
int main()
{
complex<double> c1(4.0,3.0)
cout << "c1: " << c1
complex<float> c2(polar(5.0,0.75))
cout << c1 + complex<double>(c2.real(),c2.imag())
return 0
}
Correct Answer

(A) c1: (4,3)(7.65844,6.40819)

[#189] What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
int x
int *p
x = 5
p = &x
cout << *p
return 0
}
Correct Answer

(A) 5

[#190] What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
int i
enum month
{
JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,DEC
}
for (i = JAN
i <= DEC
i++)
cout << i
return 0
}
Correct Answer

(A) 012345678910