Write a program for a retail store. The program will use three classes to identi
ID: 3856786 • Letter: W
Question
Write a program for a retail store. The program will use three classes to identify and store the characteristics of its different customers.
This three classes will include a base class and two derived classes.
Design a base class named PersonData_C which will have member variables for last name, first name, and zip code. These three variables must be declared private.
The PersonData_C class will contain the appropriate constructors, getters and setters, and a virtual member function named Display_Data which will display the last name. first name, and zip code.
The CustomerData_C class (derived from PersonData) will have two member variables: customerNumber will be used to hold a unique integer for each customer, and mailingList will be a bool which is set to true if the customer wishes to be on the mailing list and false if not.
The CustomerData_C class will override virtual function Display_Data, and this version will display the customer number and mailing list code plus the PersonData_C class data.
Also write the appropriate constructors, accessor and mutator member functions for this class.
The retail store has a "preferred customer plan" in which customers may earn discounts on all their purchases. The amount of a customer's discount for a current purchase is determined by the amount of the customer's prior cumulative purchases in the store:
-after customers spend $500 (not including current purchase), they get a 5% discount on the current and all subsequent purchases.
-after customers spend $1,000 (not including current purchase), they get a 6% discount on the current and all subsequent purchases.
-after customers spend $1,500 (not including current purchase), they get a 7% discount on the current and all subsequent purchases.
-after customers spend $2,000 (not including current purchase), they get a 10% discount on the current and all subsequent purchases.
Write a PreferredCustomer_C class (derived from CustomerData_C) which will have two member variables: purchasesAmount will hold the total of a customer's purchases to-date, and discountLevel should be set to the correct discount percentage based on the purchasesAmount and the store's "preferred customer plan" described above (note: whenever the purchasesAmount is updated, the discountLevel must be re-calculated).
This class will override virtual function Display_Data, and this version will display the purchase amount to-date and discount level plus the CustomerData_C class data and the PersonData_C class data.
The PreferredCustomer_C class will also need the appropriate constructors, setters, and getters, and a member function to purchase items, i. e., spend money, which will add to the purchase amount to-date (after discount, if any).
In main create a CustomerData_C object using constructor arguments customer number: 987654 and mailing list code: true, and first and last name: Norton Orton, and zip code: 56789.
Then in function Display_Customer_Info with a base class reference variable as a parameter, use the virtual function Display_Data to display this object’s data items (screen print this display).
In main, create a PreferredCustomer_C object using the default constructor, then have the user enter the following data and store it in the object:
-last name: McDaniels
-first name: McDougal
-zip code: 10001
-customer number: 222222
-mailing list: 1 (true)
-purchase amount to-date: $2000.00
Have this preferred customer make a $1,000 purchase (entered by the user), and in the function with the base class reference variable as a parameter, use the virtual function Display_Data to display the information stored in the PreferredCustomer_C object's 7 data items (screen print the data entry and this display).
Attachments
Explanation / Answer
The answer is as follows:
The code is as follows:
#include<iostream.h>
#include<string>
class PersonData_C {
private:
string lastname;
string firstname;
int zipcode;
public:
PersonData_C(string lname, string fnmae, int zip){
lastname = lname;
firstname = fname;
zipcode = zip;
}
virtual void Display_Data(){
cout << "Last name:" << lastname << endl;
cout << "First name:" << firstname << endl;
cout << "Zip Code:" << zipcode << endl;
}
void setLastName(string name){
lastname = name;
}
void setFirstName(string name){
firstname = name;
}
void setZipCode(int code){
zipcode = code;
}
string getLastName(){
return lastname;
}
string getFirstName(){
return firstname;
}
int getZipCode(){
return zipcode;
}
};
class CustomerData_C: public PersonData_C {
private:
int customerNumber;
bool mailingList;
public:
CustomerData_C(string lname, string fnmae, int zip, int custNo, bool mailList) : PersonData_C (string lname, string fnmae, int zip){
customerNumber = custNo;
mailingList = mailList;
}
void Display_Data(){
PersonData_C::Display_Data();
cout << "Customer Number:" << customerNumber << endl;
cout << "MailingList:" << mailingList << endl;
}
void setCustomerNumber(int num){
customerNumber = num;
}
void setMailingList(bool opt){
mailingList = opt;
}
int getCustomerNumber(){
return customerNumber;
}
bool getMailingList(){
return mailingList;
}
};
class PreferredCustomer_C: public CustomerData_C {
private:
double purchaseAmount;
double discountLevel;
public:
PreferredCustomer_C(string lname, string fnmae, int zip, int custNo, bool mailList, double puramount, double disc) :
CustomerData_C (string lname, string fnmae, int zip, int custNo, bool mailList){
purchaseAmount = puramount;
discountLevel = disc;
}
void Display_Data(){
CustomerData_C::Display_Data();
cout << "Purchase Amount:" << purchaseAmount << endl;
cout << "Discount level:" << discountLevel << endl;
}
void setPurchaseAmount(double amt){
purchaseAmount = amt;
}
void setDiscountLevel(double disc){
discountLevel = disc;
}
double getPurchaseAmount(){
return purchaseAmount;
}
double getDiscountLevel(){
return discountLevel;
}
void spendMoney(double amt){
purchaseAmount = purchaseAmount + amt;
if (purchaseAmount >= 500 && purchaseAmount < 1000)
discountLevel = 0.05;
if (purchaseAmount >= 1000 && purchaseAmount < 1500)
discountLevel = 0.06;
if (purchaseAmount >= 1500 && purchaseAmount < 2000)
discountLevel = 0.07;
if (purchaseAmount >= 2000)
discountLevel = 0.1;
}
};
void main(){
string last,first;
int zip, custNum;
double puramt;
bool mlist;
CustomerData_C cust("Orton", "Norton",56789, true);
PreferredCustomer_C preCust;
PersonData_C *pdata;
pdata = &cust;
pdata->Display_Data();
cout << "Enter last name:"
cin >> last;
cout << "Enter first name:"
cin >> first;
cout << "Enter zip code:"
cin >> zip;
cout << "Enter Customer Number:"
cin >> custNum;
cout << "Enter mailing list:"
cin >> mlist;
cout << "Enter purchase amount to-date:"
cin >> puramt;
preCust.setLastName(last);
preCust.setFirstName(first);
preCust.setZipCode(zip);
preCust.setCustomerNumber(custNum);
preCust.setMailingList(mlist);
preCust.setPurchaseAmount(puramt);
preCust.spendMoney(1000);
pdata = &preCust;
p->Display_Data();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.