Every time I run it, it would give me "Prob1.cpp:6:9: error: invalid conversion from 'const char*' to 'char*' [-fpermissive] set = rndseq;" can someone please help me fix this?
The purpose of the program: is to loop a.randFromSet(); 100,000 times and give back the frequency of each time a number in rndseq[] has been called.
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
#ifndef PROB1_H
#define PROB1_H
class Prob1Random
{
private:
char *set; //The set of numbers to draw random numbers from
char nset; //The number of variables in the sequence
int *freq; //Frequency of all the random numbers returned
int numRand; //The total number of times the random number function is called
public:
Prob1Random(constchar,constchar *); //Constructor
~Prob1Random(void); //Destructor
char randFromSet(void); //Returns a random number from the set
int *getFreq(void) const{ return freq; }; //Returns the frequency histogram
char *getSet(void) const{ return set; }; //Returns the set used
int getNumRand(void) const{ return numRand; }; //Gets the number of times randFromSet has
//been called
};
"Error: a value of type "const char *" cannot be assigned to an entity of type "char *""
The whole point of "const" is that the value never gets changed. When you do "set = rndseq" you are assigning something that can't be changed (const char *) to something that can (char *). You are also copying the address (since both of these are pointers), and that will guarantee that "seq" can change whatever rndseq is looking at it.
Okay, when I remove the delete set; and delete freq; and changed the "const char*" to char * it gives me "RUN FAILED (exit value 1, total time: 569ms)".
I threw a couple output statements around and it error happens to be every single one of my for- loops. I removed them one by one up until the last one and it ran without any errors afterwards. Let me try and fix it and I will report back.