#include "stdstuff.h" #include "Customer.h" // Your method implementations go here. // the constructor creates a customer with id 10, total 0, date 1 1 2011 and name "default" Customer::Customer() { id = 10; total = 0; purchDate = Date(1,1,2011); custName = "default"; } // constructor creates a customer with the fields provided; sets the customer to the // default and quits if any field is not within the valid range Customer::Customer(int id, double total, const Date &purchase, const String2002 &name) { // check that fields are in valid range if ( id<1 || id>1000 || total<0 || purchase.compareTo(Date(1,1,2000))<0 || purchase.compareTo(Date(31,12,2015))>0 || name.length()<1 || name.length()>20 ) { // set to default *this=Customer(); // and quit quit("Customer::Customer -- invalid customer.\n"); } // otherwise use given fields this->id = id; // this-> indicates the field Customer::total = total; // Customer:: indicates the field purchDate = purchase; custName = name; } // returns the customer id int Customer::getID() const { return id; } // returns the customer total double Customer::getTotal() const { return total; } // returns the customer purchase date Date Customer::getDate() const { return purchDate; } // returns the customer name String2002 Customer::getName() const { return custName; } // sets the customer id to the value given; quits if value not between 1 and 1000 void Customer::setID(int nId) { if (nId<1 || nId>1000) quit("Customer::setID -- new ID not in range 1-1000\n"); id = nId; } // sets the customer total to the value given; quits if value < 0 void Customer::setTotal(double nTotal) { if (nTotal<0) quit("Customer::setTotal -- new total less than 0\n"); total = nTotal; } // sets the customer purchase date to the value given; quits if not between 2000 and 2015 void Customer::setDate(const Date &nDate) { if (nDate.compareTo(Date(1,1,2010))<0 || nDate.compareTo(Date(31,12,2015))>0) quit("Customer::setDate -- new date not between 2000 and 2015\n"); purchDate = nDate; } // sets the customer name to the value given; quits if not in range 1 to 20 characters void Customer::setName(const String2002 &nName) { if (nName.length()<1 || nName.length()>20) quit("Customer::setName -- new name not between 1 and 20 char\n"); custName = nName; } // returns true if two customers are equal (i.e. their ids are equal), false otherwise bool Customer::operator==(const Customer &otherCust) const { return id==otherCust.id; } // returns true if this customer is less than otherCust (i.e. this customer id is less than // otherCust's id), false otherwise bool Customer::operator<(const Customer &otherCust) const { return id