CustomerDB - #include "stdstuff.h" # #include...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include "stdstuff.h" #include "CustomerDB.h" # // the constructor creates an empty database CustomerDB::CustomerDB() { numCusts=0; // no customer yet (so nothing goes in the ci array) } // returns the number of customers in the database int CustomerDB::getNumCusts() const { return numCusts; } // add a new customer to the database; returns true if successful, false otherwise // (database full or customer already exists) bool CustomerDB::add(int id, double total, const Date &purchase, const String2002 if(numCusts==MAXCUST) return false; // database is full for(int i=0;i<numCusts;i++) { if(ci[i].id==id) return false; // Customer already in database } // insert Customer at end ci[numCusts].id = id; ci[numCusts].total = total; ci[numCusts].purchDate = purchase; ci[numCusts].custName = name; numCusts++; // we've added a Customer return true; // success } // remove a customer from the database; returns true if successful, false otherwise (customer // does not exist) bool CustomerDB::remove(int id) { for(int i=0;i<numCusts;i++) { if(ci[i].id==id) { // found it numCusts--; ci[i] = ci[numCusts]; // decrement number of customers and move last one into ith pos'n return true; // Customer removed } } return false; // Customer does not exist in database } // prints the full customer database (or a note if the database is empty);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/13/2011 for the course SYSC 2002 taught by Professor Unknown during the Spring '07 term at Carleton.

Page1 / 4

CustomerDB - #include &quot;stdstuff.h&quot; # #include...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online