mercredi 16 mars 2016

Not able to access a vector from private data section?

I have a C++ assignment to create a more random random number generator in C++. specifics can be found:http://ift.tt/1QYRoVS .

I'm getting an error message every time I try to access the vector in the private data section, and I can't figure out why?

I am also using complex Double and Integer classes that we created separately.

Header file:

 #ifndef RANDOM
 #define RANDOM

 #include "Double.h"
 #include "Integer.h" 
 #include <vector>
 #include <iostream>
 #include <time.h>


 const int VECT_SIZE =250;
 const int PERCENT = 225;

 class Random
 {
 private:
     std::vector<double> vect(int(VECT_SIZE));
     void fillVect(double min, double max);
     void shuffle();

int index;

 public:
     Random(); // Default constructor 
     Random(double min, double max); 
     Random(Double min, Double max);
     Random(int min, int max); 
     Random(Integer min, Integer max); 

     Random(int seed); //seed the random number generator
     int nextInt(); // Returns the next random number as an int
     double nextDbl(); 
     void setRange(double min, double max); 
     Integer nextInteger();
     Double nextDouble();

 };
 #endif

Parts of main class that seem to have errors:

 void Random::fillVect(double min, double max)
 {
     for(int i = 0; i < VECT_SIZE; i++)
         {
    this->vect.push_back((((double)rand()/(double)RAND_MAX)*(max - min)) + min);

 }
shuffle();

 }
 void Random::shuffle()
 {
     index =0;
     for (int i = 0; i <100; i++)
     {
         int r = rand() % VECT_SIZE;
         this->vect.push_back(vect[r]);
     } 
 }

Parts of main class that seem to have errors:

 Random::Random(double min, double max)
 {
     vect.clear();
     fillVect(min, max);
 }

Parts of main class that seem to have errors:

 double Random::nextDbl()
 {
     if(index>PERCENT)
     {
         this->shuffle();
     }
     index++;
     return this->vect[index];    
 }




Aucun commentaire:

Enregistrer un commentaire