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 f contractiD: string modelNumber: int colour: string marketPrice: double phone: PhoneModel + MobileContract(string, string PhoneModel) +display: void + calcPlanPhonePrice: double + PhoneModel int, string, double) +display) void +getMarketPrice): double act rsPhoneDiscount: double + RoadshowContract(string, string PhoneModel, double) +display: void +calcPlanPhonePrice):double Additional Information: Class MobileContract string. Constructor. The are, Plan type D PhoneModel) (planID), Contract ID (contractID) and Phone model (phoneMode). Valid plan Ds are planA. planB and planC Calculates phone price under contact plan by applying discounts as follows. planA-> 20% discount from market price. planB-30% discount from market price. calcPlanPhonePrice():double lanC”-> 35% discount from market price Uses cout to display its respective data members. Invoke display method in PhoneModel class to display display(: void details. Class RoadshowContract RoadshowContract(string, string.Constructor. The parameters are, Plan type D PhoneModel, double): planID), Contract ID (contractID), Phone model (phoneModel) and Road show Discount Amount (rsPhoneDiscount). Invokes the base class constructor with the ar Invokes the base class calcPlanPhonePrice) and subtracts the rsPhoneDiscount from the retum value of base class calcPlanPhonePrice). Returns the final pass-in t to set base class data members calcPlanPhonePrice)double hone price after discount Uses cout to display its respective data members. Invoke display method in PhoneModel class to display display): void one details. Class PhoneModel PhoneModel (string, string. double: Constructor. The parameters are, Phone Model (modelNımber). Phone Colour (colour) and Markeit Price of the Phone (marketPrice). The constructor assumes has the following default values: modelNumber_S900. colour-Black, marketPrice= 1200.0 Uses cout to display its respective data members. marketPrice should be displayed with two decimal display 0:void aces Accessor methid. Returns the market Price etPrice0:double

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution: a) Method Overloading: . This happens when more than one methods have same name, but different signature om The dif

Data members string modelNumber; string colour; double marketPrice; public: // Functiobs PhoneModel (string num-S900, strinClass MobileContract class MobileContract string planID; string contractID; PhoneModel phone; public: MobileContract (stringcontractID-conID phone-ph; void MobileContract:: display () coutくくPlan ID: くくplanTD<<endl ; coutくぐContract ID: くくcontract!/7 Calculate price double RoadshowContract: : calcPlanPhonePrice () double val=MobileContract: calcPlanPhone Price(); val-valfor (int i-0;i<4; i++) mobcon.at (i)->display); cout<<mobcon.at (i) calcplanPhonePrice ()<<endl system (pause) return 0 OutContract ID: 2 Model Number S900 Colour: Black Market Price: 1200 350 Press any key to continue . . -

Executable C++ Code:

#include<iostream>

#include<string>

#include<vector>

using namespace std;

//.................Question b...............................

class PhoneModel

{

// Data members

string modelNumber;

string colour;

double marketPrice;

public:

// Functiobs

PhoneModel(string num="S900",string col="Black",double price=1200.0);

void display();

double getMarketprice();

};

// Constructor

PhoneModel::PhoneModel(string num,string col,double price)

{

modelNumber=num;

colour=col;

marketPrice=price;

}

// Display

void PhoneModel:: display()

{

cout<<"Model Number: "<<modelNumber<<endl;

cout<<"Colour: "<<colour<<endl;

cout<<"Market Price: "<<marketPrice<<endl;

}

// Get market price

double PhoneModel::getMarketprice()

{

return marketPrice;

}

//.................Question c...............................

// Class MobileContract

class MobileContract

{

string planID;

string contractID;

PhoneModel phone;

public:

MobileContract(string ID,string conID, PhoneModel ph);

void display();

virtual double calcPlanPhonePrice();

};

// Derived class

class RoadshowContract: public MobileContract

{

double rsPhoneDiscount;

public:

RoadshowContract(string planID,string contractID, PhoneModel phone,double rsdiscount);

double calcPlanPhonePrice();

void display();

};

//.................Question d...............................

// Constructor

MobileContract::MobileContract(string ID,string conID, PhoneModel ph)

{

planID=ID;

contractID=conID;

phone=ph;

}

void MobileContract:: display()

{

cout<<"Plan ID: "<<planID<<endl;

cout<<"Contract ID: "<<contractID<<endl;

phone.display();

}

// Calculate price

double MobileContract::calcPlanPhonePrice()

{

if(planID=="planA")

{

return 0.2*phone.getMarketprice();

}

else if(planID=="planB")

{

return 0.3*phone.getMarketprice();

}

else if(planID=="planC")

{

return 0.35*phone.getMarketprice();

}

}

// Constructor

RoadshowContract::RoadshowContract(string planID,string contractID, PhoneModel phone,double rsdiscount):MobileContract(planID,contractID,phone)

