Question: A) Suppose you have a class called base which has been inherited by a class called derived. ( both classes have public, protected and private
A) Suppose you have a class called base which has been inherited by a class called derived.
( both classes have public, protected and private members )
What can a client of derived access within the class base ?
What can the class derived access within the class base ?
B) Suppose you have a class called more which has a private object of a class called simple. ( both classes have public, protected and private members )
What can a client of more access within the class simple ?
What can the class more access within the class simple ?
C)What is a pointer variable ?
D)What is a destructor and which are its properties ?
E)What are the two differences between a dynamic variable and an ordinary variable?
F) What are the advantages of using a dynamic array instead of a regular array ?
G) When does memory leak occur ? How can you minimize it ?
H)Suppose you have an int pointer which contains the address of a dynamic variable.
What will you be able to change if you pass to a function the pointer as a value
parameter ?
How about if you pass the pointer as a reference parameter?
I)What doesoperator overloadingallow us to do ?
J)What iscomposition?
K)What isinheritance?
L)Explain the difference between theprivateandprotectedmembers of a class.
M)What is afriendfunction ?
N)What doclass templatesallow us to do ?
O)Why must the << and the >> operators be overloaded as friend functions instead of member functions, for a user defined class ?
P)What is a copy constructor ? Why and when do we need it ?
Q)What is astruct?
R) Use the following declarations for all parts of this question:
struct date {
int day, month, year; };
date *today;
int *p;
1) Create a dynamic integer variable using pointer p and a dynamic structure variable
using pointer today.
2) Assign 10 to the dynamic integer variable and May 21, 1986 to the dynamic structure
variable.
3) Release memory for the dynamic integer variable and create a dynamic integer array
of size 50 using pointer p.
4) Release memory for the dynamic structure variable and the dynamic array, and clear
the contents of pointer p and today.
S) Consider the following two classes:
classsimpleclassmore:publicsimple
{ {
private: private:
int a; int x;
protected: protected:
char c; double z;
public: public:
simple ( int, char ); more ( int, char, int, double );
void read (); void set ();
void print (); void print();
}; };
Answer the following questions ( be precise ! )
1) What can a client ofmoreaccess within the classmore?
2) What can a client ofmoreaccess within the classsimple?
3) What can the classmoreaccess within the classsimple?
4) The first two parameters of the constructor ofmoreshould be given to the constructor
ofsimple the last two are for x and z . Write the definition of the constructor ofmore.
5) Write a call to the functionread of classsimple to be included in the functionset-
of classmore.
6) Write a call to the functionprint classsimple to be included in the functionprint-
of classmore.
T)Consider the following simple class:
class Rectangle
{
private:
double length, width;
public:
Rectangle ( double l, double w ){ length = l; width = w; }
double area() { return length * width; }
double perimeter(){ return 2* ( length + width ); }
};
1) Write a copy constructor for the class.
2) Consider the following class that uses the Rectangle class defined above:
class artItem
{
private:
Rectangle canvas_frame;
Rectangle canvas;
String title;
};
a) Write a constructor which initializes the picture_frame, the canvas, and the title. The constructor
receives a string parameter to initialize the title, a Rectangle object to pass to the Rectangle
copy constructor when creating the picture_frame object, and a Rectangle object to pass to the
Rectangle copy constructor when creating the canvas object.
b) Write a print method that prints the title and prints the perimeter of picture_frame and the area
of canvas call the methods area and perimeter to get both values.
3) From the Rectangle class defined in above, derive a class named Box having an additional data
member named depth, a constructor with three parameters ( one for the depth and two for the
constructor of Rectangle) , and a volume method that returns the volume of the box
volume is length *width * depth.
U)Write the following functions:
1.Write a function, to be included in a template sorted/unsorted list class, called smaller, that will receive an xtype parameter. The function will return how many items in the list are smaller than the parameter.
2.Write a function, to be included in a template sorted/unsorted list class, called print_twice, that will print the list first forward and then backwards.
3.Write a function, to be included in a template unsorted list class, called replace_item, that will receive two xtype parameters, one called olditem, the other called newitem. The function will replace all occurrences of olditem with newitem ( if olditem exists !! ) and it will return the number of replacements done.
4.Write a function, to be included in a template sorted/unsorted list class, that will deletealloccurrences of
an xtype parameter.
5.Write a function, to be included in a template sorted list class, that will delete all items that are greater
than an xtype paramter.
6.Write a function, to be included in a template sorted list class, that will return the number of occurrences of an xtype paramter.
7.Write a function, to be included in a template sorted list class that will receive two xtype parameters
called smallest and largest. The method will count and return how many values in the list are between
smallest and largest.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
