Question #6(a-c) /Answer
#include <condefs.h>
#pragma hdrstop
#include "..\Block I\Mt262io.h"
#include <fstream.h>
USELIB("..\Block I\Mt262io.lib");
#pragma argsused
/* Revision 6a */
class VendType
{
private:
int Quantity[10];
float Price[10];
float Change;
bool ChangeAvailable;
public:
void Initialise(int NewQuantity[10], float NewPrice[10], float NewChange);
float Supply(int ItemNumber, float MoneyOffered);
void RefillItem(int ItemNumber, int ItemQuantity);
void RefilChange(float MoreChange);
};
int main(int argc, char **argv)
{ VendType V;
int NQ[10];
float NP[10];
float NC;
V.Initialise(NQ,NP,NC);
V.Supply(10, 14.50);
getchar();
return 0;
}
void VendType :: Initialise(int NewQuantity[10], float NewPrice[10], float NewChange)
{ int Index;
Change=NewChange;
for (Index=1; Index <= 10; Index=Index+1)
{
Quantity[Index]=NewQuantity[Index];
Price[Index]=NewPrice[Index];
}
ChangeAvailable=(Change>0);
};
float VendType :: Supply(int ItemNumber, float MoneyOffered)
{
if (MoneyOffered > Price[ItemNumber])
{
if (Quantity[ItemNumber] > 0)
{
Quantity[ItemNumber]=Quantity[ItemNumber]-1;
}
else
{
return MoneyOffered;
}
}
else
{
return MoneyOffered;
}
if (Change > Price[ItemNumber])
return (Change - Price[ItemNumber]);
else
return 0;
};
void VendType :: RefillItem(int ItemNumber, int ItemQuantity)
{};
void VendType :: RefilChange(float MoreChange)
{};
#include <condefs.h>
#pragma hdrstop
#include "..\Block I\Mt262io.h"
#include <fstream.h>
USELIB("..\Block I\Mt262io.lib");
#pragma argsused
/* Revision 6b */
class CopierType
{
private:
float Ratio;
int NumCopies;
int PaperCopies;
public:
void Initialise(int PaperLoaded);
void SetRatio(float NewRatio);
void SetCopies(int CopiesWanted);
bool CanCopy(void);
void Copy(void);
};
int main(int argc, char **argv)
{ CopierType C;
C.Initialise(1000);
getchar();
return 0;
}
void CopierType :: Initialise(int PaperLoaded)
{
Ratio=1.0;
NumCopies=1;
PaperCopies=PaperLoaded;
};
void CopierType :: SetRatio(float NewRatio)
{
if (NewRatio < 0.71)
Ratio=0.71;
else if (NewRatio > 1.41)
Ratio=1.41;
else
Ratio=NewRatio;
};
void CopierType :: SetCopies(int CopiesWanted)
{
if (CopiesWanted < 1)
NumCopies=1;
else if (CopiesWanted > 4000)
NumCopies=4000;
else
NumCopies=CopiesWanted;
};
bool CopierType :: CanCopy(void)
{
return (NumCopies >= PaperCopies);
};
void CopierType :: Copy(void)
{
PaperCopies=PaperCopies-NumCopies;
};
#include <condefs.h>
#pragma hdrstop
#include "..\Block I\Mt262io.h"
#include <fstream.h>
USELIB("..\Block I\Mt262io.lib");
#pragma argsused
/* Revision 6c */
class SeatDataType
{
private:
int CurrentWriter;
int IsLocked;
public:
void Initialise(void);
bool GetWriteAccess(int AgentId);
bool FreeWriteAccess(int AgentId);
bool CanCloseDown(void);
};
int main(int argc, char **argv)
{ SeatDataType S;
S.Initialise();
getchar();
return 0;
}
void SeatDataType :: Initialise()
{
CurrentWriter=0;
IsLocked=false;
};
bool SeatDataType :: GetWriteAccess(int AgentId)
{
if ((AgentId > 0)&&(IsLocked == false))
{
IsLocked=true;
CurrentWriter=AgentId;
return true;
}
else
{
return false;
}
};
bool SeatDataType :: FreeWriteAccess(int AgentId)
{
return (AgentId == CurrentWriter);
};
bool SeatDataType :: CanCloseDown(void)
{
return IsLocked;
};
|