Hi all,
This is my first experience with c++ programming. I am struggling with our first assignment to create a program that generates 10 random numbers. We are supposed to separate the implementation and the interface, so I have a header file (rng.h) and 2 cpp files (rng.cpp, main. cpp). Can someone please help me out?? I'm not even sure if I'm on the right track and I'm getting 5 errors when I compile.
Any help is GREATLY appreciated.
Thanks in advance.
rng.h
rng.cppCode:#ifndef RNG_H #define RHG_H //aRandomNumberGenerator class definition class aRandomNumberGenerator { public: //Constructor initializes aRandomNumberGenerator aRandomNumberGenerator(); void setSeed(unsigned long); double generate(); private: unsigned long seed; }; //end of class aRandomNumberGenerator #endif
main.cCode:#include <iostream> #include <cstdlib> #include "rng.h" using namespace std; void aRandomNumberGenerator::setSeed(unsigned long) { seed = 2345; srand(seed); } double aRandomNumberGenerator::generate() { return rand(); }
Code:#include <iostream> #include <cstdlib> #include "rng.h" #include "rng.cpp" int main() { cout<<"Ten random numbers are: "<<endl; for(double i = 0; i<=10; i++) { cout<<generate(); } return 0; }



LinkBack URL
About LinkBacks



