Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project 3: BitVector & Application Implementing BitVector of undetermined size implementing new concepts of copy constructor and assignment operators as well as destructors to determine

Project 3: BitVector & Application

Implementing BitVector of undetermined size implementing new concepts of copy constructor and assignment operators as well as destructors to determine the prime numbers up to a maximum range.

Educational Objectives. After successfully completing this assignment, the student should be able to accomplish the following:

Implement a class from a class definition

Implement class BitVector

You may use the bitset and iomanip library

Implement global operators for a class

Implement global operators class BitVector

Correctly separate class definition and implementation using files

Create executables of class client programs using makefiles and the Make utility

Test a class using specs and an existing test platform

Create client applications to determine the Prime Numbers up to a maximum range

Operational Objectives: Implement the class BitVector

Deliverables: bitvector.cpp, bitvector.h, makefile

bitvector.h: I have included a draft or start of the bitvector.h which you may use and/or modify. Submit your own copy. Your program must work with the supplied main routine

#ifndef BITVECTOR_H #define BITVECTOR_H #include #include #include using namespace std; class BitVector { public: BitVector(); // Default Constructor explicit BitVector (size_t); // construct a BitVector // with specified size BitVector (const BitVector&); // copy constructor ~BitVector (); // Destructor void Set (const size_t index); // make index bit = 1 void Set (); // make all bits = 1 void Unsetmultiple(const size_t index); // Unset all bits up to the // max number that are multiples // of the number passed in; not including // the number passed in. void Unset (const size_t index); // make index bit = 0 void Unset (); // make all bits = 0 void Flip (const size_t index); // flip index bit (change value of bit) void Flip (); // flip all bits bool Test (size_t index) const; // return index bit value true if it is set // false otherwise. void Print (const string x); // Prints index value // of the bits turned on. BitVector& operator = (const BitVector& a); // assignment operator overload size_t Size () const; // return the number of bits which is 32 times // the number of words. private: int size; // Number of words; bitset<32> * bvect; // Bit Vector dynamically }; #endif

Sample Main Routine to test if all of your member functions are defined:

#include #include "bitvector.h" #include using namespace std; void TheSeive(BitVector & pn); int main() { int largestprime=-0; cout << "Hello, BitVextor World!" << endl; // ****************************************************************** // * Test the Default BitVector * // ****************************************************************** BitVector DefaultVector; BitVector CopyofDefaultVector; BitVector PrimeListTo(100); // Prime numbers to 100 // ****************************************************************** // * Set all the odd bits on and print it out. * // ****************************************************************** for (int x=0; x

}

Functional Requirements:

Implement the bitvector.h as stated in this document exactly. You may add the library if you wish.

Test the functionality of all of the methods even if they are not used in determining if a vector was set or not.

Write your own driver and be sure to test all of your member functions to see if the work properly. For instance, the Flip() should reverse all the bits. I would print out a before and after.

Your constructors should turn all bits initially to off.

Test the Flip() method that reverses all the bits by performing the Flip() and print out the bitvector to ensure all were flipped. I would print out a before and after .

The default constructor should allocate enough words to store 256 bits.

void Set (const size_t index); - Passes in a constant integer zero or larger and turns that particular bit on. If the bit value is out of range then take no action.

void Set (); - Sets all bits to ones. You can do this by setting each word to a -1.

void Unset (const size_t index); - Unsets all bits to zeros.

void Flip (const size_t index); - Passes in a constant integer zero or larger and flips that particular bit. If the bit value is out of range then take no action.

void Flip (); - Reverse all of the bits.

bool Test (size_t index) const; - Check the bit passed in as a positive integer value. Return a True if the bit is set to one, otherwise return zero. If the value is out of range then return zero.

void Print (string S); - Print the status of each bit. You may elect to print only the bits turned on or whether a bit is turned on or off. Passes a string to print as a header.

explicit BitVector (size_t); - Creates a new BitVector object of size passed in.

BitVector (const BitVector&); - Creates a new BitVector object and copies the contents of the the BitVector object passed in as a parameter.

~BitVector (); - Destroy and deallocate the memory for the BitVector Object.

BitVector& operator = (const BitVector& a); - Copy (over write) the contents of one BitVector into another. They must be of the same size.

size_t Size () const; - Return the size in the number of bits that the object will hold.

void Unsetmultiple (const size_t index); - A value is passed to this function and the function unsets all bit locations that are multiples of that value. This is part of the Sieve algorithm.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

What are the purposes of promotion ?

Answered: 1 week ago

Question

What factors in Nooyis Five C model facilitate employee trust?

Answered: 1 week ago