Total Question 52
Total Marks 80
40 MCQ’S
4 Question 2 marks
4 Question 3 marks
4 Question 5 marks
50 % mcq’s from past papers
And long questions are given below
1- describe a way to declare a template function as a friend of any other class. marks 2
Answer:
template< class T >
class B {
int data;
friend void doSomething( T ); // granting friendship to template
doSomething in // class B
friend A< T >; // granting friendship to class A in class B
};
2- What do you know about function Template? 2 marks
Answer:
Function templates are used when we want to have exactly identical operations on different data types in case
of function templates we cannot change implementation from data type to data type however we can specialize
implementation for a particular data type.
3- What do you mean by Stack unwinding? 2 marks
Answer:-
The flow control ( the order in which code statements and function calls are made) as a result of throw statement is referred as “stack unwinding”
4- What will be the output after executing the following code? 3 marks
class c1{
public:
virtual void function(){
cout”I am in c1”endl;
}
};
class c2: public c1{
public:
void function(){
cout”I am in c2”endl;
}
};
class c3: public c1 {
public:
void function(){
cout”I am in c3”endl;
}
};
int main(){
c1 * test1 = new c2();
c1 * test2 = new c3();
test1->function();
test2->function();
system(“PAUSE”);
return 0;
}
Answer:-
I am in c2
I am in c3
5- What is nested function and also give the syntax? 3 marks
6- Ek question no 4 ki tra ka tha out put show krna tha [topic (class)] . . . 5 makrs
(ye nahe hai pr same isi tra ka tha)
What would be the output of this code?
class mother {
public:
mother ()
{ cout "mother: no parameters\n"; }
mother (int a)
{ cout "mother: int parameter\n"; }
};
class daughter : public mother {
public:
daughter (int a)
{ cout "daughter: int parameter\n\n"; }
};
class son : public mother {
public:
son (int a) : mother (a)
{ cout "son: int parameter\n\n"; }
};
int main () {
daughter rabia (0);
son salman(0);
return 0;
}
Answer:
mother: no parameters
daughter: int parameter
mother: int parameter
son: int parameter
7- Ek template ka qstion tha js me int type age size tha average nkani thi with usage of array . . . 5 marks
8- How can we set the default values for non type parameters? . . 3 marks
Answer:-
We can set default value for this non type parameters, as we do for parameters passed in ordinary functions,
template< class T, int SIZE = 10 >
class Array {
private:
T ptr[SIZE];
public:
void doSomething();
…
}
9- Ek question me coding ki hui thi us me srf abstract or concrete alag krna tha ? 5 marks
(sorry ye question sahi tra yad nahe hai)
Baki k qstion yad nahe aa rahay sorry for that . . . .
Total Marks 80
40 MCQ’S
4 Question 2 marks
4 Question 3 marks
4 Question 5 marks
50 % mcq’s from past papers
And long questions are given below
1- describe a way to declare a template function as a friend of any other class. marks 2
Answer:
template< class T >
class B {
int data;
friend void doSomething( T ); // granting friendship to template
doSomething in // class B
friend A< T >; // granting friendship to class A in class B
};
2- What do you know about function Template? 2 marks
Answer:
Function templates are used when we want to have exactly identical operations on different data types in case
of function templates we cannot change implementation from data type to data type however we can specialize
implementation for a particular data type.
3- What do you mean by Stack unwinding? 2 marks
Answer:-
The flow control ( the order in which code statements and function calls are made) as a result of throw statement is referred as “stack unwinding”
4- What will be the output after executing the following code? 3 marks
class c1{
public:
virtual void function(){
cout”I am in c1”endl;
}
};
class c2: public c1{
public:
void function(){
cout”I am in c2”endl;
}
};
class c3: public c1 {
public:
void function(){
cout”I am in c3”endl;
}
};
int main(){
c1 * test1 = new c2();
c1 * test2 = new c3();
test1->function();
test2->function();
system(“PAUSE”);
return 0;
}
Answer:-
I am in c2
I am in c3
5- What is nested function and also give the syntax? 3 marks
6- Ek question no 4 ki tra ka tha out put show krna tha [topic (class)] . . . 5 makrs
(ye nahe hai pr same isi tra ka tha)
What would be the output of this code?
class mother {
public:
mother ()
{ cout "mother: no parameters\n"; }
mother (int a)
{ cout "mother: int parameter\n"; }
};
class daughter : public mother {
public:
daughter (int a)
{ cout "daughter: int parameter\n\n"; }
};
class son : public mother {
public:
son (int a) : mother (a)
{ cout "son: int parameter\n\n"; }
};
int main () {
daughter rabia (0);
son salman(0);
return 0;
}
Answer:
mother: no parameters
daughter: int parameter
mother: int parameter
son: int parameter
7- Ek template ka qstion tha js me int type age size tha average nkani thi with usage of array . . . 5 marks
8- How can we set the default values for non type parameters? . . 3 marks
Answer:-
We can set default value for this non type parameters, as we do for parameters passed in ordinary functions,
template< class T, int SIZE = 10 >
class Array {
private:
T ptr[SIZE];
public:
void doSomething();
…
}
9- Ek question me coding ki hui thi us me srf abstract or concrete alag krna tha ? 5 marks
(sorry ye question sahi tra yad nahe hai)
Baki k qstion yad nahe aa rahay sorry for that . . . .
Best of luck & also pray for me
0 comments
Post a Comment