Consider the definition of the following class:
class Sample
{
private:
int x;
double y;
public :
Sample();
//Constructor 1
Sample(int);
//Constructor 2
Sample(int, int);
//Constructor 3
Sample(int, double);
//Constructor 4
};
i. Write the
definition of the constructor 1 so that the private member variables are initialized
to 0.
ii. Write the
definition of the constructor 2 so that the private member variable x is
initialized according to the value of the parameter, and the private member
variable y is initialized to 0.
iii. Write the definition of the constructors 3 and 4 so that the private
member variables are initialized according to the values of the parameters
i) Sample(){
x = 0;
y = 0;
}
ii) Sample(int f){
x = f;
}
iii) Sample(int f, double g){
x = f;
y = g;
}
Comments
Leave a comment