C How to Program (8th Edition)
C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 19, Problem 19.9E

19.9 (Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping options, each with specific costs associated. Create an inheritance hierarchy to represent various types of packages. Use class Package as the base class of the hierarchy, then include classes TwoDayPackage and OvernightPackage that derive from Package. Base class Package should include data members representing the name, address, city, state and ZIP code for both the sender and the recipient of the package, in addition to data members that store the weight (in ounces) and cost per ounce to ship the package. Package ‘5 constructor should initialize these data members. Ensure that the weight and cost per ounce contain positive values. Package should provide a public member function calculatecost that returns a double indicating the cost associated with shipping the package. Package ‘5 calculatecost function should determine the cost by multiplying the weight by the cost per ounce. Derived class TwoDayPackage should inherit the functionality of base class Package, but also include a data member that represents a flat fee that the shipping company charges for two-day-delivery service. TwoDayPackage’s constructor should receive a value to initialize this data member. TwoDayPackage should redefine member function calculatecost 50 that it computes the shipping cost by adding the flat fee to the weight-based cost calculated by base class Package ‘S calculateCost function. Class OvernightPackage should inherit directly from class Package and contain an additional data member representing an additional fee per ounce charged for overnight-delivery service. OvernightPackage should redefine member function calculatecost so that it adds the additional fee per ounce to the standard cost per ounce before calculating the shipping cost. Write a test program that creates objects of each type of Package and tests member function calculatecost.

Blurred answer
Students have asked these similar questions
T/F 4) Consider the following class hierarchy: Refer to Example Code Ch 09-1: A is a derived class of X.
T/F 4) Consider the following class hierarchy:Refer to Example Code Ch 09-1:A is a derived class of X.
1/3 Part-1 (Objects and Classes) Create a Java Project (with a class and a test class) to represent some real-world entity such as a technology item (TV. Fan etc), an animal, a person, a vehicle, etc. In our class, we have already seen example classes such as Circle, Student, Rectangle, TV etc. The class will: a) Create a total of 5 member variables for the class by selecting the appropriate data types for each field. For example, a class to represent a lamp might include color, price, height, numBulbs, batteryOperated. Each of these 5 variables needs a data type. b) Include at least three different constructor methods, including the default constructor (no argument constructor), so totally three constructors. c) Create a method called showValues( ) to display the values of an object in a formatted manner, The Java test class (with a main method) will: a) Instantiate at least three objects (using each of the constructors at least once) with your program. b) Store the data from the…

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
The ____________ is always transparent.

Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)

What two questions should you ask to determine a classs responsibilities?

Starting Out with Java: From Control Structures through Objects (6th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY