Object Exam
Object Exam
(i) write the constructor definition for class A, so that each object of A and B will be initialized
correctly.
class B {
float y;
public:
B (float); // only this constructor is provided for B
};
class A {
int x;
B b;
…
};
(ii) The following is a declaration of class Array which contains an array of integers.
class Array {
int size; // size of the array
int* ptr; // pointer to first element of array
public:
Array (int=10); // default constructor
~Array();
//…
};
a. write a default constructor definition for class Array, in which ptr is initialized to point to an
array of zeros of any size . The default size of the array is 10.
b. Write a definition for the destructor of class Array that properly destruct the object, and free all
the memory allocated for the object.
(iii) Write a full C++ program that keeps printing the multiples of the integer 2 (ex. 2, 4, 8, 16, 32,
64…). You need to use an infinite loop to perform this task.
Nahid.eat();
Nahid.sleep();
Rami = Nahid;
Rami.jump();