Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the definitions of the functions setWaitingTime, getArrivalTime, getTransa

ID: 3579065 • Letter: W

Question

Write the definitions of the functions setWaitingTime, getArrivalTime, getTransactionTime, and getCustomerNumber of the class customerType defined in the section Application of Queues: Simulation.

Write the definitions of the functions getRemainingTransactionTime, setCurrentCustomer, getCurrentCustomerNumber, getCurrentCustomerArrivalTime, getCurrentCustomerWaitingTime, and getCurrentCustomerTransactionTime of the class serverType defined in the section Application of Queues: Simulation.

Write the definition of the function runSimulation to complete the design of the computer simulation program (see the section Application of Queues: Simulation). Test run your program for a variety of data. Moreover, use a random number generator to decide whether a customer arrived at a given time unit.

Show how you would use this simulation code to advise the manager of the movie theater described on page 1233 in the text (Slide 91) as to how many cashiers he/she should hire.

The following output was generated using these simulation parameters:

Please do not use global variables and code in C++, thank you (:

Application of Queues: Simulation (cont'd) Computer simulations are useful for modeling complex systems Particularly when it is difficult to construct a mathematical model Example The manager of a local movie theater is hearing complaints from customers about the length of time they have to wait in line to buy tickets. The theater currently has only one cashier. Another theater is preparing to open in the neighborhood, and the manager is afraid of losing customers. The manager wants to hire enough cashiers so that a customer does not have to wait too long to buy a ticket but does not want to hire extra cashiers on a trial basis and potentially waste time and money. One thing that the manager would like to know is the average time a customer has to wait for service. The manager wants someone to write a program to simulate the behavior of the theater. C++ Programming: Program Design Including Data Structures, Seventh Edition 91

Explanation / Answer

#include
#include
using namespace std;

//definition of the template class stackType
template
class stackType
{
// data memebers of the class
private :
int maxStackSize;
int stackTop;
Type *list;

// data methods of the class
public :
void initializeStack();
bool isFullStack() const;
bool isEmptyStack() const;
void push( const Type& );
void pop();
Type top() const;
stackType( int = 20 );
~stackType();
bool operator==( const stackType& );
}; // end template class stackType

// initialize the stack
template
void stackType::initializeStack()
{
stackTop = 0;
} // end function initializeStack

// check for stack fullness
template
bool stackType::isFullStack() const
{
return ( stackTop == maxStackSize );
} // end function isFullStack

// check for stack empty
template
bool stackType::isEmptyStack() const
{
return ( stackTop == 0 );
} // end function isEmptyStack
// insert an element into stack

template
void stackType::push( const Type& newItem )
{
if ( !isFullStack() )
{
list[ stackTop ] = newItem;
stackTop++;
} // end if
else
cout << " Can not add to a full stack";
} // end function push

// delete an element from the stack
template
void stackType::pop()
{
if ( !isEmptyStack() )
stackTop--;
else
cout << " Can not remove from an empty stack";
} // end function pop

// return the value of stack-top
template
Type stackType::top() const
{
assert( stackTop != 0 );
return list[ stackTop - 1 ];
} // end function top

// constructor for the class stackType
template
stackType::stackType( int stackSize )
{
if ( stackSize <= 0 )
{
cout << "Invalid size";
stackSize = 10;
} // end if
else
maxStackSize = stackSize;

stackTop = 0;
list = new Type[ maxStackSize ];
} // end constructor stackType

// destructor for the class stackType
template
stackType::~stackType()
{
delete[] list;
} // end destructor stackType

// overload the equality operator
template
bool stackType::operator==
( const stackType& right )
{
// check for same number of elements
if ( this->stackTop != right.stackTop )
return false;
//check for equality of elements at corresponding positions
for ( int i = 0; i list[ i ] != right.list[ i ] )
return false;
return true;
}


//main function
int main()
{
// let the user know about the program
cout << " Program to overload the realtional " << "operator == for the class stackType.";

// create objects of type stackType
stackType s1( 12 );
stackType s2( 15 );

// insert elements into the stacks
cout << " Inserting elements 5, 10, 15 ... "
<< "to both the stacks.";
for ( int i = 5; i < 50; i+=5 )
{
s1.push( i );
s2.push( i );
} // end for
//check and print whether the stacks are equal or not
if ( s1 == s2 )
cout << " Both the stacks are equal";
else
cout << " Both the stacks are not equal";
// insert one more element into the second stack
cout<<" Inserting element 11 to the second stack.";
s2.push( 11 );
//check and print whether the stacks are equal or not
if ( s1 == s2 )
cout << " Both the stacks are equal";
else
cout << " Both the stacks are not equal";
cout << " ";
return 0;
}