Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the class, derived class, and the virtual functions as shown in Display

ID: 3821119 • Letter: C

Question

Consider the class, derived class, and the virtual functions as shown in Display for Q3. Create a derived class (of Sale) called 'MailorderSale' having one private member variable called 'shipping_charge'. It should have constructor function and virtual function 'bill' (this function adds shipping_charge to the price). Define all these functions (no need of default constructors) In the main function, define one object of DiscountSale with (11, 10) initial values and define another object of MailorderSale with (8, 2) initial values. Then write statements to compare their bills using overload operator '

Explanation / Answer

#include<iostream.h>

class DiscountSale;

class MailorderSale;

class Sale
{
protected:
double price;
public:
   virtual void bill()=0;
   virtual void display()
   {

   }
};


class DiscountSale : public Sale
{
private:
   float dis;
   double payamt;
public:

   DiscountSale(double p,float d)
   {
   price=p;
   dis=d*0.01;
   }

   void bill()
   {
   payamt=price -(price*dis);
   }

   void display()
   {
   cout<<" Total Purchase amount :"<<price;
   cout<<" discount Amount :"<<(price*dis);
   cout<<" Payment amount after discount :"<<payamt;
   }
};

class MailorderSale : public Sale
{

private:
   double shipping_charge;
   double payamt;
public:

   MailorderSale(double p,double sc)
   {
   price =p;
   shipping_charge=sc;
   }

   void bill()
   {
   payamt=price +shipping_charge;
   }

   void display()
   {
   cout<<" Shipping Charge :"<<shipping_charge;
   cout<<" Price :"<<price;
   cout<<" Pay amount :"<<payamt;
   }
};


int main()
{
Sale *s;
DiscountSale ds(11,10);
MailorderSale ms(8,2);
s=&ds;
cout<<" ===ITEM 1 DISCOUNT SALE==="<<endl;
s->bill();
s->display();
s=&ms;
cout<<" ==ITEM 2 MAILORDER SALE==="<<endl;
s->bill();
s->display();
}