What is the output of the program?
#include
#include
using namespace std;
int main()
{
string s1="Hello";
string s2="World";
s1+=s2;
cout << s1;
return( 0 );
}
A. It prints: HelloWorld
B. It prints: Hello
C. It prints: World
D. It prints: HelWorld
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int s(int n);
int main()
{
int a;
a = 3;
cout << s(a);
return 0;
}
int s(int n)
{
if(n == 0) return 1;
return s(n?1)*n;
}
A. It prints: 4
B. It prints: 6
C. It prints: 3
D. It prints: 0
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main(){
int i = 1;
for(i=10; i>-1; i/=2) {
if(!i)
break;
}
cout << i;
return 0;
}
A. It prints: 0
B. It prints: 1
C. It prints: -1
D. Compilation error
What happens when you attempt to compile and run the following code? #include
#include
using namespace std;
class A {
public:
int x;
};
class B : public A {
public:
B() { x=1;}
B(int x) {this?>x = x;}
};
int main () {
B c1;
B c2(10);
cout << c1.x;
cout << c2.x;
return 0;
}
A. It prints: 010
B. It prints: 110
C. It prints: 00
D. It prints: 1
What is the output of the program?
#include
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
void setAge(int a=10) {age = a;}
void Print() { cout << age;}
};
int Base::age=0;
int main () {
Base a,*b;
b = new Base();
a.setAge();
b?>setAge(20);
a.Print();
b?>Print();
return 0;
}
A. It prints: 2020
B. It prints: 1020
C. It prints: 20
D. It prints: 10
What happens when you attempt to compile and run the following code?
A. It prints: 1
B. It causes a compilation error
C. It prints: -1
D. It prints: 0
What happens when you attempt to compile and run the following code?
A. It prints: 5.2110.0
B. It prints: 5.210.0
C. It prints: 52.10
D. It prints: 5210
What will variable "y" be in class B?
class A {
int x;
protected:
int y;
public:
int age;
};
class B : public A {
string name;
public:
void Print() {
cout << name << age;
}
};
A. public
B. private
C. protected
D. None of these
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
int main()
{
string s1[]= {"H" , "t" };
string s;
for (int i=0; i<2; i++) {
s = s1[i];
s.insert(1,"o");
cout << s;
}
return( 0 );
}
A. It prints: Hoto
B. It prints: Ho
C. It prints: to
D. It prints: Ht
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class A {
protected:
int y;
public:
int x;
int z;
A() { x=1; y=2; z=3; }
A(int a, int b) : x(a), y(b) { z = x * y;}
void Print() {
cout << z;
}
};
int main () {
A a(2,5);
a.Print(); return 0; }
A. It prints: 10
B. It prints: 2
C. It prints: 6
D. It prints: 5