C++ Programming - Functions
Exercise : Functions - Programs
- Functions - General Questions
- Functions - Programs
36.
What will be the output of the following program?
#include<iostream.h>
#include<string.h>
class BixString
{
char x[50];
char y[50];
char z[50];
public:
BixString()
{ }
BixString(char* xx)
{
strcpy(x, xx);
strcpy(y, xx);
}
BixString(char *xx, char *yy = " C++", char *zz = " Programming!")
{
strcpy(z, xx);
strcat(z, yy);
strcat(z, zz);
}
void Display(void)
{
cout<< z << endl;
}
};
int main()
{
BixString objStr("Learn", " Java");
objStr.Display();
return 0;
}
37.
What will be the output of the following program?
#include<iostream.h>
class BaseCounter
{
protected:
long int count;
public:
void CountIt(int x, int y = 10, int z = 20)
{
count = 0;
cout<< x << " " << y << " " << z << endl;
}
BaseCounter()
{
count = 0;
}
BaseCounter(int x)
{
count = x ;
}
};
class DerivedCounter: public BaseCounter
{
public:
DerivedCounter()
{ }
DerivedCounter(int x): BaseCounter(x)
{ }
};
int main()
{
DerivedCounter objDC(30);
objDC.CountIt(40, 50);
return 0;
}
38.
What will be the output of the following program?
#include<iostream.h>
class Number
{
int Num;
public:
Number(int x = 0)
{
Num = x;
}
void Display(void)
{
cout<< Num;
}
void Modify();
};
void Number::Modify()
{
int Dec;
Dec = Num % 13;
Num = Num / 13;
if(Num > 0 ) Modify() ;
if(Dec == 10) cout<< "A" ;
else if(Dec == 11) cout<< "B" ;
else if(Dec == 12) cout<< "C" ;
else if(Dec == 13) cout<< "D" ;
else cout<< Dec ;
}
int main()
{
Number objNum(130);
objNum.Modify();
return 0;
}
39.
What will be the output of the following program?
#include<iostream.h>
class Base
{
int x, y;
public:
Base()
{
x = y = 0;
}
Base(int xx)
{
x = xx;
}
Base(int p, int q = 10)
{
x = p + q;
y = q;
}
void Display(void)
{
cout<< x << " " << y << endl;
}
}objDefault(1, 1);
class Derived: public Base
{
Base obj;
public:
Derived(int xx, int yy): Base(xx, xx + 1)
{ }
Derived(Base objB = objDefault)
{ }
};
int main()
{
Derived objD(5, 3);
Derived *ptrD = new Derived(objD);
ptrD->Display();
delete ptrD;
return 0;
}
40.
What is correct about the following program?
#include<iostream.h>
class Base
{
int x, y, z;
public:
Base()
{
x = y = z = 0;
}
Base(int xx, int yy = 'A', int zz = 'B')
{
x = xx;
y = x + yy;
z = x + y;
}
void Display(void)
{
cout<< x << " " << y << " " << z << endl;
}
};
class Derived : public Base
{
int x, y;
public:
Derived(int xx = 65, int yy = 66) : Base(xx, yy)
{
y = xx;
x = yy;
}
void Display(void)
{
cout<< x << " " << y << " ";
Display();
}
};
int main()
{
Derived objD;
objD.Display();
return 0;
}
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers