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 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
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 objectStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started