Question: Example Code: The example below demonstrates the aspects of constructor overloading, defining member functions outside the class, and most importantly objects as function arguments. This

 Example Code: The example below demonstrates the aspects of constructor overloading,

Example Code: The example below demonstrates the aspects of constructor overloading, defining member functions outside the class, and most importantly objects as function arguments. This program starts with a distance dist2 set to an initial value and adds to it a distance dist1, whose value is supplied by the user, to obtain the sum of the distances. It then displays all three distances #include using namespace std; class Distance //English Distance class { private: int feet; float inches; public: //constructor (no args) Distance() : feet(0), inches(0.0) { } //constructor (two args) Distance(int ft, float in) : feet(ft), inches(in) { } void getdist() //get length from user { cout>feet; cout>inches; } inline void showdist(); //display distance void add_dist( Distance, Distance ); //declaration }; //-------------------------------------------------------------- //definition of inline function which display distance inline void Distance::showdist() { cout= 12.0) //if total exceeds 12.0, { //then decrease inches inches -= 12.0; //by 12.0 and feet++; //increase feet } //by 1 feet += d2.feet + d3.feet; //add the feet } void main() { Distance dist1, dist3; //define two Distance Objects Distance dist2(11, 6.25); //define and initialize dist2 dist1.getdist(); //get dist1 from user dist3.add_dist(dist1, dist2); //dist3 = dist1 + dist2 //display all lengths cout

Tasks: 5.1. Code the example of complex class given above and include the functions for addition, subtraction and multiplication of objects of complex class and return the object containing result. Test all the functions in main. 5.2. Modify the above task such that; define the member function show() outside the class and also define it as inline. 5.3. Modify the task (5.1) by defining all the member functions outside the class definition. 5.4. Test the distance class example given above.

Subject: Object Oriented Programming Programming Language: C++ Perform all the tasks. As I'm a beginner so please write simple and easy code as you can. Thank You!

5. Lab Tasks 5.1. Code the example of complex class given above and include the functions for addition, subtraction and multiplication of objects of complex class and return the object containing result. Test all the functions in main. 5.2. Modify the above task such that; define the member function show() outside the class and also define it as inline. 5.3. Modify the task (5.1) by defining all the member functions outside the class definition 5.4. Test the distance class example given above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!