0% found this document useful (0 votes)
36 views

Part 1 Explanation Code

The document outlines the class structure needed to model a package delivery system. There will be an abstract Package class with Sender and Receiver objects. Concrete classes like StandardPackage, OvernightPackage, and TwoDayPackage will inherit from Package and override its pure virtual functions to calculate costs and display details polymorphically. The Sender and Receiver classes will contain address information and be composed within Package.

Uploaded by

Talha Rizwan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Part 1 Explanation Code

The document outlines the class structure needed to model a package delivery system. There will be an abstract Package class with Sender and Receiver objects. Concrete classes like StandardPackage, OvernightPackage, and TwoDayPackage will inherit from Package and override its pure virtual functions to calculate costs and display details polymorphically. The Sender and Receiver classes will contain address information and be composed within Package.

Uploaded by

Talha Rizwan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Part 1).

Identify the classes needed to implement the above system and the
relationship between those classes. Please give the interface
(prototype) of the classes you have decided in this part.

Answer:
From the statement we can conclude that there will be an abstract
class of “Package” which will link the different types of packages
together. The prototype of the Abstract class “Package” will be
class Package
{
protected:
Sender *S1;
Receiver *R1;
double weight;
double StandardCostPerKG;
double totalcost;
public:
virtual double costOfPackage() = 0;
virtual void display() = 0;
};

In the Package class we have also declared two objects of classes


Sender and Receiver by composition because
Sender has a Package
Receiver has/will have a Package
class Receiver
{
protected:
string name;
Address* R1;
string mobileNumber;
public:
//Default Constructor
Receiver();

//Non Default Constructor


Receiver(string iName, Address* iR1, string iMobileNo);

//Display Function (if needed)


void displayAddress();
};

class Sender
{
protected:
string name;
Address* A1;
string mobileNumber;
public:
//Default Constructor
Sender();

//Non Default Constructor


Sender(string iName, Address *iS1, string iMobileNo);

//Display Function (if needed)


void displayAddress();

};

An object of Address will also be declared in Sender and Receiver


classes via composition because
A Sender has an Address
A Receiver has an Address
From the statement we also know that there are three types of
Packages
 Standard Delivery Package
 Overnight Delivery Package
 Two Day Delivery Package
Since Standard Delivery Package is a Package
Overnight Delivery Package is a Package
And Two Day Delivery is a Package
We can conclude that all three types of package will inherit from the
Package Abstract Class and will inherit protected variables and public
functions from the abstract class of Package via public inheritance

class StandardPackage:public Package


{
public:
//Non Default Constructor
StandardPackage(Sender *iS1, Receiver *iR1, double iweight, double
iStandardCostPerKG);

double costOfPackage();
void display();
};
class OvernightPackage :public Package
{
protected:
double AdditionalCost;
public:
//Non Default Constructor
OvernightPackage(Sender *iS1, Receiver *iR1, double iweight, double
iStandardCostPerKG,double iAddCost);

double costOfPackage();
void display();
};

class TwoDayPackage :public Package


{
protected:
double FlatFee;
public:
//Non Default Constructor
TwoDayPackage(Sender *iS1, Receiver *iR1, double iweight, double
iStandardCostPerKG, double iFlatFee);

double costOfPackage();
void display();
};

Pure virtual functions of double costOfPackage(); and void display(); will


link all Package classes and will demonstrate polymorphism in these
classes.

Part 2 or the implementation of all these classes are in the provided


.cpp and .h files which include the driver.cpp file

You might also like