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:
Create an abstract class Item, having the abstract function: double GetTotalPrice
Update the Artifact class to inherit Item
Driver Program:
Change the driver program from HW to:
Remove the Artifacts and Services vectors
Add a new vector called Items, which contains pointers to Item instances
Add at least artifacts and services to the Items collection
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 ;
virtual ~Item default;
;
class Division
public:
std::string GUID;
std::string Name;
std::string PhoneNumber;
std::string Description;
Division Parent;
Divisionstd::string guid, std::string name, std::string phone, std::string desc, Division parent
: GUIDguid Namename PhoneNumberphone Descriptiondesc Parentparent
;
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;
Artifactstd::string guid, std::string name, std::string desc, std::string category,
Division division, double price, double discount, DiscountTypeEnum discountType, int quantity
: Item GUIDguid Namename Descriptiondesc Categorycategory
DivisionPtrdivision Priceprice Discountdiscount DiscountTypediscountType Quantityquantity
double GetEffectivePrice const
if DiscountType AMOUNT
return std::max Price Discount;
else
return std::max Price Price Discount ;
double GetTotalPrice const override
return std::max Quantity GetEffectivePrice;
;
class Service : public Item
public:
double Duration;
double Rate;
double RateDiscount;
DiscountTypeEnum RateDiscountType;
Servicestd::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 Artifactguid name, desc, category, division, price, discount, discountType, quantity
Durationduration Raterate RateDiscountrateDiscount RateDiscountTyperateDiscountType
double GetEffectiveRate const
if RateDiscountType AMOUNT
return std::max Rate RateDiscount;
else
return std::max Rate Rate RateDiscount ;
double GetTotalPrice const override
return std::max Artifact::GetTotalPrice GetEffectiveRate Duration;
;
int main
std::vector items;
items.pushbacknew ArtifactART "Laptop", "Sony Vaio", "Electronics",
nullptr, PERCENTAGE, ;
items.pushbacknew ArtifactART "Smartphone", "iPhone "Electronics",
nullptr, AMOUNT, ;
items.pushbacknew ArtifactARTTshirt", "Cotton Casual Tee", "Clothing",
nullptr, AMOUNT, ;
items.pushbacknew ServiceSER "Custom Software Development", "Bespoke software solutions",
"Custom Development", nullptr, AMOUNT, PERCENTAGE;
items.pushbacknew ServiceSER "Graphic Design Service", "Creative graphic design services",
"Design", nullptr, AMOUNT, PERCENTAGE;
items.pushbacknew ServiceSER "Furniture Assembly Service", "Professional furniture assembly",
"Assembly", nullptr, AMOUNT, PERCENTAGE;
std::cout "Total Prices of Items:
;
double totalPrices ;
for Item item : items
double itemTotalPrice itemGetTotalPrice;
totalPrices itemTotalPrice;
std::cout "Total Price: $ itemTotalPrice std::endl;
std::cout "Overall Total Price: $ totalPrices std::endl;
for auto& item : items
delete item;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
