LATEST UPDATE

CIMA study stuff added

BOX

Saturday, September 4, 2010

SIMULATION LAB 5

/*
#include

using namespace std;

int main(void)
{
cin.get();//pause
return 0;

}//end main

*/

TASK 2 add RNG.h
#include
#include
#include


//wrapper class to the built in C rand() function
class RNG
{

public:
RNG();
~RNG();

// the point of using const on a parameter to a function should be to let your compiler know
// that the parameter shouldnot be modified during your program
// this alllow your to keep your code safe and bug-free


int generate(const int &lower, const int & upper );
double generate(const double & lower,const double &upper);

protected:
time_t seconds; //seed value
};



RNG::RNG()
{ // the constructor seeeds the RNG number generator that is in

time(&seconds); //get value from system clock and place in seconds variable
srand((unsigned int) seconds);
}
RNG::~RNG()
{

}
int RNG::generate(const int &lower, const int &upper)
{
return((rand()%(upper-lower))+lower); // Genereate a number between 'lower' and 'upper'

}
double RNG::generate(const double &lower, const double&upper)
{
return ((double) rand()/((RAND_MAX)+1.0)) * (upper-lower)+lower;

}


//TASK 3 RNG in main

#include
#include "RNG.h"
using namespace std;

int main(void)
{
RNG r ;
for(int i=0; i<10;i++)//test simple int random
cout << r.generate(0,12)<for(int i=0; i<10; i++) //test simple float random
cout <
cin.get(); //pause
return 0;
}
//end main

No comments:

Post a Comment

UBIT

SMS AT ANY NETWORK

STAND UP 4 THE CHAMPION

Search This Blog