#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <string>
using namespace System;
using namespace std;
class Sito
{
private:
public:
bool *array1;
int cRange;
~Sito()
{
delete [] array1;
cout << "Memory deleted!\n";
}
Sito(int nRange)
{
cRange = nRange;
array1 = new bool[nRange];
for (int i = 2; i < nRange; i++)
{
array1[i] = 0;
}
}
void Odsiej()
{
for (int i = 2; i*i <= cRange; i++)
if (!array1[i])
for (int j = i*i; j <= cRange; j += i)
array1[j] = 1;
}
void Wyswietl()
{
cout << "Prime numbers:\n";
for (int i = 2; i < cRange; i++)
{
if (!array1[i])
cout << i << " ";
}
}
void Sprawdz(int check)
{
for (int i = 2; i < cRange; i++)
{
if (i == check)
{
if (array1[i] == 0)
cout << "This is prime nuber!\n";
else
cout << "It isn't a prime number!\n";
}
else
{
}
}
}
};
int main(void)
{
cout << " Erestotenes' sieve by Maszaczek.\n\n";
cout << "Set range: ";
int mRange;
cin >> mRange;
Sito *program = new Sito(mRange);
program->Odsiej();
//program->Wyswietl();
cout << "\n\n\nWould you like to check number from 2.." << mRange << " <y/n>: ";
char choice;
cin >> choice;
int check;
if (choice == 'y' || choice == 'Y')
{
cout << "Which number would you like to check?: ";
cin >> check;
program->Sprawdz(check);
}
else
{
}
delete program;
//program->~Sito();
To mój cały kod. Gdzie mogą być śmieci albo gdzie mogło zostać to już usunięte?