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;
}
The following class diagrams are designed for a restaurant that also provides home delivery services. Study...
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 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 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 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 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 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 / 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 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 { 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...