I am new to programming, and I am having trouble understanding the srand(time(0). I am using it to create a program that will generate random times of the day.
I have defined my class time as follows:
// class Time definittion
Time( int =0, int =0, int=0 );
void setime( int, int, int ) const;
void setHour( int ) const;
int getHour() const;
void setMinute( int ) const;
int getMinute() const;
void setSecond( int ) const;
int getSecond() const;
void printUniversal() const;
}; // end class Time
I am trying to use class to create a derived RandTime.h class to generate a random time of day.
I have already created a abstract base class that will be used to generate random numbers or strings in various questions.
1) I am unsure of my headers to use in the RandTime class
2) I am unsure how to properly use Srand
I have started with my header files:
// Derived class that generates a random time
// of day using the Time class
using namespace std;
srand time (0);
cout << time;
srand() is a function, and not a type. You would call srand like this:
Try not to call srand more then once.