Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Customer Class (please finish as fast as possible) The following class named Customer can be used to keep track of the purchases made by

C++ Customer Class (please finish as fast as possible)

The following class named Customer can be used to keep track of the purchases made by customers in some store. The class accumulates the total time elapsed since the customer's first and last purchases.

Your job consists of completing the definitions of the following missing methods:

  • Exercise #1: Customer(long ID, string firstName, string lastName) constructor
  • Exercise #2: purchase(float amount) method
  • Exercise #3: isLoyal() method
  • Exercise #4: nextForCoupon(Employee e2) method
  • Exercise #5: compareLastNames(Employee e2) method

Each exercise is independent of the others, so you may work on them in any order.

To make your job easier please consider following these recommendations:

  • Read all the exercises before your start working.
  • Work first on the exercises that you consider easier for you.
  • Read the test cases to clarify any doubts about how the methods should work
  • Code and test your solutions in VSCode before pasting them into Moodle. Use the debugger.
  • Avoid getting stuck in an exercise. If you cannot solve it in a reasonable amount of time, move to the next one.
  • Paste each exercise solution to Moodle as soon as you finish it. Do not wait until your time is running out to start pasting solutions.

You can use the following starter code to work your solutions on Visual Studio Code.

#include #include #include #include

using namespace std;

class Customer {

private: long ID; string firstName; string lastName; float purchases; int yearsSinceLastPurchase; int yearsSinceFirstPurchase;

public: // Getters long getID() { return ID; } string getFirstName() { return firstName; } string getLastName() { return lastName; } float getPurchases() { return purchases; } int getYearsSinceLastPurchase() { return yearsSinceLastPurchase; } int getYearsSinceFirstPurchase() { return yearsSinceFirstPurchase; }

// Setters void setID(long id) { ID = id; } void setFirstName(string fn) { firstName = fn; } void setLastName(string ln) { lastName = ln; } void setPurchases(float s) { purchases = s; } void setYearsSinceLastLastPurchase(int y) { yearsSinceLastPurchase = y; } void setYearsSinceFirstPurchase(int y) { yearsSinceFirstPurchase = y; }

// Constructors

Customer(long id, string fn, string ln, float sal, int yslp, int ysfp) { ID = id; firstName = fn; lastName = ln; purchases = sal; yearsSinceLastPurchase = yslp; yearsSinceFirstPurchase = ysfp; }

// DO NOT EDIT OR CHANGE THIS METHOD void display() // Used to display tcst case results { cout << fixed; cout << setprecision(2); cout << "ID: " << this->getID(); cout << " / First Name: " << this->getFirstName(); cout << " / Last Name: " << this->getLastName(); cout << " / Purchases: " << this->getPurchases(); cout << " / Years Since Last Purchase: " << this->getYearsSinceLastPurchase(); cout << " / Years Since First Purchase: " << this->getYearsSinceFirstPurchase() << endl; }

// EXERCISE #1 // Contructor creates new Customer with defaul initial Purchases of 0 // and 0 years since last and first purchases Customer(long ID, string fn, string ln);

// Instance methods

// EXERCISE #2 // Register a new purchase by the target Customer of a fixed amount (parameter) . // Round to smallest dollar amount. // Reset years since last purchase. void purchase(float amount);

// EXERCISE #3 // Returns true if target Customer has reached loyalty level and false otherwise. // A loyalty level is reached after purchases of at least 1 thousand dollars // and over 5 years since the first purchase. bool isLoyal();

// EXERCISE #4 // Returns true target Customer should get a coupon before parameter Customer, // and false if parameter Customer should get coupon first. // Customers with the longest time since last purchase should get a coupon first. // bool nextForCoupon(Customer e2);

// EXERCISE #5 // Returns an int > 1 if target Customer's last name goes before target Customer // alphabetically decreasing by last name, an int < 1 if parameter Customer should go first, // and zero otherwise. // HINT: Uses compariosn methods from the string class int compareLastNames(Customer e2); };

// EXERCISE #1 // Contructor creates new Customer with defaul initial Purchases of 0 // and 0 years since last and first purchases Customer::Customer(long id, string fn, string ln) { // YOUR CODE }

// Instance methods

// EXERCISE #2 // Register a new purchase by the target Customer of a fixed amount (parameter) . // Round to smallest dollar amount. // Reset years since last purchase. void Customer::purchase(float amount) { // YOUR CODE }

// EXERCISE #3 // Returns true if target Customer has reached loyalty level and false otherwise. // A loyalty level is reached after purchases of at least 1 thousand dollars // and over 5 years since the first purchase. bool Customer::isLoyal() { return false; }

// EXERCISE #4 // Returns true target Customer should get a coupon before parameter Customer, // and false if parameter Customer should get coupon first. // Customers with the longest time since last purchase should get a coupon first. // bool Customer::nextForCoupon(Customer e2) { return false; }

// EXERCISE #5 // Returns an int > 1 if target Customer's last name goes before target Customer // alphabetically decreasing by last name, an int < 1 if parameter Customer should go first, // and zero otherwise. // HINT: Uses compariosn methods from the string class int Customer::compareLastNames(Customer e2) { return 0; }

int main() {

// tcst cases

// EXERCISE #1 Customer tc1(2, "Bienve", "Velez"); tc1.display();

// EXERCISE #2 Customer tc2(1, "Juan", "del Pueblo", 50000, 0, 0); tc2.purchase(10000); tc2.display();

// EXERCISE #3 Customer tc3(2, "Bienve", "Velez"); cout << (tc3.isLoyal() ? "TRUE" : "FALSE") << endl; // FALSE tc3.setPurchases(1000); tc3.setYearsSinceFirstPurchase(6); cout << (tc3.isLoyal() ? "TRUE" : "FALSE") << endl; // TRUE tc3.setPurchases(1000); tc3.setYearsSinceFirstPurchase(6); cout << (tc3.isLoyal() ? "TRUE" : "FALSE") << endl; // TRUE tc3.setPurchases(999); tc3.setYearsSinceFirstPurchase(6); cout << (tc3.isLoyal() ? "TRUE" : "FALSE") << endl; // FALSE

// EXERCISE #4 Customer tc4(1, "Juan", "del Pueblo", 50000, 10, 20); Customer tc5(1, "Maria", "del Pueblo", 60000, 15, 15); cout << (tc4.nextForCoupon(tc5) ? "TRUE" : "FALSE") << endl; // FALSE cout << (tc5.nextForCoupon(tc4) ? "TRUE" : "FALSE") << endl; // TRUE

// EXERCISE #5 Customer tc6(1, "Juan", "Rivera", 50000, 10, 20); Customer tc7(1, "Maria", "Velez", 60000, 15, 15); Customer tc8(1, "Maria", "Velazquez", 60000, 15, 15);

cout << ((tc6.compareLastNames(tc7) < 0) ? "Passed" : "Failed") << endl; cout << ((tc7.compareLastNames(tc6) > 0) ? "Passed" : "Failed") << endl; cout << ((tc7.compareLastNames(tc8) > 0) ? "Passed" : "Failed") << endl; cout << ((tc8.compareLastNames(tc7) < 0) ? "Passed" : "Failed") << endl; cout << ((tc7.compareLastNames(tc7) == 0) ? "Passed" : "Failed") << endl;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

Bachelors degree in Information Systems or Statistics

Answered: 1 week ago