Professional Documents
Culture Documents
#define PHONENUMBER_H
#include <iostream>
#include <string>
using namespace std;
class PhoneNumber {
public:
void input(istream &s);
// inputs in form
// (aaa) lllnnnn
void output(ostream &s) const;
// outputs in form input
bool operator < (const PhoneNumber & v) const;
bool operator <= (const PhoneNumber & v) const;
bool operator >= (const PhoneNumber & v) const;
bool operator > (const PhoneNumber & v) const;
// relational based on all parts, area first, then
// local
bool operator == (const PhoneNumber & v) const;
bool operator != (const PhoneNumber & v) const;
// equality based on all parts
bool sameExchange(const PhoneNumber & v) const;
// returns true if two numbers are in the same area
// and the same local exchange
bool sameArea(const PhoneNumber & v) const;
// returns true if two numbers are in the same area
private:
string area; // aaa
string exchange; // lll
string number; // nnnn
};
istream & operator >> (istream &s, PhoneNumber &v);
// inputs using keyword operation
ostream & operator << (ostream &s, const PhoneNumber &v);
// outputs using keyword operation
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef CALL_H
#
#define CALL_H
/* this class defines objects representing individual calls. The
* call contains the calling number, the number called, the date
* and time of the call, and the duration of the call.
*
*/
#include <iostream>
#include <string>
u
using namespace std;
#
#include "PhoneNumber.h"
c
class Call {
public:
void input(istream &s);
// inputs in form
// caller called date time duration
// where caller and called are phone numbers, date
// and time are strings and duration is an integer
// number of minutes
const PhoneNumber & getCaller() const;
// returns caller's phone number
int getDuration() const;
// returns duration of call;
void output(ostream &s) const;
// outputs in form input
bool isLocal() const;
bool isArea() const;
bool isNonArea() const;
// determines kind of call:w
private:
PhoneNumber callingNumber;
PhoneNumber calledNumber;
string date;
string time;
int duration;
}
};
istream & operator >>(istream &s, Call & v);
// inputs using keyword operation
ostream & operator <<(ostream &s, const Call & v);
// outputs using keyword operation
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef CALLLIST_H
#
#define CALLLIST_H
/* this class defines an input order list of calls. The calls
* may be inserted and the list printed.
*
*/
#include <iostream>
u
using namespace std;
#
#include "Call.h"
c
class CallList {
public:
CallList();
// constructs empty list
CallList(const CallList & v);
// copy
~CallList();
// destructor
CallList & operator = (const CallList & v);
// assignment
void insert(const Call & call);
// adds call to tail of list
void output(ostream &s) const;
// outputs calls, one per line
private:
struct Elem {
Call info;
Elem * next;
};
Elem * head;
Elem * tail;
// note: list contains head sentinel so is never truely
// empty and thus insert doesn't have a special case (nor
// does copy or assignment).
}
};
ostream & operator << (ostream & s, const CallList & v);
// outputs using keyword operation
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef ACCOUNT_H
#
#define ACCOUNT_H
/* this class provides phone number accounts. Each account has a
* phone number (which is its identifying feature), an account
* address and a previous balance. In addition, it contains a
* list of all the calls made to the account, separated into
* local, area, and out of area calls.
*
*/
#include <iostream>
#include <string>
u
using namespace std;
#include "PhoneNumber.h"
#include "Call.h"
#
#include "CallList.h"
c
class Account {
public:
Account();
// constructs empty account to be filled by input
Account(const PhoneNumber & number);
// constructs dummy account with identifying number
// specified
void input(istream & s);
// inputs in form
// phoneNumber |address| prevBal
// where address may contain spaces and previous
// balance is an integer number of cents.
void addCall(const Call & call);
// adds call to the account
void printBill(ostream &s) const;
// outputs in form
// phoneNumber address
// previousBalance
// localMinutes
// localCharge
// areaMinutes
// areaCharge
// outAreaMinutes
// outAreaCharge
// total
// localCallList
// areaCallList
// outAreaCallList
bool operator >= (const Account & v) const;
bool operator > (const Account & v) const;
bool operator < (const Account & v) const;
bool operator <= (const Account & v) const;
// relational operators based on phone number
bool operator == (const Account & v) const;
bool operator != (const Account & v) const;
// equality operators based on phone number
private:
PhoneNumber phoneNumber;
string address;
int prevBalance;
int localMinutes;
CallList localCalls;
int areaMinutes;
CallList areaCalls;
int nonAreaMinutes;
CallList nonAreaCalls;
}
};
istream & operator >> (istream &s, Account &v);
// inputs using keyword operation
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef ACCOUNTDB_H
#
#define ACCOUNTDB_H
/* this class provides storage for any number of accounts. The
* accounts may be accessed in either original insertion order or
* by phone number (when calls are added).
*
*/
#include <iostream>
u
using namespace std;
#include "Account.h"
#
#include "Call.h"
c
class AccountDB {
public:
AccountDB();
// constructs empty database
~AccountDB();
// destructor
void insert(const Account & acct);
// inserts account into database. Insertion order is
// maintained. It is assumed that accounts will be
// unique.
void printBills(ostream &s) const;
// prints bill for each account. Bills output in
// original insertion order for database
void addCall(const Call & call);
// adds a call into the database, adding it to
// the matching account. It is assumed that all
// calls belong to accounts in the database (if they
// are not, they will be silently ignored).
private:
AccountDB(const AccountDB &);
AccountDB & operator = (const AccountDB &);
// copy, assignment not implemented
struct Node {
Account info;
Node * next;
Node * left;
Node * right;
};
Node * head;
Node * tail;
Node * root;
static void insert(Node * &r, Node * p);
// inserts node pointed to by p into subtree rooted
// at r can be used if recursive insertion
}
};
#endif