Click here to Skip to main content
15,846,727 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CProgressCtrl cannot be passed as a parameter Pin
PJ Arends14-Jul-06 11:18
professionalPJ Arends14-Jul-06 11:18 
AnswerRe: CProgressCtrl cannot be passed as a parameter Pin
eusto14-Jul-06 11:19
eusto14-Jul-06 11:19 
GeneralRe: CProgressCtrl cannot be passed as a parameter Pin
PJ Arends14-Jul-06 11:26
professionalPJ Arends14-Jul-06 11:26 
GeneralRe: CProgressCtrl cannot be passed as a parameter Pin
eusto14-Jul-06 11:33
eusto14-Jul-06 11:33 
AnswerRe: CProgressCtrl cannot be passed as a parameter Pin
Hamid_RT14-Jul-06 20:07
Hamid_RT14-Jul-06 20:07 
QuestionGet button color from theme Pin
cje14-Jul-06 9:28
cje14-Jul-06 9:28 
AnswerRe: Get button color from theme Pin
Joe Woodbury14-Jul-06 10:26
professionalJoe Woodbury14-Jul-06 10:26 
Questiondynamic arrays in classes - are they correct? Pin
jon-8014-Jul-06 9:13
professionaljon-8014-Jul-06 9:13 
I'm creating a class and trying to create a dynamic array of Prime Numbers. However, the compiler is giving this error:

c:\Documents and Settings\Jon\My Documents\Visual Studio Projects\IAD Practice and Assignment\C++ - Assignment\C++ - Assignment\01 - Primes\Previous Versions\v0.3\Primes\PrimeGen.cpp(39): error C2664: 'CPrimeGen::isPrime' : cannot convert parameter 1 from 'int' to 'int *'



class CPrimeGen
{
public:
CPrimeGen(int iUpperBound);
CPrimeGen(int iUpperBound, int iInterval);
CPrimeGen(int iLowerBound, int iUpperBound, int iInterval);
virtual ~CPrimeGen();


bool isPrime (int iNumber);
bool *PrimeNumber; // array of PrimeNumbers


};


PrimeGen.cpp
CPrimeGen::CPrimeGen(int iUpperBound)
{
int iNoOfIntervals = iUpperBound + 1;
this->PrimeNumber = new bool[iNoOfIntervals];

for (int iIndex = 1; iIndex <= iUpperBound; iIndex++)
{
if (isPrime(iIndex) == true)
{this->PrimeNumber[iIndex] = true;}
else
{this->PrimeNumber[iIndex] = false;}
}

}
CPrimeGen::CPrimeGen(int iUpperBound, int iInterval)
{
int iNoOfIntervals = (iUpperBound / iInterval) + 1;
this->PrimeNumber = new bool[iNoOfIntervals];

for (int iIndex = 1; iIndex <= iUpperBound; iIndex+= iNoOfIntervals)
{
if (isPrime(iIndex) == true)
this->PrimeNumber[iIndex] = true;
else
{this->PrimeNumber[iIndex] = false;}
}
}

CPrimeGen::CPrimeGen(int iLowerBound, int iUpperBound, int iInterval)
{
int iNoOfIntervals = ((iUpperBound - iLowerBound + 1) / iInterval ) + 1;
this->PrimeNumber = new bool[iNoOfIntervals];

for (int iIndex = iLowerBound; iIndex <= iUpperBound; iIndex+= iNoOfIntervals)
{
if (isPrime(iIndex) == true)
this->PrimeNumber[iIndex] = true;
else
{this->PrimeNumber[iIndex] = false;}
}
}

CPrimeGen::~CPrimeGen(void)
{
delete [] PrimeNumber;
}

bool CPrimeGen::isPrime(int iNumber)
{

/* hard-setting prime numbers */
if (iNumber <= 1) return false;

/* Algorithm: Sieve of Erastosthenes*/

int *mPrimeNumber;
mPrimeNumber = new int[iNumber + 1];
int iIndex;

/* initialize values
0: not set
1: prime
2: not-prime
*/
for (iIndex = 0; iIndex <= iNumber; iIndex++)
{mPrimeNumber[iIndex] = 0;}

iIndex = 2;
mPrimeNumber[iIndex] = 1;
for (iIndex = iIndex * iIndex; iIndex <= iNumber; iIndex += 2)
{mPrimeNumber[iIndex] = 2;}

iIndex = 2;
while (iIndex <=iNumber)
{
iIndex++;
// the next unset number is a prime
if (mPrimeNumber[iIndex]==0)
{ mPrimeNumber[iIndex] = 1;

// multiples of iIndex set as non-prime
for (int iInnerIndex = iIndex * 2; iInnerIndex <= iNumber; iInnerIndex += iIndex)
{mPrimeNumber[iInnerIndex] = 2;}}
}

// set return value
switch (mPrimeNumber[iNumber])
{ case 1:
{
delete [] mPrimeNumber;
return true;
break;
}
case 2:
{
delete [] mPrimeNumber;
return false;
break;
}
}
};

Jon
AnswerRe: dynamic arrays in classes - are they correct? Pin
cje14-Jul-06 10:05
cje14-Jul-06 10:05 
AnswerRe: dynamic arrays in classes - are they correct? Pin
Zac Howland14-Jul-06 10:29
Zac Howland14-Jul-06 10:29 
AnswerRe: dynamic arrays in classes - are they correct? Pin
Hamid_RT15-Jul-06 6:03
Hamid_RT15-Jul-06 6:03 
QuestionVS2005 Team Pin
Alex_Y14-Jul-06 9:12
Alex_Y14-Jul-06 9:12 
AnswerRe: VS2005 Team Pin
Jun Du14-Jul-06 9:22
Jun Du14-Jul-06 9:22 
GeneralRe: VS2005 Team Pin
Alex_Y14-Jul-06 9:43
Alex_Y14-Jul-06 9:43 
GeneralRe: VS2005 Team Pin
Jun Du14-Jul-06 10:23
Jun Du14-Jul-06 10:23 
GeneralRe: VS2005 Team Pin
Alex_Y14-Jul-06 10:36
Alex_Y14-Jul-06 10:36 
GeneralRe: VS2005 Team Pin
Jun Du14-Jul-06 10:49
Jun Du14-Jul-06 10:49 
GeneralRe: VS2005 Team Pin
Alex_Y14-Jul-06 12:25
Alex_Y14-Jul-06 12:25 
QuestionWhat's the best way to do this? Pin
Alex Cutovoi14-Jul-06 9:07
Alex Cutovoi14-Jul-06 9:07 
QuestionRe: What's the best way to do this? Pin
Jun Du14-Jul-06 9:27
Jun Du14-Jul-06 9:27 
AnswerRe: What's the best way to do this? Pin
Alex Cutovoi14-Jul-06 9:55
Alex Cutovoi14-Jul-06 9:55 
GeneralRe: What's the best way to do this? Pin
Jun Du14-Jul-06 10:47
Jun Du14-Jul-06 10:47 
QuestionDifference between debug and execution on open file Pin
hli114-Jul-06 8:52
hli114-Jul-06 8:52 
AnswerRe: Difference between debug and execution on open file Pin
eusto14-Jul-06 9:12
eusto14-Jul-06 9:12 
GeneralRe: Difference between debug and execution on open file Pin
hli114-Jul-06 9:35
hli114-Jul-06 9:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.