The following class is defined as part of a project to
simulated a vending machine. The machine dispenses
class VendType
{
private:
int Quantity[10]; // Amounts of te items currently in machine
float Price[10]; // Corresponding prices of items.
float Change; // Current amount of change available
bool ChangeAvailable; // True if machine can give change.
public:
void Initialise(int NewQuantity[10], float NewPrice[10], float NewChange);
// Initialises a VendType object with the values in the arrays and sets
// Change to NewChange. Sets changedAvailable to true if Change is
// positive.
float Supply(int ItemNumber, float MoneyOffered);
// If MoneyOffered is sufficient to buy the item numbered
// ItemNumber and there is one in stock, then reduces stock
// by 1. If the item cann ot be supplied for either reason, returns
// the value MoneyOffered. Otherwise, returns the necessary
// change (if available) or zero if no change.
// Updates other data as necesary.
void RefillItem(int ItemNumber, int ItemQuantity);
// Tops up the given item with the given quantity
void RefillChange(float MOreChange);
// Tops up change. Updates other data as necessary.
};
Write that part of the code file for this class which is necessary to implement
the Initialise and Supply methods. Question 6b The following class is defined as part of a project to simulated a photocopying
machine. The machine can
class CopierType
{
private:
float Ratio; // The current copying ratio. Must be between 0.71 and 1.41
int NumCopies; // Number of copies required of current sheet
int PaperCount; // Current number of sheets of paper available for making copies. Max is 4000.
public:
void Initialise(int PaperLoaded);
// Initialises a CopierType. Sets amount of aper to the value of
// the parameter PaperLoaded, sets Ratio to 1.0 and NumCopies to 1
void SetRatio(float NewRatio);
// Set copy ratio. If NewRatio is out of permitted range setts
// to max permitted or min permitted as appropriate.
void SetCopies(int CopiesWanted);
// Sets number of copies. If Copies wanted is out of permitted range, sets
// to max permitted or min permitted as appropriate.
bool CanCopy(void);
// Returns true if there is enough paper to fulfill copy job, false otherwise.
void Copy(void);
// Signals that the machine has done the copying. Updates PaperCount.
};
Write that C++ code file which implements the five methods for this class. [7]. Question 6c The following C++ code shows part of a class declaration for a theatre seat
booking database. The information
class SeatDatatType
{
private:
int CurrentWriter; // Id of agent currently writing information to database
int IsLocked; // Set true if an agent currently has write access to database
public:
void Iinitialise(void);
// Initialises a SeatDataType object. Sets CurrentWriter to zero, IsLocked to false
bool GetWriteAccess(int AgentId);
// If AgentId is positive and IsLocked is false, this sets IsLocked true
// CurrentWriter to AgentId and returns true, otherwise returns false
bool FreeWriteAccess(int AgentId);
// If AgentId matches CuurrentWriter, updates data and returns true,
// else returns false
bool CanCloseDown(void);
// Returns true if no agent currently has write access to the database,
// false otherwise
};
Write the C++ code file which implements the four methods for this class. [7] |