Question: can you help me with the followin task ( ID number 2 0 0 1 9 2 2 3 2 ) : Implement the KMP
can you help me with the followin taskID number :
Implement the KMP or BM string pattern matching algorithm. If your ID number is odd implement
KMP otherwise if even implement BM
Driver Program:
Modify the classes code if needed and write a program to show the items that contain a certain
search string entered by the user in their name. Your code should traverse only the Items collection that
contains pointers to objects of both Artifact and Service classes.
After using the above algorithm to find which items contain the string, display their names and GUID,
ordered by the number of occurrences of the string, from high to low.
Here is the code you have to use:
#include
#include
#include
#include
enum DiscountTypeEnum AMOUNT, PERCENTAGE ;
class Item
public:
virtual double GetTotalPrice const ;
virtual std::string GetName const ;
virtual std::string GetCategory 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 Quantity GetEffectivePrice;
std::string GetName const override
return Name;
std::string GetCategory const override
return Category;
;
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 duration, double rate, double rateDiscount, DiscountTypeEnum rateDiscountType
: Item 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 Duration GetEffectiveRate;
std::string GetName const override
return "Service";
std::string GetCategory const override
return "Service";
;
void Mergestd::vector& items, int left, int mid, int right
int n mid left ;
int n right mid;
std::vector Ln Rn;
for int i ; i n; i
Li itemsleft i;
for int j ; j n; j
Rj itemsmid j;
int i ; Initial index of first subarray
int j ; Initial index of second subarray
int k left; Initial index of merged subarray
while i n && j n
if LiGetTotalPrice RjGetTotalPrice
itemsk Li;
i;
else
itemsk Rj;
j;
k;
while i n
itemsk Li;
i;
k;
while j n
itemsk Rj;
j;
k;
void Mergesortstd::vector& items, int left, int right
if left right
return; Returns recursively
int mid left right left;
Mergesortitems left, mid;
Mergesortitems mid right;
Mergeitems left, mid, right;
int main
std::vector items;
Adding items to the vector
items.pushbacknew ArtifactART "Laptop", "Highperformance laptop", "Electronics", nullptr, PERCENTAGE, ;
items.pushbacknew ArtifactART "Smartphone", "Latest model smartphone", "Electronics", nullptr, AMOUNT, ;
items.pushbacknew A
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
