Answer to Question #217178 in C++ for Chirag

Question #217178

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


1
Expert's answer
2021-07-15T00:07:26-0400
i) Sample(){
x = 0;
y = 0;
}
ii) Sample(int f){
x = f;
}
iii) Sample(int f, double g){
x = f;
y = g;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS