Answered step by step
Verified Expert Solution
Question
1 Approved Answer
hello, can you help with the tasks below using the code i put at the end: Implement a function to apply the Quicksort or Mergesort
hello, can you help with the tasks below using the code i put at the end:
Implement a function to apply the Quicksort or Mergesort sorting algorithm. If your ID number is odd
implement Quicksort, otherwise if even implement Mergesortthe ID is
Driver Program:
Modify the classes code if needed and write a program to sort the collection of Items based on
their total price.
After the collection is sorted, use a loop to print the name, category and total price of each
element in the Items list.
Here is the code:
#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 Durationduration Raterate RateDiscountrateDiscount RateDiscountTyperateDiscountType
std::string artifactGuid guid;
std::string artifactName name;
std::string artifactDesc desc;
Division artifactDivision division;
double artifactPrice price;
double artifactDiscount discount;
DiscountTypeEnum artifactDiscountType discountType;
int artifactQuantity quantity;
Artifact artifactartifactGuid artifactName, artifactDesc, category, artifactDivision, artifactPrice, artifactDiscount, artifactDiscountType, artifactQuantity;
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 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, ;
Add services to the items vector
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::end;
for auto& item : items
delete item;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started