// Class Declarations for ListOfContracts with the ability to add as many contracts
// as desired
// Also set up to allow a user program to iterate through the list
// File: ch10lst5.h
#include "common2.h"
#include "contrct4.h" // Uses the modified version of the contract class.
const CONTRACT_GROWTH = 3; // Size to start list and to grow by when necessary
// Use small number for testing purposes
class ListOfContracts
{
public:
ListOfContracts();
/*
Purpose: to instantiate (create) an instance of the class 'ListOfContracts'.
Goal: a new instance of class 'ListOfContracts' now exists
Receives: NONE
RETURNS: NONE
*/
~ListOfContracts(); // the destructor
void Add(Contract contract);
/*
Purpose: To add an instance of the class 'Contract' to the list.
Goal: A new instance of class 'contract' is on the list
Receives: a contract
Returns: NONE:
*/
/* This function is complex enough to deserve an algorithm
Search to find if 'contract' already exists
If need add contract (it is not in list)
Check to see if there is room on the list
if no room,
create more room
add contract
increment numContract
else
state that it already exists
*/
void Delete(int contractNum);
/*
Purpose: To delete an instance of the class 'Contract' from the list.
Goal: The instance of class 'contract' is deleted
Receives: a contract number
Returns: NONE:
*/
bool FindContract(int ID, Contract& contract);
/*
Purpose: To find out if a contract is in the list
Goal: If the list holds a contract with id 'ID', the function
returns that contract in the variable 'contract' and
the function returns true
Or the function returns false and 'contract' holds garbage.'
Receives: A contract ID
Returns: Whether or not the contract was found AND if found, the contract
itself.
*/
void ReplaceContract (Contract contract);
/*
Purpose: To replace the properties of one contract in the list
Goal: The properties of the contract in the list with the ID of
'contract' have been replaced
Receives: A contract
Returns: NONE
*/
void Reset();
/*
To reset the iteration marker to start at the beginning of the list
*/
Contract GetNext();
/* To get the next contract when iterating through contracts
*/
bool AreThereMore();
/* To test for more contracts to iterate through
*/
private:
int numContracts; // indicates next available slot in list
int presentMax; // present size of array
int next; // Used to iterate through the list
// Holds the 'next' unaccessed contract in a set of requests
Contract* listOfContracts;
int Search(int contractID);
void IncreaseSize();
/* Another function worth an algorithm
Increment presentMax by CONTRACT_GROWTH
Get enough memory for array of new 'presentMax' size and have 'tempArray'
point to it
Copy old list contents (listOfContracts) into new list area pointed to by
tempArray
Delete memory pointed to by listOfContracts
Assign pointer value in 'tempArray' to listOfContracts
*/
};