Write a base class, Package. This class represents a package, it should contain its weight in kilos and the cost per kilo to ship the package. It should also have a public member function, calculateCost(), that calculates the cost for the package to ship. This class’ constructor should accept values to initialize its weight and cost per kilo. Package’s calculateCost() should return a double by multiplying its weight by the cost per kilo. Create a derived class, TwoDayPackage, that inherits from Package. Add a data member that represents a flat-fee for the two-day delivery ser- vice. This class’ constructor should accept a value to initialize this fee. Override TwoDayPackage’s calculateCost() to add the flat-fee on top of the standard cost. NOTE: that the standard cost calculation could change, so don’t assume the standard cost is just weight times cost per weight. Create another derived class, OvernightPackage, that inherits from Package. Add a data member that represents an additional fee per kilo for the overnight delivery service. This class’ constructor should accept a value to initialize this fee. Override OvernightPackage’s calculateCost() to add the fee per kilo to the standard cost. Accept 4 doubles to represent: • the weight of the package, • cost per kilo to ship, • flat fee for the 2 day package, and • additional fee per kilo for overnight Print out the cost for the standard package, two day package, and overnight package on 1 line.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

C++ PROGRAM(Package-delivery)

Write a base class, Package. This class represents a package, it should
contain its weight in kilos and the cost per kilo to ship the package. It should also have a public member function, calculateCost(), that calculates the cost for the package to ship. This class’ constructor should accept values to initialize its weight and cost per kilo. Package’s calculateCost() should return a double by multiplying its weight by the cost per kilo.

  • Create a derived class, TwoDayPackage, that inherits from Package.
    Add a data member that represents a flat-fee for the two-day delivery ser-
    vice. This class’ constructor should accept a value to initialize this fee.
  • Override TwoDayPackage’s calculateCost() to add the flat-fee on top of the standard cost. NOTE: that the standard cost calculation could change, so don’t assume the standard cost is just weight times cost per weight.
  • Create another derived class, OvernightPackage, that inherits from Package. Add a data member that represents an additional fee per kilo for the overnight delivery service. This class’ constructor should accept a value to initialize this fee.
  • Override OvernightPackage’s calculateCost() to add the fee per kilo to the standard cost.
  • Accept 4 doubles to represent:
    • the weight of the package,
    • cost per kilo to ship,
    • flat fee for the 2 day package, and
    • additional fee per kilo for overnight
  • Print out the cost for the standard package, two day package, and overnight package on 1 line.

Sample Input

1 5 80 150 80

Sample Output

1 400.00 550.00 800.00

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY