What happens if character 3 is entered as input?
#include
using namespace std;
class A {
public:
int i;
};
int main () {
int c;
A obj;
obj.i = 5;
cin >> c;
try
{
switch (c)
{
case A. throw 20;
case B. throw 5.2f;
case C. throw obj;
default: cout<<"No exception";
}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }
catch (A e)
{ cout << "object exception. Exception Nr. " << e.i; }
catch (...)
{ cout << "An exception occurred."; }
return 0;
}
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 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;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class BaseC
{
int *ptr;
public:
BaseC() { ptr = new int(10);}
BaseC(int i) { ptr = new int(i); }
~BaseC() { delete ptr; }
void Print() { cout << *ptr; }
};
int main()
{
BaseC *o = new BaseC(5);
o?>Print();
}
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class A {
int x;
protected:
int y;
public:
int z;
A() { x=1; y=2; z=3; }
};
class B : public A {
string z;
public:
void set() {
y = 4;
z = "John";
}
void Print() {
cout << y << z;
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class A
{
public:
virtual void Print(){ cout<<"A";}
};
class B:public A
{
public:
void Print(){ cout<< "B";}
};
int main()
{
A *obj;
A ob1;
obj = &ob1;
obj?>Print();
B ob2;
obj = &ob2;
obj?>Print();
}
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 );
}
What is the output of the program given below?
#include
using namespace std;
int main (int argc, const char * argv[])
{
int i=10;
{
int i=0;
cout<
}
{
int i=5;
cout << i;
}
cout<
return 0;
}
Which statement should be added in the following program to make work it correctly?
using namespace std;
int main (int argc, const char * argv[])
{
cout<<"Hello";
}
What will happen when you attempt to compile and run the following code?
#include
using namespace std;
int getValue();
int main()
{
const int x = getValue();
cout< return 0; } int getValue() { return 5; }
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int fun(int x) {
return x<<2;
}
int main(){
int i;
i = fun(1) / 2;
cout << i;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
int *t;
t = new int[2];
for (int i=0; i<2; i++) {
t[i]=0;
}
cout << t[1];
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main (int argc, const char * argv[])
{
int x,y;
union t
{
char tab[2];
int i;
};
union t u;
u.tab[0] = 1;
u.tab[1] = 2;
u.i = 0;
x = u.tab[0];
y = u.tab[1];
cout << x << "," << y << "," << u.i;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main(void)
{
string s;
s = "Test";
s.resize (s.size() ? 1);
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;
int main()
{
int x=20;
int *ptr;
ptr = &x;
cout<<*ptr;
return 0;
}
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) { z = x + y; }
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;
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
#include
using namespace std;
class complex{
double re;
double im;
public:
complex() : re(1),im(0.4) {}
bool operator==(complex &t);
};
bool complex::operator == (complex &t){
if((this?>re == t.re) && (this?>im == t.im))
return true;
else
return false;
}
int main(){
complex c1,c2;
if (c1==c2)
cout << "OK";
else {
cout << "ERROR";
}
}
What is the output of the program if character “1” is supplied as input?
#include
using namespace std;
int main () {
int c;
cin >> c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
case 3:
throw 'a';
}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }
catch (float e)
{ cout << "float exception. Exception Nr. " << e; }
catch (...)
{ cout << "An exception occurred."; }
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()
{
Second t[2];
for (int i=0; i<2; i++)
t[i].Print();
}
What will happen when you attempt to compile and run the following code?
#include
#include
using namespace std;
int fun(int);
int main()
{
int *x = new int;
*x=10;
cout << fun(*x);
return 0;
}
int fun(int i)
{
return i*i;
}
Which code, inserted at line 12, generates the output "5b"?
#include
using namespace std;
namespace myNamespace1
{
int var = 5;
}
namespace myNamespace2
{
char var = 'b';
}
int main () {
//insert code here
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();
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
int i = 5;
cout<<"Hello World" << ++i;
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 happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
int i=2;
switch(i)
{
case 1:
cout<<"Hello";
break;
case 2:
cout<<"world";
break;
case 3:
printf("End");
break;
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
int main()
{
string s1[]= {"How" , "to" };
s1[0].swap(s1[1]);
for (int i=0; i<2; i++) {
cout << s1[i];
}
return( 0 );
}
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class A {
int x;
protected:
int y;
public:
int z;
};
class B : private A {
string name;
public:
void set() {
x = 1;
}
void Print() {
cout << x;
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
int f(int i);
int main()
{
int i=0;
i++;
for (i=0; i<=2; i++)
{
cout< } return 0; } int f(int a) { return a+a; }
What is the output of the program?
#include
#include
using namespace std;
int main()
{
char str[] = "Hello\0\World\0";
cout << str;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
union un
{
int x;
char c;
};
union un u1 = {10};
union un u2 = {'a'};
union un u3 = {20, 'a'};
cout< cout< cout< return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
struct Person {
string name;
int age;
};
class First
{
Person *person;
public:
First() {person = new Person;
person?>name = "John";
person?>age = 30;
}
void Print(){
cout<
}
};
int main()
{
First t;
t.Print();
}