Counter

 

 

//counter.cpp "how"file

 

bool counter::Increment()

{

m-nValue++;

if(n_nValue=n_nLimit)

{

m_nValue =0;

return true;

}

return false;

}

 

void Coutner::Display()

{

cout << n_nValue;

}

Counter::Counter()

{

m_nLimit=0;

m_nValue=0;

}

//Counter.h "what"file

Class Counter

{

private: //access specifiers…default private

int m_nValue;

int n_nLimit;

public:

Counter();

void Display();

void Increment();

bool Increment();

void SetValueAndLImit(int nVal, int nLim);

};

 

Void Counter::SetValueAnd Limit(int nVal, int nLim)

{

m_nValue=nVal;

m_nLimit=nLim;

}

 

 

 

 

CLOCK PROGRAM

//Clock.h

Class Clock

{

Counter n_Min;

Counter n_Sec;

Counter n_Milli;

Void Display();

Clock();

Void Increment();

};

//Access Specifiers

//Clock.cpp

Clock::Clock()

{

m_Min. SetValueAndLimit(0,60);

m_Sec. SetValueAndLimit(0, 60);

m_milli. SetValueAndLimit(0,1000);

}

void Clock::Display()

{

m_min. Display();

cout<< ‘:’ ;

n_Sec. Display();

cout<< ‘.’;

m_milli.Display();

cout<< endl;

}

void Clock::Increment()

{

if(m_milli.Increment()==true)

{

if(n_Sec.Increment()==true)

{

m_Milli.Increment();

}

}

}

//main.cpp

int main()

{

Clock c;

c.Display();

for(int I=0; I<1000000;I++)

//for( ; ; ) to loop forever

{

c.Increment();

c.Display();

}

return 0;

}

 

 

 

 

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