In: Computer Science
(In C++)
Task 1:
Implement a code example of Constructor Chaining / Constructor Overloading.
Make sure to label class and methods with clear descriptions describing what is taking place with the source code.
Attach a snipping photo of source code and output
output:
code:
#include <iostream>
using namespace std;
class construct_overloading
{
public:
float sum;
construct_overloading() /*Constructor with no parameters*/
{
sum = 0;
}
construct_overloading(int a, int b) /*Constructor with two
parameters*/
{
sum = a + b;
}
void display()
{
cout<< sum<< endl;
}
};
int main()
{
/*here we make two object of class construct_overloading*/
construct_overloading co1; /*here when we create co1 than first
Constructor overlop a second Constructor*/
construct_overloading co2(10,20); /*here when we create co2 than
second Constructor overlop a first Constructor*/
co1.display();
co2.display();
return 1;
}