Dispenser-1

Classes:

Machine

Counter

Dispenser

UI -presents the user with an interface(menu)

-Accept legal comands

-Rejects illegal commands

-Holds a value that is pass to .....

Attributes

Methods

Dispenser

-cans in stock

-price

-name of product

 

-sell – release can

Machine

-1 dispenser for each kind of drink

-1 counter

-DoAction (ui)

 

Counter

-available change

-amount tendered

-add money

-give change

-return money

-make sale

 

 

Attributes

Class Counter

{

private: int

m_ nAmountTendered;

int n_nChangeAvailable;

int GiveChange(int nPrice);

public:

Counter(int nChange=1000);

int AddMoney(in nAMount);

bool MakeSale(int nPrice);

int ReturnMoney();

int GetAmount() Const; //Accessor function,

//const: execution of this method is not going to change the state or value of the object or naything in the object

};

Counter::Counter(int n Change)

{

m_nAmountTendered = 0;

m_nChangeAvailable = nChange;

}

int Counter::AddMoney(int nAmount)

{

m_nAmountTendered += nAmount

return m_nAmountTendered;

}

int Counter::GiveChange(int nPrice)

{

int nChange = M_nAmountTendered – nPrice;

if (nChange > m_nChangeAvailable)

{

nChange = m_nChangeAvailable;

m_nChangeAvailable = 0;

return nChange;

}

m_nChangeAvailable -= nChange;

return nChange;

}

bool Counter::MakeSale(int nPrice)

{

if (m_nAmountTendered < nPrice)

{

cout << "Not enough cash";

cout << endl;

return false;

}

int nchange = GiveChange(nPrice);

cout << "Sale Complete"

cout << endl;

if (nChange > 0)

{

cout << "Returned: " << nChange;

cout << endl;

}

m_nAmountTendered = 0;

return true;

}

int Counter::Return Money()

{

int ntemp = m_nAmount Tendered;

m_nAmountTendered = 0;

return nTemp;

}

 

int Counter::GetAmount() const

{

return m_nAmountTendered;

}

 

Class Dispenser

{

int m_nCans;

int m_nPrice;

char M-szName[NAME_SIZE +1];

Public:

Dispenser()

Void SetValues(char* szName, int nPrice, int nCans = 25);

int GetCanCount() conts;

int GetPrice() const;

char* GetName() const; //accessor function

bool ReleaseCan();

};

Dispenser::Dispenser()

//don’t need now with

//Machine::Machine(): Initalization List Constructor

{

m_nCans=0;

m_nPrice=0;

m_szName[0] = ‘\0’;

}

//S/B w/ Initializtiion List

Dispenser::Despenser(char* szName, int nPrice, int nCans)

}

void Dispenser::SetValues(char* szName, int nPrice, int nCans)

{

strncpy(m_szname, szname,NAMESIZE);

m_szname[NAME_SIZE] = ‘\0’;

//m_szname @ NAME_SIZE

m_nCans = nCans;

m-nPrice = nPrice;

}

int Dispenser::GetCanCount() const

{

return m_nCans;

}

int Dispenser::Get Price() const

{

return m_nPrice;

}

Char* Dispenser::GetName() const

{

returnm_szName;

}

bool Dispenser::ReleaseCan()

{

if(GetCanCount() > 0)

{

m-nCans--;

return true;

}

return false;

}

Class Machine

{

Dispenser m_Jolt;

Dispenser m_Diet;

Dispenser m_OJ;

Dispenser m_Sprite;

Dispenser m_Prune;

Counter m_CC:

Public:

Machine(); //constructor

void DoAction(int nCommand);

};

 

 

 

 

Dispenser-2

Class Counter

{

public:

int GetAmount();

int AddMoney(int nAmount);

int DispenseChange(int nAMount);

int ReturnMoney();

};

Class Dispenser{

bool Release can();

int GetCanCount();const;

int GetPrice()const;

char* GetName() const;

{;

Class Machine

{

void DoAction(int nCommand);

};

Class UI

{

private:

int m_nCommand;

void ShowMenu();

public:

UI():

int GetValueFromUser();

int GetCommand() const;

bool IsExit();

}

void UI::Show Menu()

{

system ("cls");

cout << "Please select one of the following options: \n"

cout << "\n\t L: Loonie\n";

cout << "\n\t Q: Quarter \n";

.

.

.

.

.

cout <<"\n\t J: Jolt Cola \n";

cout << "\n\t O: Orange Juice\n";

cout <<"\n\t M: Redraw Menu\n";

cout << "\n\t x: Exit Program\n<<endl;

}

 

 

#define LEGAL_COMMANDS "LQDNRJOCPSMXlqdnrjocpsmx"

int UI::Get Value From User()

{

char szCmd[1+1];

while(true)

{

cout << "Enter a command>";

if (GetChars(szCmd,1,LEGAL_COMMANDS) ==0)

{

Show Menu():

}

else

{

szCmd[0] = toupper(szCmd[0]);

m_nCommand = szCmd[0];

//m_nCommand=touper(szCmd[0]); //replaces above 2 lines

return m_nCommand;

}

}

}

 

 

int UI::GetCommand()const

{

return m_nCommand;

}

 

bool UI::IsExit()

{

return m_nCommand == (int) ‘X’;

}

UI::UI()

{

m_nCommand = 0;

Show Menu();

}

#include "UI.h"

#include "Machine,h"

int main ()

{

UI ui;

Machine S;

ui.GetValueFromUser();

while (ui.IsExit() == false)

{

s.DoAction(ui.GetCommand());

ui.GetValueFromUser();

}

return 0;

}

void Machine ::DoAction(int nCmd)

{

Switch(n(nrd)

{

Case ‘L’:

m.cc.AddMoney(100);

return;

case’Q’:

m_CC.AddMoney(25);

return;

case ‘R’:

m_CC.TrturnMoney();

return;

.

.

.

.

.

.

.

.

.

case ‘J’:

if (m_CC.GetAmount(0 .= M-Jolt.GetPrice())

{

if (m_Jolt.ReleaseCan() == true)

{

int nRet = m_CC.MakeSale(m_Jolt.GetPrice());

cout << "One Can of" <<

m_Jolt.GetName() <<

"Sold " << mRet <<

"cents returned" << endl;

}

else

{

cout << "Sold Out!" <<endl;

}

}

 

 

 

Back | HOME | Next




Canpol Solutions Przeszukaj Katalog -- przeszukaj katalog / zamowienia, komentarze --  Poczta Polonijnej Witryny

Internet ExplorerUzywaj zawsze najnowszej przegladarki
M.I.E. lub, ewentualnie Netscape ktorej, niestety na razie nie polecamy..
Netscape


Canpol Solutions © Polonijna Witryna