Question: hello can you use the code i posted below and do the following tasks: 1 . Create an abstract class Item, having the abstract function:

hello can you use the code i posted below and do the following tasks:
1. Create an abstract class Item, having the abstract function: double GetTotalPrice()
2. Update the Artifact class to inherit Item
Driver Program:
Change the driver program from HW 1 to:
(1) Remove the Artifacts and Services vectors
(2) Add a new vector called Items, which contains pointers to Item instances
(3) Add at least 3 artifacts and 3 services to the Items collection
(4) Use a loop to calculate and display the total prices of all elements in the Items collection.
Here is the code:
#include
#include
#include
#include
enum DiscountTypeEnum { AMOUNT, PERCENTAGE };
class Item {
public:
virtual double GetTotalPrice() const =0;
virtual ~Item()= default;
};
class Division {
public:
std::string GUID;
std::string Name;
std::string PhoneNumber;
std::string Description;
Division* Parent;
Division(std::string guid, std::string name, std::string phone, std::string desc, Division* parent)
: GUID(guid), Name(name), PhoneNumber(phone), Description(desc), Parent(parent){}
};
class Artifact : public Item {
public:
std::string GUID;
std::string Name;
std::string Description;
std::string Category;
Division* DivisionPtr;
double Price;
double Discount;
DiscountTypeEnum DiscountType;
int Quantity;
Artifact(std::string guid, std::string name, std::string desc, std::string category,
Division* division, double price, double discount, DiscountTypeEnum discountType, int quantity)
: Item(), GUID(guid), Name(name), Description(desc), Category(category),
DivisionPtr(division), Price(price), Discount(discount), DiscountType(discountType), Quantity(quantity){}
double GetEffectivePrice() const {
if (DiscountType == AMOUNT)
return std::max(0.0, Price - Discount);
else
return std::max(0.0, Price - Price * Discount /100.0);
}
double GetTotalPrice() const override {
return std::max(0.0, Quantity * GetEffectivePrice());
}
};
class Service : public Item {
public:
double Duration;
double Rate;
double RateDiscount;
DiscountTypeEnum RateDiscountType;
Service(std::string guid, std::string name, std::string desc, std::string category,
Division* division, double price, double discount, DiscountTypeEnum discountType, int quantity,
double duration, double rate, double rateDiscount, DiscountTypeEnum rateDiscountType)
: Item(), Artifact(guid, name, desc, category, division, price, discount, discountType, quantity),
Duration(duration), Rate(rate), RateDiscount(rateDiscount), RateDiscountType(rateDiscountType){}
double GetEffectiveRate() const {
if (RateDiscountType == AMOUNT)
return std::max(0.0, Rate - RateDiscount);
else
return std::max(0.0, Rate - Rate * RateDiscount /100.0);
}
double GetTotalPrice() const override {
return std::max(0.0, Artifact::GetTotalPrice()+ GetEffectiveRate()* Duration);
}
};
int main(){
std::vector items;
items.push_back(new Artifact("ART1", "Laptop", "Sony Vaio", "Electronics",
nullptr, 185.99,30, PERCENTAGE, 5));
items.push_back(new Artifact("ART2", "Smartphone", "iPhone 12", "Electronics",
nullptr, 999.99,50, AMOUNT, 3));
items.push_back(new Artifact("ART3","T-shirt", "Cotton Casual Tee", "Clothing",
nullptr, 19.99,5, AMOUNT, 10));
items.push_back(new Service("SER1", "Custom Software Development", "Bespoke software solutions",
"Custom Development", nullptr, 0.0,0, AMOUNT, 1,10.5,50.0,10, PERCENTAGE));
items.push_back(new Service("SER2", "Graphic Design Service", "Creative graphic design services",
"Design", nullptr, 0.0,0, AMOUNT, 2,5.0,20.0,5, PERCENTAGE));
items.push_back(new Service("SER3", "Furniture Assembly Service", "Professional furniture assembly",
"Assembly", nullptr, 0.0,0, AMOUNT, 1,2.5,15.0,3, PERCENTAGE));
std::cout << "Total Prices of Items:
";
double totalPrices =0.0;
for (Item* item : items){
double itemTotalPrice = item->GetTotalPrice();
totalPrices += itemTotalPrice;
std::cout << "Total Price: $"<< itemTotalPrice << std::endl;
}
std::cout << "Overall Total Price: $"<< totalPrices << std::endl;
for (auto& item : items)
delete item;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!