Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Please! 3/12/16-Practice Questions 1. Add a default constructor to the follo

ID: 3738128 • Letter: C

Question

C++ Please!

3/12/16-Practice Questions 1. Add a default constructor to the following code that sets the name to "unknown" and age to class Dog zero. string name int age; public: constructors go here 2. A. What is function overloading? B. Add two overloading constructors to the code from question 1 1. A constructor that has two parameters (for name and age) and sets the name and age with the parameter values. A constructor that has one parameter (for name) and sets the name with the parameter value. 2. 3. What is the output of the tollowing program? int a 4 intx &a; int y &b; cout

Explanation / Answer

/*If you have any query do comment in the comment section else like the solution*/

1.

class Dog

{

string name;

int age;

Dog()

{

this->name="unknown";

this->age=0;

}

}

2)A) Functions with same name but different paremeters of different method signature is known as function overloading.

2)B)1)

lass Dog

{

string name;

int age;

Dog(string name,int age)

{

this->name=name;

this->age=age;

}

}

2)B)1)

lass Dog

{

string name;

int age;

Dog(string name)

{

this->name=name;

}

}

3.

2

8

Reason: x contains address of a so adding b to *x will change the value at address to 2(4+(-2)) now value of a becomes 2. Now x is assigned address of b by equating it with y which holds the address of y. Now a is equated with 10+ *y; value at *y is -2 so adding it with 10 will give 8 as output.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote