Question: EXPLAIN THE ANSWERS USING CONCEPT OF OOP ( OBJECT ORIENTED PROGRAMMING ) Consider the following class definitions: (read and understand carefully) #include #include using namespace

EXPLAIN THE ANSWERS USING CONCEPT OF OOP ( OBJECT ORIENTED PROGRAMMING )

Consider the following class definitions: (read and understand carefully)

#include

#include

using namespace std;

class Service

{

public:

void print () const ;

void set_val(float, int);

float amount();

Service();

Service(float, int);

private:

float price;

int no_of_days;

int special();

};

class superService: public Service

{ public:

void print () const;

void set_val(float, int, float);

int manipulate();

supersService();

superService(float, int, float);

private:

float coupon_value;

};

/// ==== Service Class function definitions ===========

Service ::Service():price(0), no_of_days(0)

{ }

Service::Service(float a, int b)

{price = a;

no_of_days =b;

/// cout

}

int Service:: special()

{

cout

}

float Service::amount()

{

return (price*no_of_days);

}

void Service::print () const

{

cout

}

void Service:: set_val(float i, int j)

{

price=i;

no_of_days =j;

}

/// ============================================================

/// --- Derived class functions ----

void superService:: print () const

{

cout

cout"Price= "price "no_of_days= " no_of_days"Coupon= "coupon_valueendl;

}

void superService:: set_val(float i, int j, float k)

{

price=i;

no_of_days =j;

coupon_value =k;

}

int superService::manipulate()

{

price= 0.9 * price;

no_of_days = no_of_days+2;

coupon_value = 0.3 * price;

}

//superService::superService()

//{ cout

superService::superService(float a, int b, float c)

{ price=a;

no_of_days=b;

coupon_value=c;

cout

cout"Price= "price "no_of_days= " no_of_days"Coupon= "coupon_valueendl;

}

///___ Testing Function in Main _______

int main ()

{ Service service1, service2(8.6,50);

superService super2(4.2,5,6.2);

service1.print();

service1.set_val(5,6);

cout"The value is "service1.amount()endl;

super2.print();

return 0;

}

Part a) Which private members, if any, of Service are public members of superService? Part b) Which members, functions and/or data of class Service are directly accessible in the class superService? Part c) What should be changed in above program so that it executes and gets tested in main function (in the same hierarchy by removing any errors)? Part d) What will happen if the definition of respective function amount() in above code is replaced by the definition given below:

float Service::amount()

{

return (price*no_of_days-(coupon*price));

}

Part e) Will the following statement be valid or invalid in the code above? Justify if it is valid and explain reason if invalid?

void superService:: set_val(float i, int j, float k)

{

Service::set_val(i,j);

coupon_value =k;

}

Part f) Which function in above code, if any, is overridden and which is overloaded? Explain how is any function overloaded or overridden in above code? Part g) In the main program write a testing code that should do the following 4 cases and call any function with pointer. Which one case will give errors/problem in executing the class functions with pointer and why? 1. Aim a Base-Class Pointer at a Base-Class Object and call any function 2. Aim a Derived-Class Pointer at a Derived-Class Object and call any function 3. Aim a Base-Class Pointer at a Derived-Class Object and call any function 4. Aim a Derived-Class Pointer at a Base-Class Object and call any function

EXPLAIN THE ANSWERS USING CONCEPT OF OOP ( OBJECT ORIENTED PROGRAMMING )

Part h) Which function(s) in the parent class Service can be made as virtual function(s)? What will be the effect of making that function as virtual? How will you call the virtual function from all above (hierarchical) classes in the main (write that code fragment for all possible function calls in the main)? Part i) Is Service an abstract class? Justify Why/how?

Hint: Service *service; Service sl; Service = &s1; This fragment shows a base class pointer aimed at a Base class object

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!