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

The following class diagrams are designed for a restaurant that also provides ho

ID: 3593638 • Letter: T

Question

The following class diagrams are designed for a restaurant that also provides home delivery services. Study the given class diagrams, additional information and answer questions that follow: MobileContract PhoneModel # planID: string # contract! D: string # phone: PhoneModel modelNumber: int colour: string - marketPrice: double MobileContract(string, string, PhoneModel) + display(): void + calcPlanPhonePrice): double +PhoneModel(int, string, double) + display0: void +getMarketPrice(): double RoadshowContract - rsPhoneDiscount: double + RoadshowContract(string, string, PhoneModel, double) + display0: void + calcPlanPhonePrice): double

Explanation / Answer

a) Method overloading: Method overloading is a feature which allows two or more methods in the same class have same method name but must have different arguments either by their type or by the number of arguments.

for example:

void display(int x, int y);

void display(int x);

void display(float x);

Here all above methods have the same method name "display" but the different type of arguments.

Method overriding: Method overriding is a feature that allows a child class to give their own specific implementation for the same method which is already defined in its parent class.

For example, if Parent class have a method void display() to display its content, the child class can override the functionality of its parent class method by implementing same method void display() in its class which displays its content.

b)

Class PhoneModel
{
//data members
private:
int modelNumber;
string color;
double marketPrice;

//constructor
public: PhoneModel(int model, String colr, double price)
{
modelNumber=model;
color=colr;
marketPrice=price;
}
  
//member functions
public: void display()
{
cout<<"Model Number :"<< modelNumber<<endl;
cout<<"Color :"<<color<<endl;
cout<<"Market Price: %.2d"<<marketPrice<<endl;
}

public: double getMarketPrice()
{
return marketPrice;
}
};

c).

//base class specification

class MobileContract
{
public:
string planID;
string contractID;
PhoneModel phone;

};

//derived class specification

class RoadShowContract: public MobileContract //inherid MobileContract class
{
private :
double rsPhoneDiscount;

};

d)

class MobileContract
{
public:
string planID;
string contractID;
PhoneModel phone;

public: MobileContract(string plan, string contract, PhoneModel model)
{
planID=plan;
contractID=contract;
phone=model;

}

public: void display()
{
cout<<"Plan ID :"<< planID<<endl;
cout<<"Contract ID :"<<contractID<<endl;
phone.display();
}

public: double calPlanPhonePrice( )
{
double temp=phone.getMarketPrice();
double result=0.00;
if(planID.compare("planA"))
{
result = temp-temp*0.20;
}
if(planID.compare("planB"))
{
result = temp-temp*0.30;
}
if(planID.compare("planC"))
{
result = temp-temp*0.35;
}
return result;
}


};

class RoadShowContract: public MobileContract
{
private :
double rsPhoneDiscount;

public:
RoadShowContract(string plan, string contract, PhoneModel model,double rsDiscount)
: MobileContract(plan,contract,model)
{

rsPhoneDiscount= rsDiscount;
}

public: void display()
{
cout<<"Road Show Discount: %.2d"<<rsPhoneDiscount<<endl;
MobileContract::phone.display();

}

};

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