Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ programming A retail store has a preferred customer plan where customers may

ID: 3673511 • Letter: C

Question

C++ programming

A retail store has a preferred customer plan where customers may earn discounts on all their purchases.The amount of a customer’s discount is determined by the amount of the customer’s cumulative purchases in the store.

• When a preferred customer spends $500, he or she gets a 5% discount on all future purchases.

• When a preferred customer spends $1,000, he or she gets a 6% discount on all future purchases.

• When a preferred customer spends $1,500, he or she gets a 7% discount on all future purchases.

• When a preferred customer spends $2,000 or more, he or she gets a 10% discount on all future purchases.

Design a class named PreferredCustomer , which is derived from the CustomerData class you created in Programming Challenge 7. The PreferredCustomer class should have the following member variables:

• purchasesAmount (a double ) • discountLevel (a double )

The purchasesAmount variable holds the total of a customer’s purchases to date. The discountLevel variable should be set to the correct discount percentage, according to the store’s preferred customer plan. Write appropriate member functions for this class and demonstrate it in a simple program. Input Validation: Do not accept negative values for any sales figures.

Explanation / Answer

PreferredCustomer.h

#ifndef PREFERREDCUSTOMER_H
#define   PREFERREDCUSTOMER_H

#include "CustomerData.h"

class PreferredCustomer : public CustomerData {
private:
    double purchasesAmount;
    double discountLevel;
    void setDiscountLevel(double discountLevel);
public:
    PreferredCustomer();

    double getDiscountLevel() const;
    void setPurchasesAmount(double purchasesAmount);
    double getPurchasesAmount() const;


};

#endif   /* PREFERREDCUSTOMER_H */


CustomerData.CPP

#include "CustomerData.h"

CustomerData::CustomerData() {
}

void CustomerData::setMailingList(bool mailingList) {
    this->mailingList = mailingList;
}

bool CustomerData::isMailingList() const {
    return mailingList;
}

void CustomerData::setCustomerNumber(int customerNumber) {
    this->customerNumber = customerNumber;
}

int CustomerData::getCustomerNumber() const {
    return customerNumber;
}


CustomerData.h
#ifndef CUSTOMERDATA_H
#define   CUSTOMERDATA_H

#include "PersonData.h"

class CustomerData : public PersonData {
private:
    int customerNumber;
    bool mailingList;
public:
    CustomerData();

    void setMailingList(bool mailingList);

    bool isMailingList() const;

    void setCustomerNumber(int customerNumber);
  
    int getCustomerNumber() const;

};

#endif   /* CUSTOMERDATA_H */

PersonData.cpp
#include "PersonData.h"

PersonData::PersonData() {
}

void PersonData::setPhone(string phone) {
    this->phone = phone;
}

string PersonData::getPhone() const {
    return phone;
}

void PersonData::setZip(int zip) {
    this->zip = zip;
}

int PersonData::getZip() const {
    return zip;
}

void PersonData::setState(string state) {
    this->state = state;
}

string PersonData::getState() const {
    return state;
}

void PersonData::setCity(string city) {
    this->city = city;
}

string PersonData::getCity() const {
    return city;
}

void PersonData::setAddress(string address) {
    this->address = address;
}

string PersonData::getAddress() const {
    return address;
}

void PersonData::setFirstName(string firstName) {
    this->firstName = firstName;
}

string PersonData::getFirstName() const {
    return firstName;
}

void PersonData::setLastName(string lastName) {
    this->lastName = lastName;
}

string PersonData::getLastName() const {
    return lastName;
}

PersonData.h

#ifndef PERSONDATA_H
#define   PERSONDATA_H

#include <string>
using namespace std;

class PersonData {
private:

    string lastName;
    string firstName;
    string address;
    string city;
    string state;
    int zip;
    string phone;

public:
    PersonData();

    void setPhone(string phone);

    string getPhone() const;

    void setZip(int zip);

    int getZip() const;

    void setState(string state);

    string getState() const;

    void setCity(string city);

    string getCity() const;

    void setAddress(string address);

    string getAddress() const;

    void setFirstName(string firstName);

    string getFirstName() const;

    void setLastName(string lastName);

    string getLastName() const;

};

#endif   /* PERSONDATA_H */

PreferredCustomer.cpp

#include "PreferredCustomer.h"

PreferredCustomer::PreferredCustomer() {

}

void PreferredCustomer::setDiscountLevel(double discountLevel) {
    this->discountLevel = discountLevel;
}

double PreferredCustomer::getDiscountLevel() const {
    return discountLevel;
}

void PreferredCustomer::setPurchasesAmount(double purchasesAmount) {

    if (purchasesAmount < 0) {
        purchasesAmount = 0.0;
    }
    this->purchasesAmount = purchasesAmount;

    if (purchasesAmount < 500) {
        setDiscountLevel(0.0);

    } else if ((500 <= purchasesAmount) && (purchasesAmount < 1000)) {
        setDiscountLevel(0.05);

    } else if ((1000 <= purchasesAmount) && (purchasesAmount < 1500)) {
        setDiscountLevel(0.06);

    } else if ((1500 <= purchasesAmount) && (purchasesAmount < 2000)) {
        setDiscountLevel(0.07);

    } else {
        setDiscountLevel(0.1);
    }

}

double PreferredCustomer::getPurchasesAmount() const {
    return purchasesAmount;
}

main.cpp
#include "PreferredCustomer.h"

PreferredCustomer::PreferredCustomer() {

}

void PreferredCustomer::setDiscountLevel(double discountLevel) {
    this->discountLevel = discountLevel;
}

double PreferredCustomer::getDiscountLevel() const {
    return discountLevel;
}

void PreferredCustomer::setPurchasesAmount(double purchasesAmount) {

    if (purchasesAmount < 0) {
        purchasesAmount = 0.0;
    }
    this->purchasesAmount = purchasesAmount;

    if (purchasesAmount < 500) {
        setDiscountLevel(0.0);

    } else if ((500 <= purchasesAmount) && (purchasesAmount < 1000)) {
        setDiscountLevel(0.05);

    } else if ((1000 <= purchasesAmount) && (purchasesAmount < 1500)) {
        setDiscountLevel(0.06);

    } else if ((1500 <= purchasesAmount) && (purchasesAmount < 2000)) {
        setDiscountLevel(0.07);

    } else {
        setDiscountLevel(0.1);
    }

}

double PreferredCustomer::getPurchasesAmount() const {
    return purchasesAmount;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote