EBK PROBLEM SOLVING WITH C++
EBK PROBLEM SOLVING WITH C++
9th Edition
ISBN: 9780133834505
Author: 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
Write a program to create class “Counter” having integer data member, overload the post increment, post decrement, pre increment and pre decrement for the class “Counter”
Create the class DynamicArrayOfStrings that implements the following two interfaces
Create a TestTriangle class in an individual .java file. In the main method,(1) Create a Triangle object with default base and height values.(2) Create a Triangle object with specified base = 3 and height =4.

Chapter 15 Solutions

EBK PROBLEM SOLVING WITH C++

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