Hi i have created a program that simulates an elevator. It works ok, but is there a way I can get a better random output than the
method I have used? Here is my program -- i would also appreciate any light critisism on my idea.
Code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
// class for elevator bell
class Bell
{
private:
int m_ring;
public:
Bell( int initring ) { m_ring = initring; }
~Bell() {};
void rang ( void ) { std::cout << "\n\nThe bell rang!"; }
void noRang ( void ) { std::cout << "\n\nAwaiting bell..."; }
int setRing( int RING ) { m_ring = RING; }
int getRing () const { return m_ring; }
};
// class for time of day
class Clock
{
private:
int m_time;
public:
Clock ( int inittime ) { m_time = inittime; }
~Clock() {};
void announce ( void ) { std::cout << "\n\nEstimating time.."; }
int setTime ( int TIME ) {
TIME = rand() & 0 + 59; m_time = TIME; }
int getTime() const { return m_time; }
};
// class for people
class Person
{
private:
int m_pgie; // people getting in elevator
int m_pgoe; // people getting off elevator
int m_psie; // people staying in elevator
public:
Person ( int initpgie, int initpgoe, int initpsie ) { m_pgie =initpgie; m_pgoe = initpgoe; m_psie = initpsie; }
~Person() {};
void peopleIn ( void ) { std::cout << "\n\nPeople enter elevator"; }
void peopleStay ( void ) { std::cout << "\n\nPeople staying in elevator"; }void peopleOut ( void ) { std::cout << "\n\nPeople leave elevator"; }
int getPgie() const { return m_pgie; }
int getPgoe() const { return m_pgoe; }
int getPsie() const { return m_psie; }
int setPgie ( int PGIE ) {
PGIE = rand() & 0 + 25; m_pgie = PGIE; }
int setPgoe ( int PGOE ) {
PGOE = rand() * 0 + 25; m_pgoe = PGOE; }
int setPsie ( int PSIE ) {
PSIE = rand() & 0 + 25; m_psie = PSIE; }
};
// driver - main function //////////////////////////////////////////////////////
//
int main ( void )
{
// randomise results
srand(time(0));
std::cout << "\tELEVATOR PROGRAM\n\n";
// create objects and assign all default values to zero
Bell bl(0);
Clock cl(0);
Person pp(0,0,0);
cl.announce();
cl.setTime(0);
std::cout << "The time minutes past the hour is: " << cl.getTime();
bl.noRang();
std::cout << "\n\nbell has a null value of " << bl.getRing();
bl.setRing(1);
bl.rang();
std::cout << "\n\nThe bell rang, so has a true value of " << bl.getRing();
pp.peopleIn();
pp.setPgie(0);
std::cout << "\n\nAmount of people entered was: " << pp.getPgie() << "\n\n";
std::cout << "\n\n*****ELEVATOR IN MOTION******\n\n";
pp.peopleStay();
pp.setPsie(0);
std::cout << "\n\nAmount of people who stayed was: " << pp.getPsie() << "\n\n";
pp.peopleOut();
pp.setPgoe(0);
std::cout << "\n\nAmount of people who left was: " << pp.getPgoe() << std::endl;
std::cin.get();
return 0;
}
PS: I appoligise for the way it has appeared on the cboard as in my editor, MSVC++2003 it looks much better than this!