{

rsPhoneDiscount=rsdiscount;

}

// Calculate rice

double RoadshowContract::calcPlanPhonePrice()

{

double val=MobileContract::calcPlanPhonePrice();

val=val-rsPhoneDiscount;

return val;

}

// Dislay

void RoadshowContract::display()

{

MobileContract::display();

cout<<"Phone discount: "<<rsPhoneDiscount<<endl;

}

//.................Question e...............................

int main()

{

vector<MobileContract *>mobcon;

PhoneModel ph=PhoneModel("u800","red",99.0);

PhoneModel ph1=PhoneModel("u600","black",199.0);

PhoneModel ph2=PhoneModel("u900","green",299.0);

PhoneModel ph3;

mobcon.push_back(new MobileContract("planA","1",ph));

mobcon.push_back(new MobileContract("planB","2",ph1));

mobcon.push_back(new RoadshowContract("planA","2",ph2,10));

mobcon.push_back(new RoadshowContract("planB","2",ph3,10));

for(int i=0;i<4;i++)

{

mobcon.at(i)->display();

cout<<mobcon.at(i)->calcPlanPhonePrice()<<endl;

}

system("pause");

return 0;

}

Add a comment
Know the answer?
Add Answer to:
The following class diagrams are designed for a restaurant that also provides home delivery services. Study...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Examine the following class diagram, additional information and answer the questions that follow screenType: char screenSize:...

    Examine the following class diagram, additional information and answer the questions that follow screenType: char screenSize: int resolution: string price: double standard: boo1 TV(char= 'L', int= 50, string=" HD", double= 600, bool = true ) setorder )void displayvoid getPrice() :double etstandard (:bool; Additional Information Meth tv 〔 char = 'L,, ユnt S0, string ="HD", double -600, bol - true | Constructor with default values. The tional arguments are screenType. screenSize, resolution, price and standard Set the data members accordingly. [Note:...

  • Create the class Book which has the following members: 1. private members: 1. title as String...

    Create the class Book which has the following members: 1. private members: 1. title as String 2. isbn as String 3. author as String 4. price as double 2. public members: 1. default constructor which initializes all data members to their default values. 2. non-default constructor which initializes all data members to parameters values. 3. toString which returns a representing String of the Book. 4. add all the setters and getters. Create the class EBook which is a subclass of...

  • Please help me with my JAVA programming Exercise. a. The Talk-A-Lot Cell Phone Company provides phone...

    Please help me with my JAVA programming Exercise. a. The Talk-A-Lot Cell Phone Company provides phone services for its customers. Create an abstract class named PhoneCall that includes a String field for a phone number and a double field for the price of the call. Also include a constructor that requires a phone number parameter and that sets the price to 0.0. Include a set method for the price. Also include three abstract get methods—one that returns the phone number,...

  • Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The clas...

    Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...

  • Create an Item class, which is the abstract super class of all Items.           Item class...

    Create an Item class, which is the abstract super class of all Items.           Item class includes an attribute, description of type String for every item. [for eg. Book]                                                             A constructor to initialize its data member of Item class.               Override toString() method to return details about the Item class. Create the ExtraCharge interface with the following details.                       Declare a constant RATE with value 0.25   Declare a method called calculateExtraCharge(), which returns a double value. Create the...

  • C++ Could you check my code, it work but professor said that there are some mistakes(check...

    C++ Could you check my code, it work but professor said that there are some mistakes(check virtual functions, prin() and others, according assignment) . Assignment: My code: #include<iostream> #include<string> using namespace std; class BasicShape { //Abstract base class protected: double area; private:    string name; public: BasicShape(double a, string n) { area=a; name=n; } void virtual calcArea()=0;//Pure Virtual Function virtual void print() { cout<<"Area of "<<getName()<<" is: "<<area<<"\n"; } string getName(){    return name; } }; class Circle : public...

  • This is assignment and code from this site but it will not compile....can you help? home...

    This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...

  • Question #1 (CLO: 1,2.3) Make a class called Car. Declate its data, model, colour, price Also...

    Question #1 (CLO: 1,2.3) Make a class called Car. Declate its data, model, colour, price Also make a constructor to initialize these data variables. Make a getPrice() method to return price. Make a Child class of Car, called Truck. It has a data variable, weight. Make a constructor that takes all the data variables including weight and those of Car class. Also override getPrice() method, which return 20% discount price if the weight is more than 20,000 else it returns...

  • Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person {...

    Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person { public: Person() { setData("unknown-first", "unknown-last"); } Person(string first, string last) { setData(first, last); } void setData(string first, string last) { firstName = first; lastName = last; } void printData() const { cout << "\nName: " << firstName << " " << lastName << endl; } private: string firstName; string lastName; }; class Musician : public Person { public: Musician() { // TODO: set this...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT