Mid-Term II Solution
Mid-Term II Solution
Fall-2019 (CS-Department)
Mid-term II Exam
Question 1:
Nine-Tails Gift Delivery Service allows users to book and send gifts. The service allows gifts to be
delivered at the doorstep reliably.
The service delivers three types of gifts; that are perfumes, chocolate cakes and flowers. Furthermore,
happy bundle is another gift type in which any two of these three gift items are sent together as gifts.
Each gift type has a unique category ID i.e. CK1 for cakes, FL1 for flowers, PF1 for perfumes and HB1 for
happy bundles.
There is another entity involved, the Taxation Department. The Taxation Department must have access
to the revenue and payable tax of Nine-Tails Delivery Service (but the Taxation Department does not
need to be able to access any other attributes).
The classes for this scenario are presented in Figure 1. Carefully read the assumptions below and then
perform the tasks given on the next page.
Assumptions:
1. You may create or modify any variables and override any functions if needed to satisfy the
requirements of the question. But their role in the program have to be justifiable.
2. The floral type can either be Rose, Tulip or Daisy. The unit price for each of these types is Rs. 50.
3. Perfumes and chocolate cakes are taxable gift items, but tax is not applicable on flowers.
4. The perfumes available are either from GUCCI, VERSACE or CHANEL. The unit price for perfume is Rs.
1200 for GUCCI, Rs. 1100 for VERSACE and Rs. 950 for CHANEL
5. The value given to weight variable for chocolate cake should be assumed as given in pounds
6. The price for chocolate cake is Rs. 700 per pound
7. The tax rate for perfume is 7% of the price and for chocolate cake it is 4% of the price.
Page 1 of 8
Figure 1
Tasks to be performed:
a. Identify the type(s) of inheritance present between the given classes and for each type of
inheritance that you identify, simply list down the classes involved in it.
b. Using the inheritance that you identified in Task 1, provide class declarations only.
class Gift { };
class Flowers: virtual public Gift { };
class Perfume: virtual public Gift { };
class ChocolateCake: virtual public Gift { };
class HappyBundle: public Flowers, public Perfume, public ChocolateCake { };
Page 2 of 8
c. In the classes, declare variables and also provide suitable implementation for constructor(s) of each
class. Overload the constructors wherever necessary. Also implement setter & getter functions for
every private variable.
class Gift
{
string catID;
bool taxApplicable;
int tax, price;
int quantity; // a variable added as per need
public:
static int payableTax;
static int revenue;
Page 3 of 8
class Perfume: virtual public Gift
{
string brand;
public:
static int stock;
Perfume()
{
}
public:
static int stock;
ChocolateCake()
{
}
ChocolateCake(int weight, string msgOnCake, int quantity)
{
setCatID("CK1");
setQuantity(quantity);
this->weight = weight;
this->msgOnCake = msgOnCake;
setPrice(700);
stock -= quantity;
Gift::revenue += getQuantity() * weight * getPrice();
Gift::payableTax += (getPrice() * 0.04);
}
};
Page 4 of 8
public:
HappyBundle(string brand, string floralType): Perfume(brand, 1), Flowers(floralType, 1)
{
setCatID("HB1");
p = true;
f = true;
}
d. Override the functions wherever necessary and show their implementations (in both the parent and
child classes).
class Gift
{
// other code
public:
virtual int bill() = 0;
};
}
};
Page 5 of 8
// other code
public:
int bill()
{
return getQuantity() * getPrice();
}
};
}
};
Page 6 of 8
e. Write the code for calling any function of the Perfume class using pointer variable of its parent class.
f. Override the variable tax in Perfume class and make it a constant with value 0.07 (for 7% tax).
g. For keeping track of the inventory, there must be a mechanism to find how much of each individual
gift item is remaining in stock. Also provide mechanism to see the current revenue (overall profit).
Keep in mind that each gift category has a different price.
class Gift
{
// other code
public:
static int revenue;
};
int Gift::revenue = 0; // initial profit/revenue
Page 7 of 8
h. Provide a copy constructor for copying objects of Flowers class.
Flowers(Flowers& ob)
{
setCatID(ob.getCatID());
setPrice(ob.getPrice());
floralType = ob.floralType;
setQuantity(ob.getQuantity());
stock -= ob.getQuantity();
Gift::revenue += ob.getQuantity() * ob.getPrice();
}
i. Provide mechanism for TaxationDept class to access the revenue and payable tax amount of Nine-
Tails Delivery Service.
class NineTails
{
string contactNo, officeAddress, email;
int tax, revenue;
public:
NineTails()
{
tax = Gift::payableTax;
revenue = Gift::revenue;
}
class TaxationDept
{
NineTails nt;
public:
void calculateTax()
{
cout << "Tax Payable: " << nt.tax << endl;
cout << "Revenue: " << nt.revenue << endl;
}
};
~ Good luck!
Page 8 of 8