B) In the main function, define one object of Discount Sale with (11, 10) initia
ID: 3839667 • Letter: B
Question
B) In the main function, define one object of Discount Sale with (11, 10) initial values and define another object of MailorderSale with (8,2) initial values. Then write statements to compare their bills using overloaded operator ‘<‘ and print appropriate messages.
Display for Q3. Interface for the Base Class Sale This is the header file sale. h. This is the interface for the class Sale. Sale is a class for simple sales. #ifndef SALE H #define SALE H #include ki ostream using namespace std; namespace sale savitch C Tass Sale pub Tic: Sale CD; Sale (doub 7e the price) virtua 7 double bi 11 O Const double savings Sale& other) const; calling object. Returns the savings if you buy other instead of the protected: double price boo T operator Cconst Sale& first, const Sale& second Compares two sa Tes to see which is Targer sa Tesa vitch Mendi f SALE HExplanation / Answer
//main.cpp
#ifndef SALE_H
#define SALE_H
#include<iostream>
using namespace std;
namespace salesavitch
{
class Sale
{
public:
Sale();
Sale(double the_price);
virtual double bill() const;
double savings(const Sale& other) const;
protected:
double price;
};
bool operator < (const Sale& first, const Sale& second) ;
}
#endif
using namespace salesavitch;
class MailorderSale : public salesavitch::Sale
{
double shipping_charge;
public:
MailorderSale(double shipping,double s);
double bill() const;
};
bool operator < (const MailorderSale& first, const MailorderSale& second);
Sale::Sale()
{
price = 0;
}
Sale::Sale(double p)
{
price = p;
}
double Sale::savings(const Sale& other) const
{
return price;
}
double Sale::bill() const
{
return price;
}
MailorderSale::MailorderSale(double p, double s) : Sale(p)
{
shipping_charge = s;
}
double MailorderSale::bill() const
{
return shipping_charge + price;
}
bool operator < (const Sale& first, const Sale& second)
{
if (first.bill() < second.bill())
{
return true;
}
else
{
return false;
}
}
bool operator < (const MailorderSale& first, const MailorderSale& second)
{
if (first.bill() < second.bill())
{
return true;
}
else
{
return false;
}
}
int main()
{
MailorderSale discontSale1(11, 10);
MailorderSale discontSale2(8, 2);
if (operator<(discontSale1, discontSale2))
{
cout << "first sale less than second sale" << endl;
}
else
{
cout << "Second sale less than second sale" << endl;
}
}
----------------------------------------------------------------
//output
Second sale less than second sale
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.