What happens when you attempt to compile and run the following code?
#include
using namespace std;
class First
{
public:
void Print(){ cout<<"from First";}
};
class Second:public First
{
public:
void Print(){ cout<< "from Second";}
};
void fun(First *obj);
int main()
{
First FirstObject;
fun(&FirstObject);
Second SecondObject;
fun(&SecondObject);
}
void fun(First *obj)
{
obj?>Print();
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class A
{
public:
virtual void Print()=0;
};
class B:public A
{
public:
virtual void Print(){ cout<< "B";}
};
int main()
{
B ob2;
A *obj;
obj = &ob2;
obj?>Print();
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class Base {
int age;
public:
class C {
int b;
void PrintC() { cout << b; }
};
Base () {age=5;};
void setAge(int a=20) {age = a;}
void Print() { cout << age;}
};
int main () {
Base a;
a.setAge(10);
a.Print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class A {
public:
void Print(){ cout<<"A";}
};
class C:public A {
public:
virtual void Print()=0;
};
int main()
{
C obj3;
obj3?>Print();
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int compare(int, int);
int main()
{
int x = compare(10, 20);
cout << x;
return 0;
}
int compare(int i, int j)
{
return i }
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class First
{
public:
void Print(){ cout<<"from First";}
};
class Second
{
public:
void Print(){ cout<< "from Second";}
};
int main()
{
Second t[2];
for (int i=0; i<2; i++)
t[i].Print();
}
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, z;
A() : x(1), y(2), z(0) {}
A(int a, int b) : x(a), y(b) { z = x * y;}
void Print() { cout << z; }
};
class B : public A {
public:
int y;
B() : A() {}
B(int a, int b) : A(a,b) {}
void Print() { cout << z; }
};
int main () {
A b(2,5);
b.Print();
return 0;
}
What will the variable "y" be in class B?
class A {
int x;
protected:
int y;
public:
int age;
};
class B : protected A {
string name;
public:
void Print() {
cout << name << age;
}
};
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
int i = 0;
do {
i++;
if (i==3)
break;
cout<
}
while(i < 5);
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
void print(char *c);
int main (int argc, const char * argv[])
{
print("Test");
return 0;
}
void print(char *c)
{
cout< }
Which of the following is a correct way to define the function fun() in the program below?
#include
#include
#include
using namespace std;
int main()
{
int a[2][2];
fun(a);
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class First
{
string *s;
public:
First() { s = new string("Text");}
~First() { delete s;}
void Print(){ cout<<*s;}
};
int main()
{
First FirstObject;
FirstObject.Print();
FirstObject.~First();
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
int x=0;
int *ptr;
ptr = &x;
cout< return 0; }
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
int x,y=10;
float f;
f = 5.20;
x=(int) f;
cout << x <<", ";
f=float (y);
cout << f;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class First
{
public:
void Print(){ cout<<"from First";}
};
class Second
{
public:
void Print(){ cout<< "from Second";}
};
int main()
{
First FirstObject;
FirstObject.Print();
Second SecondObject;
SecondObject.Print();
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
#define DEF_A 0
#define DEF_B DEF_A+1
#define DEF_C DEF_B+1
int main(int argc, char *argv[]) {
cout << DEF_C;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class Test {
float i,j;
};
class Add {
public:
int x,y;
Add (int a=3, int b=3) { x=a; y=b; }
int result() { return x+y;}
};
int main () {
Test test;
Add * padd;
padd = &test;
cout << padd?>result();
return 0;
}
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 );
}
What is the output of the program?
#include
#include
using namespace std;
int main()
{
string s1="World";
string s2;
s2="Hello" + s1;
cout << s2;
return( 0 );
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int min(int a, int b);
int main()
{
int b=10;
b = min(5,20);
cout << b;
return 0;
}
int min(int a, int b)
{
if (a
return(a);
else
return(b);
}
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;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int x=5;
static int y;
int i=0;
void static myFunction()
{
y=x++ + ++i;
}
int main (int argc, const char * argv[])
{
x++;
myFunction();
cout< }
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double x) { re=x,im=x;};
complex(double x,double y) { re=x,im=y;}
void print() { cout << re << " " << im;}
};
int main(){
complex c1(1,2);
c1.print();
return 0;
}
What will the variable "age" be in class B?
class A {
int x;
protected:
int y;
public:
int age;
};
class B : protected A {
string name;
public:
void Print() {
cout << name << age;
}
};
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double x) { re=x,im=x;};
complex(double x,double y) { re=x,im=y;}
void print() { cout << re << " " << im;}
};
int main(){
complex c1;
double i=2;
c1 = i;
c1.print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int op(int x, int y);
int main()
{
float *pf;
float f=0.9;
pf=&f;
cout << op(1, *pf);
return 0;
}
int op(int x, int y)
{
return x*y;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
namespace myNamespace1
{
int x = 5;
int y = 10;
}
namespace myNamespace2
{
float x = 3.14;
float y = 1.5;
}
int main () {
{
using namespace myNamespace1;
cout << x << " ";
}{
using namespace myNamespace2;
cout << y;
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main(int argc, char *argv[]) {
char *s = "ABCDEF";
cout << s+2;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class SampleClass
{
string *s;
public:
SampleClass() { s = new string("Text");}
SampleClass(string s) { this?>s = new string(s);}
~SampleClass() { delete s;}
void Print(){ cout<<*s;}
};
int main()
{
SampleClass *obj;
obj = new SampleClass("Test");
obj?>Print();
}