Unformatted text preview:

MAIN Driver include iostream using namespace std include sieve h include bitarray h int main unsigned int i max counter 0 cout nEnter a positive integer for the maximum value cin max BitArray ba max Sieve ba find the primes marking the bits cout The bit array looks like this n ba n cout nPrimes less than max n for i 0 i max i if ba Query i counter cout i if counter 8 0 cout n counter 0 else cout t cout nGoodbye n return 0 END MAIN H bitarray h BitArray class declaration ifndef BITARRAY H define BITARRAY H include iostream using namespace std class BitArray friend ostream operator ostream const BitArray friend bool operator const BitArray const BitArray friend bool operator const BitArray const BitArray public BitArray unsigned int BitArray const BitArray BitArray BitArray operator const BitArray unsigned int Length const void Set unsigned int void Unset unsigned int void Flip unsigned int bool Query unsigned int const unsigned char Mask unsigned int const private unsigned char barray int arraySize endif include bitarray h include cmath void Sieve BitArray b unsigned int size b Length for unsigned int i 0 i size i b Set i b Unset 0 b Unset 1 double sizeSqrt sqrt static cast double size for unsigned int i 2 i sizeSqrt i if b Query i continue for unsigned int j 2 i j size j i b Unset j END H CPP include bitarray h arraySize n sizeof unsigned char 8 n sizeof unsigned include iostream using namespace std constructor BitArray BitArray unsigned int n char 8 1 0 barray new unsigned char arraySize for int i 0 i arraySize i barray i 0 copy construcor BitArray BitArray const BitArray a arraySize a arraySize barray new unsigned char arraySize for int i 0 i arraySize i barray i a barray i deconstructor BitArray BitArray delete barray overload op BitArray BitArray operator const BitArray a if this a return this arraySize a arraySize delete barray barray new unsigned char arraySize for int i 0 i arraySize i barray i a barray i return this overload op bool operator const BitArray b1 const BitArray b2 if b1 arraySize b2 arraySize return false bool flag true for int i 0 i b1 arraySize flag i flag b1 barray i b2 barray i return flag overload op bool operator const BitArray b1 const BitArray b2 return b1 b2 overload op ostream operator ostream s const BitArray b s unsigned int len b Length for unsigned int i 0 i len i s b Query i s return s unsigned int BitArray Length const return arraySize sizeof unsigned char 8 sets the bits void BitArray Set unsigned int index barray index sizeof unsigned char 8 Mask index sizeof unsigned char 8 unsets the bits void BitArray Unset unsigned int index barray index sizeof unsigned char 8 Mask index sizeof unsigned char 8 flips the bits void BitArray Flip unsigned int index barray index sizeof unsigned char 8 Mask index sizeof unsigned char 8 makes the bits bool BitArray Query unsigned int index const return barray index sizeof unsigned char 8 Mask index sizeof unsigned char 8 0 shifts the bits unsigned char BitArray Mask unsigned int n const return 1 n x END CPP OTHER


View Full Document

FSU COP 3330 - Notes

Download Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?