a)Show how to overload the constructor for the following class so that unitialized objects can also be created. (When creating uninitialized objects, give x and...

      

a)Show how to overload the constructor for the following class so that unitialized objects can also be created. (When creating uninitialized objects, give x and y the value 0.)
class myclass {
int x, y;
public:
myclass(int i, int j) { x=i; y=j;}
// ...
};

b)Using the class from question(a) above, show how you can avoid overload myclass() by using default arguments.

  

Answers


Davis

a)class myclass {
int x, y;
public:
myclass(int i, int j) {x=i; y=j;}
myclass() { x=0; y=0;}
};

b)class myclass {
int x, y;
public:
myclass( int i=0, int j=0) { x=i; y=j;}
};

Githiari answered the question on May 31, 2018 at 18:00


Next: Why would the following be an inappropriate use of an overloaded operator?coord coord:: operator%(coord ob) {double i;cout << "Enter a number:";cin >>i;cout << "root of...
Previous: Given the following partial class, add the necessary constructor function so that both declarations within main() are valid. class samp { int a; public: //add constructor functions int get_a() {...

View More Computer Studies Questions and Answers | Return to Questions Index


Exams With Marking Schemes

Related Questions