1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
TASK #1 – Define the Class
Write a class called ServerGroup, which will be a simple custom-made data structure. It will be special-purpose,
so it is NOT a template.
It is used to represent serving people waiting in a line.
The private section will have a pointer to a
dynamic integer array called servers,
an integer variable called spServer, and an integer variable called freeServer.
It will also be useful to have a variable representing the size of the array (number of elements).
The following member functions should be in the class:
•the constructor, which passes an integer into the function
that is used to set the number of elements in the array (representing the number of general-purpose servers).
It also sets the elements in the array to 0 and spServer to 0.
•A function called spServerFree, that will
return true if SpServer is 0 and false otherwise (this represents the number of clock ticks until the special-purpose server is free;
if the integer is 0, the server is already free).
•A function called serverFree, that returns true
if it finds a 0 in the array and a false otherwise (these integers also represent the number of clock ticks
until the corresponding servers are free).
If it finds a 0 in the array, it will set freeServer to the index of that element
(freeServer has the index of one of the servers that are free).
•A function called useServer that passes in an integer parameter,
avTransTime, and set servers[freeServer] to avTransTime (avTransTime is the average transaction time, in clock ticks, to server a person in the line).
A function called usespServer, that will pass in an integer parameter,
avTransTime, and set spServer to avTransTime (this is the same function as d) except that it is for the special-purpose servers where d) is for general purpose servers).
•A function called decServers, that will decrement spServer by 1, unless spServer is already 0.
If it is 0, it stays the same.
The decServers function will also decrement
each element in the array by 1, unless the element is already 0.
For example, if the array is 0 5 6 0 0 10,
then after decServers is called,
the array is 0 4 5 0 0 9 (this is called when a click tick of time elapses).
Place the class files in files with appropriate names (i.e., ServerGroup.h and ServerGroup.cpp)
TASK #2 – Test the Class
You are to implement a program that uses the ServerGroup class.
It should create a ServerGroup object, and then call all of the functions.
The best way to do it is to write a temporary print function in the class to print out the values of the array and the other private values.
When you know it works, just comment out this function (do not delete it!)
|