Problem Solving with C++ (9th Edition)
Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 15.3, Problem 11STE

Explanation of Solution

Program:

File name: sale.h

//include libraries

#ifndef SALE_H

#define SALE_H

#include <iostream>

using namespace std;

//using the namespace

namespace salesavitch

{

    //create a class

    class Sale

    {

        //define access specifier

        public:

        //declare the constructors

        Sale();

        Sale(double thePrice);

        //define required methods

        double bill() const;

        double savings(const Sale& other) const;

        //define access specifier

        protected:

        //declare required variables

        double price;

    };

    //define an overloaded method

    bool operator <(const Sale& first, const Sale&

  second);

}

#endif // SALE_H

File name: discount.h

//include libraries

#ifndef DISCOUNTSALE_H

#define DISCOUNTSALE_H

#include "sale.h"

//using the namespace

namespace salesavitch

{

    //create a class

    class DiscountSale : public Sale

    {

        //define access specifier

        public:

        //declare the constructors

        DiscountSale();

        DiscountSale(double the_price, double the_discount);

        //Discount is expressed as a percent of the price.

        virtual double bill() const;

        //define access specifier

        protected:

        //declare required variable

        double discount;

    };

}

#endif //DISCOUNTSALE_H

File name: sale.cpp

//include libraries

#include "sale.h"

//using the namespace

namespace salesavitch

{

    //define a constructor

  Sale::Sale() : price(0)

  {}

    //define a constructor

  Sale::Sale(double the_price) : price(the_price)

  {}

    //declare a method

  double Sale::bill() const

  {

        //return statement

  return price;

  }

    //declare a method

  double Sale::savings(const Sale& other) const

  {

        //return statement

  return ( bill() - other...

Blurred answer
Students have asked these similar questions
First, you need to design, code in Java, test and document a base class, Student. The Student class will have the following information, and all of these should be defined as Private: A. A first name (given name)B. A last name (family name/surname)C. Student number (ID) – an integer number (of type long)D. A date of birth (in day/month/year format – three integers) - (Create your own Date class, the Date class should be a separate class from this. Do NOT use the Date class from JAVA.)The Student class will have at least the following constructors and methods:(i) two constructors - one without any parameters (the default constructor), and one with parameters to give initial values to all the instance variables of Student. (ii) only necessary set and get methods for a valid class design. (iii) a reportGrade method, which you have nothing to report here, you can just print to the screen a message “There is no grade here.”. This method will be overridden in the respective child…
A. Writing an Interface In this problem you will first write an interface and then modify classes to implement the interface. Write an interface, GeometricSolid, which has one method, volume. The volume method takes no arguments and returns a double. You are provided with three classes: Cylinder, Sphere, and RightCircularCone Modify the classes so that they implement the GeometricSolid interface. Supply the appropriate method for each class. You can use Google search to find the formula for the volume. Make sure that you use Math.PI in your calculations. Notice in InterfaceRunner that the objects are added to an ArrayList of GeometricSolids. since I couldn't fit all images with two screen shots I left the link here link: https://codecheck.it/files/18040616319p6jy6gzkdzuq08nmlp81251t
Create a base class called Insect. All insects belong to an Order [i.e. “Hemiptera” (ants),  “Siphonaptera” (fleas), “Termitoidae” (termites), “Gryllidae” (crickets), etc.] and have a size that is measured in millimeters (use a double data type). Provide a default constructor that initializes the size to zero and outputs the message “Invoking the default Insect constructor” and another constructor that allows the Order and size to be set by the client. This other constructor should also output the message “Invoking the 2-argument Insect constructor.”  Also create a destructor for this class that outputs the message “Invoking the default Insect destructor.” Your Insect class should have a function called Eat that cannot be implemented.  That is, it should be declared as a purely virtual function. Your class should also have Get and Set methods to allow the order and size to be accessed.

Chapter 15 Solutions

Problem Solving with C++ (9th Edition)

Knowledge Booster
Background pattern image
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