Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help creating this program in C++ in particular for implementing the public members for each class. In this mini project, you are asked to
Need help creating this program in C++ in particular for implementing the public members for each class.
In this mini project, you are asked to process two different types of coupons and determine how they may or may not affect the total of purchases. The starter project contains multiple files. The Date Class The "Date.h" file has started the definition of a Date class. It contains only one object-level data member, days_, that stores the number of days that have passed since the beginning of the year. That is, 0 refers to January 1,1 refers to January 2 , and so on. The default constructor has been implemented to set the days_data member to 0 , representing January 1. class Date \{ private: unsigned days_; public: Date( ); \} ; You are to add a class-level constant array of 12 elements, representing the numbers of days for the 12 months of a year. In addition, add the prototypes of the following functions to the "Date.h" file, implement them in the "Date.cpp" file, and demonstrate thorough testing in the "main.cpp" file. It's important that you ensure the Date class has been properly implemented and tested BEFORE working on the Coupon and PercentageCoupon classes. - The overloaded operator as a member function to support the comparison between two Date objects. The function shall return true if the Date object on the left of > has a later date than the Date object on the right. Otherwise, false shall be returned. For example, given the following code segment: Date pi_day, april_fool; piday ="3/14"; april_fool ="4/1"; cout boolalpha; cout "pi_day > pi_day returns "(piday >pi_day ) endl cout "pi_day > april_fool returns " ( pi_day > april_fool ) endl; cout "april_fool > pi_day returns " (april_fool >pi_day endl; Here's its expected output: pi_day > pi_day returns false pi_day > april_fool returns false april_fool > p_day returns true The Coupon Class This class is created to handle coupons like the following. Add the "Coupon.h" and "Coupon.cpp" files to define and implement the following Coupon class. Add appropriate statements in the main function to perform thorough testing of related member functions in the "main.cpp" file. class Coupon \{ protected: Date expiration_; //expiration date for a coupon double discount_; //the amount of discount for the coupon bool has_expired(const string & ) const; public: Coupon(const string \( \begin{array}{l}\text { double apply(const string } \& \text {, double) const; } \\ \text { doning to_string() const; }\end{array} \) s; Here is more information about the member functions of the Coupon class. Coupon(const string &, double); This function is to create a Coupon object by setting the expiration date according to the first parameter and the discount amount according to the second parameter. You may assume that the first parameter will always have a valid date in a non-leap year, using the format of "M/D" and the second parameter will always be positive. string to_string( ) const; This function is to return a string explaining the invoking Coupon object. For example, given the following code segment: Coupon c("2/14", 2.50); cout c.to_string () end ; Here's its expected output: The coupon is $2.50 0FF by 02/14. Hint: The MM/DD format of a date can be extracted using the operators. First, the operator overloaded for the Date class can be used to send the following into a stringstream object since stringstream is a derived class of the ostream class. After that, you can use the operator to extract the "02/14" part of the above stringstream object into a string variable. bool has_expired(const string\&) const; This function is to return true if the expiration date of the invoking object is before the date represented in the string parameter, false otherwise. Again, you may assume that the string parameter will always have a valid date in a non-leap year, using the format of "M/D". To help you test this function, you may temporarily move it from protected into public. It's important to make sure this function is working properly before working on the apply member function. double apply(const string &, double) const; This function is to first call the has_expired function to verify whether the coupon has expired on the date represented in the string parameter. - If the coupon has expired, the function shall not apply any discount. Instead, it shall return the purchase amount, which is provided by the double parameter of the function. - If the coupon has not expired but the purchase amount is less than the discount amount of the invoking coupon, the function shall not apply any discount. Instead, it shall return the purchase amount. - If the coupon has not expired and the purchase amount is the same or more than the discount amount of the invoking coupon, the function shall apply the discount and return the remaining cost. The PercentageCoupon Class This class is defined to handle coupons like the following. Add the "PercentageCoupon.h" and "PercentageCoupon.cpp" files to define and implement the following derived class of the Coupon class. In the main function, add appropriate statements to perform thorough testing of related member functions in the "main.cpp" file. class PercentageCoupon : public coupon \{ public: PercentageCoupon(const string\& date, unsigned percent =0 ); double apply(const string\&, double) const; string to_string() const; P; PercentageCoupon(const string\& date, unsigned percent =0 ); This constructor is to create a new PercentageCoupon object using the parameters provided. Again, you may assume that string parameter will take the format of "M/D" and represent a valid date in a non-leap year. string to_string( ) const; This function is to override the to_string function in the base class and return a string explaining the invoking PercentageCoupon object. For example, given the following code segment: PercentageCoupon pc ("2/14", 10); cout pc.to_string () endl; Here's its expected output: The coupon is 10% 0FF by 02/14. double apply(const string &, double) const; This function is to override the apply function in the base class. - If the coupon has expired or if the purchase amount is negative, the function shall not apply any discount. Instead, it shall return the purchase amount. - If the coupon has not expired and the purchase amount positive, the function shall apply the discount and return the reduced costStep 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