Hej,
przerabiał ktoś może książkę Stephena Pratta "Język C++ Szkoła Programowania"? Jest tam jedno zadanie, rozdział 12, ćwiczenia programistyczne, zadanie 5. Nie rozumiem jego treści, czyli co mam zrobić.
"Bank Stu Kas przeprowadził analizę, z której wynika, że klienci bankomatu nie lubią czekać w kolejce dłużej niż minutę. Korzystając z programu symulującego z listingu 12.10, znajdź taką wartość średniej liczby klientów na godzinę, dla której średni czas oczekiwania w kolejce wyniesie minutę (w próbach co najmniej 100-godzinnych).
Klasy:
class Customer
{
private:
long arrive;
int processtime;
public:
Customer() {arrive = processtime = 0;}
void set(long when);
long when() const {return arrive;}
int ptime() const {return processtime;}
};
typedef Customer Item;
class Queue
{
private:
struct Node {Item item; struct Node * next;};
enum {Q_SIZE = 10};
Node * front;
Node * rear;
int items;
const int qsize;
Queue(const Queue & q) : qsize(0) { }
Queue & operator=(const Queue & q) {return *this;}
public:
Queue(int qs = Q_SIZE);
~Queue();
bool isempty() const;
bool isfull() const;
int queuecount() const;
bool enqueue(const Item &item);
bool dequeue(Item &item);
};
Plik cpp
Queue::Queue(int qs) : qsize(qs)
{
front = rear = NULL;
items = 0;
}
Queue::~Queue()
{
Node * temp;
while (front != NULL)
{
temp = front;
front = front->next;
delete temp;
}
}
bool Queue::isempty() const
{
return items == 0;
}
bool Queue::isfull() const
{
return items == qsize;
}
int Queue::queuecount() const
{
return items == qsize;
}
bool Queue::enqueue(const Item &item)
{
if(isfull())
return false;
Node * add = new Node;
add->item = item;
add->next = NULL;
items++;
if(front == NULL)
front = add;
else
rear->next = add;
rear = add;
return true;
}
bool Queue::dequeue(Item &item)
{
if(front == NULL)
return false;
item = front->item;
items--;
Node * temp = front;
front = front->next;
delete temp;
if(items == 0)
rear = NULL;
return true;
}
//metody klasy customer
void Customer::set(long when)
{
processtime = std::rand() % 3 + 1;
arrive = when;
}
W skrócie program działa w taki sposób (przykład):
Podaj maksymalną długość kolejki: 10
Podaj symulowany czas (w godzinach): 100
Podaj średnią liczbę klientów na godzinę: 15
liczba klientów przyjętych: 1485
liczba klientów obsłużonych: 1485
liczba klientów odesłanych: 0
średnia długość kolejki: 0.15
średni czas oczekiwania: 0.63 minut
Nie rozumiem treści tego zadania. Rozdział omawia dynamiczną alokację pamięci wewnątrz klas, więc powinno się coś w tym kierunku zrobić, ale nie mam pojęcia co.