Tuesday, January 12, 2010

c++part6

UNIT I
Introduction To OOP

Four mark Questions



1) Which of the following are the features of C++
i) Multiple inheritance ii) Implicit support for abstract classes
iii) pointers to class members iv) Operator overloading
a) All b) I, ii only c) I, iii, iv d) None

2) Match the following:
Escape Sequence Character
1) \a I) Tab
2) \x add ii) bell(beep)
3) \t iii) backslash
4) \\ iv) Hexadecimal representation
v) Backspace
a) 1- ii; 2- iv; 3- I; 4- iii b) 1 – iii; 2- iv ; 3- v; 4 – I c) 1- v; 2- iv; 3- I; 4- iii d) None

3) What is the O/P:
struct ss
{
int sno,age;
float fee;
char name[30];
};
void main()
{
cout<}
a) 36 b. 38 c) 30 d) 4

4) Give the o/p:
void main()
{
int I=10;
cout<<++I<<”\t”< }
a) 12 11 10 b) 11 11 11 c) 10 10 10 d) 11 10 10


5) Arrange the operators from higher at top to lowest is bottom:
i) *,-,/,%,+
ii) < , >, ==, !=, >=, <=
iii) ?:
iv) ( )
v) &&,
vi) !, ++, - -, -
vii) =,+=,-=,*=,/=,%=

a) ii, iv, iii, I, vii, v, vi b) iv, vi, I, ii, v, iii, vii c) iv, vi, ii, I, v, vii, iii d) I, iii, ii, v, vi, vii, ii, iv

6) What does the following program do :
void main()
{
char x;
cout<<”\n enter a character “;
cin>>x;
switch(x)
{
case ‘A’: case ‘a’:
case ‘E’: case ‘e’:
case ‘I’: case ‘i’:
case ‘O’: case ‘o’:
case ‘U’: case ‘u’:
cout<<”\n vowel”; break;
default:
cout<<”\n consonant”’;
}
}
a) Accepts a character and displays Vowel or consonant
b) Accepts a string and checks characters which are vowel or not
c) Error
d) None

7) Give the O/P:
for(I=0;I<5;I++)
{
if(I==3) continue;
cout<<”\n”< }
a) 1 2 4 5 b) 0 1 2 4 5 c) 0 1 2 3 5 d) 1 2 3 5

8) Give the O/p :
class myclass
{
int num;
public:
myclass(){num=0;}
myclass(int n){num=n;}
void sh(){
cout<<”\n num=”< };
void main()
{
num n1, n2(30);

n1.sh();
n2.sh();
}
a) num = 0 num = 30 b) num=” “ num=30 c) num=junkvalue num=30 d) error


9) Give the O/p :
class myclass
{
int num;
public:
myclass(int n){num=n;}
void sh(){
cout<<”\n num=”< };
void main()
{
num n1, n2(30);
n1.sh();
n2.sh();
}
a) num = 0 num = 30 b) num=” “ num=30 c) num=junkvalue num=30 d) error

10) Discuss the O/P:
class try
{
int id,tot;
public:
try(){tot=0; tot++; id=tot;}
void print()
{
cout<<”\n id is “< }

};
void main()
{
try ss1,ss2;
ss1.print();
ss2.print();
}
a) id=1 count=1 b) junk values c) Error d) None

11) Discuss the O/P:
class try
{
int id;
static int tot
public:
try(){ tot++; id=tot;}
void print()
{
cout<<”\n id is “< }
static void printcount()
{
cout<<”\n number of instances “< }

};
int try::tot=0;
void main()
{
try ss1,ss2;
try::printcount();
}
a) 1 b) 2 c) 0 d) None



12) What does the following program do:
void main()
{

int c;
for(c=65;c<=122;c++)
{
if(c>90 && c<97)
continue;
cout< }
}
a) Displays numeric set b) displays alphabet set c) displays char., set d) Error

13) What does the following program do:
void main()
{

int n[10],I,j,temp;
cout<<”\n Enter 10 numbers:”;
for(I=0;I<10;I++)
cin>>n[I];

for(I=0;I<9;I++)
{
for(j=I+1;j<10;j++)
{
if(n[I]>n[j])
{
temp=n[I];
n[I]=n[j];
n[j]=temp;
}
}
}
for(I=0;I<10;I++)
cout<<”\n”<
}
a) Displays the entered numbers in ascending order
b) Displays the entered numbers in descending order
c) Both a & b
d) None

14) Which of the one is the correct logic for reversing the string:
i) void main() ii) void main()
{ {
char ss[80]; char ss[80],ss1[80];
cout<<”\n enter a string”;
cout<<”\n enter a string:”; cin.getline(ss,80);
cin.getline(ss,80); strcpy(ss1,ss);
int l=strlen(ss); strrev(ss1);
for(l=l-1;l>=0; l- -) cout<<”\n reverse is “< cout< }

a) I only b) ii only c) Both I, ii d) None


15) What is the O/P of :
class A
{
int a;
A()
{a=0;}
public:
void show()
{
cout<<”\n a=”< }
};
void main()
{
A ss;
ss.show();
}
a) 0 b) Junk value c) error d) None

16) Match the following:
Operators Category
1) ++ A) binary
2) += B) ternary
3) ?: C) unary
a) 1- A, 2- B, 3- C b) 1- C, 2- A, 3- B c) 1- C, 2- B, 3- A d) a. 1- B, 2- A, 3- C



*************************






Key for four marks questions

1 c 2 a 3 b 4 a 5 b
6 a 7 b 8 a 9 d 10 a
11 b 12 b 13 a 14 c 15 c
16 b