Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you find the mistake in the code i pasted bellow and help me with the following task: Implement a function to apply the Quicksort
Can you find the mistake in the code i pasted bellow and help me with the following task:
Implement a function to apply the Quicksort or Mergesort sorting algorithm. If your ID number is odd
implement Quicksort, otherwise if even implement Mergesort.
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.
#include
#include
#include
#include
enum DiscountTypeEnum AMOUNT, PERCENTAGE ;
class Item
public:
virtual double GetTotalPrice const ;
virtual ~Item default; Use the default virtual destructor for proper cleanup
;
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,
items.pushbacknew ServiceSER "Custom Software Development", "Bespoke software solutions",
"Custom Development", nullptr, AMOUNT, PERCENTAG;
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
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