PMAS - Arid Agriculture University Rawalpindi: University Institute of Information Technology

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

PMAS - Arid Agriculture University Rawalpindi

University Institute of Information Technology

QUIZ #4

Question 1:Do as directed: (Marks: 3+3+3)

a. Find errors in the following code. b. Write output of the following program.
class Xyz {
class Employee {
private:
private;
static int count;
int empnum;
char code; public:
int static x; Xyz()
public { count++;
class(){} }
void showemp(int, char);
}; int show()
int class::x=0;
{
return(count);
}
c. What is the output of the following code. };
class Base{
int Xyz::count=0;
public:
void main()
Base()
{
{
Xyz a,b,c;
cout<<”Base class”<<endl;
cout<<”a=”<<a.show()<<endl;
}
cout<<”b=”<<b.show()<<endl;
};
cout<<”c=”<<c.show()<<endl;
class Child: public Base{
}
public:
Child()
{
cout<<”Child class”<<endl;
}
};

void main()
{
Child c;
}

1
Question 2: Determine True/False. Correct false statements. (Marks5)

(a) A constructor is a special member function having same name as its class which is called automatically when
an object is destroyed.
(b) Only a compiler can include a default constructor in the program.
(c) A destructor must be declared by a keyword class, preceded by a tilde (~) and may have default argument
values.
(d) In constructor overloading, compiler distinguish between multiple constructors on the basis of their return
types.
(e) When an object is initialized with another object of the same type then a default copy constructor
must be included by a user in a program.
(f) Protected class members are accessible from its own class only.
(g) Scope resolution operator (::) is used to access functions of the base class from the functions of the
derived class in function overriding.
(h) Objects of the privately derived class can access only public members of the base class.
(i) An abstract class is a class that cannot be instantiated as it is only used for the inheritance.
(j) Function overloading and overriding are the same terms used interchangeably.

Question 3: (Marks 6)
A stack is a “last in, first out” linear data structure. It is characterized by two fundamental operations,
called push and pop. The push operation adds a new item to the top of the stack. If the space allocated
to hold the stack is full when the push operation is attempted then an error message “stack is full” is
displayed. The pop operation removes an item from the top of the stack. If the stack is empty when a
pop operation is attempted then an error message “stack is empty” is displayed.
Use concept of inheritance, write code which implements a stack. Your code should store the stack
elements in an array.

You might also like