returnType className::functionName (formal parameter list)
#include <iostream> using namespace std;
cout << "Average delay: " << delay << endl;The endl represents the new line (the escape sequence \n may also be used).
cin >> iat;The data read in becomes the value of the variable iat.
simNode myNode;would declare myNode to be a reference (currently null) to a simNode object. The actual object would be created using the new operator. In C++, the above declaration would create the actual simNode (no new would be needed). In either case to access the data in the node or to invoke a function (method) to operate on the node you would use the dot operator -- for example, myNode.time or myNode.getTime().
In C++ when you declare an object as above, the default constructor (with no parameters) is invoked to create the object. If you want to use a different constructor, one with parameters, to construct the object you use the parameters in the declaration. For example, in the simNode class has several different constructors. The following declaration creates a simNode object named arrival using the constructor with two parameters (the first parameter is the time for the event and the second is the type - 0 means arrival).
simNode arrival (45.3, 0);
Often in C++ we want to declare a reference (pointer) to an object. The following declaration declares myNode as a pointer to a simNode:
simNode * myNode;The actual node would be constructed using the new operator - for example,
myNode = new simNode(23.3);creates a new simNode with time of 23.3.
In this case to access data in the node or invoke a function you use the -> operator as in myNode->time or myNode->getTime(). (An alternate, which is not used in the example program, is to use *myNode.time or *myNode.getTime() -- *myNode is the actual object pointed to by myNode.)
returnType functionName (simNode * theNode); or returnType functionName (simNode *);Note: It is standard practice to just list the type of each parameter in the declaration; it isn't necessary at that point to have a formal parameter name.
The call of the function would need to send a pointer to a simNode as the actual parameter. Two examples are:
simNode * nodePtr; simNode actualNode; ... ... functionName(nodePtr) .... ... ... functionName(&actualNode)The & operator gives the address of an object so &actualNode is a pointer to (or reference for) the object actualNode.
Java: public mm1System extends System C++: public mm1System: public SystemIn C++ the base class often has virtual functions that are not defined in the base class. Each derived class must define the functions. See the functions updateState and continueSim in the System declaration.
g++ -c myClass.cccompiles the class defined in the file myClass.cc and puts the object code in myClass.o. After compiling all your files you can then link of the object files together and create an executable file as follows:
g++ -o executableName mainProg.o myClass.oTo run the program type
./executableNameWhen a program uses lots of files it is easier to "automate" this process using a makefile. Each line of the makefile contains the commands one needs and information about which files each command depends on (so that if you want to compile the main program all other files that it depends on are checked to see if they need to be recompiled). Each line of the makefile has the following syntax:
target: a list of dependencies the command(TABs must be used to space over to the command). The target is generally the file created by the command. Then to execute the command all you need to do is type
make targetStudy the makefile for the mm1 queuing system. Note that there is a line for compiling each file in the program plus one that links all together.