Question: #include using namespace std; / / TODO: Implement all the classes and functions to make the following main function / / compiles , works, and

#include
using namespace std;
//TODO: Implement all the classes and functions to make the following main function
//compiles, works, and generates the output given in the Homework file.
int main(){
typedef int C;
C c =145960;
Bitter bitter1(c);
cout << "bitter1 has value "<< bitter1<< endl;
cout << "bitter1 has "<< bitter1.numberOfSetBits()<<" set bits inside" << endl << endl;
Bitter bitter2(c);
cout << "bitter2 is created from the same object" << endl;
cout << "bitter2 has value "<< bitter2<< endl << endl;
cout << "flipping the 0th and 3rd bits of bitter2"<< endl;
bitter2.flipBit(0);
bitter2.flipBit(3);
cout << "bitter1 has value "<< bitter1<< endl;
cout << "bitter2 has value "<< bitter2<< endl;
cout << "bitter2 has "<< bitter2.numberOfSetBits()<<" set bits inside" << endl << endl;
cout << "setting the 1st bit of bitter1 to 1 and 3rd bit of bitter2 to 0"<< endl;
bitter1.setBit(1,1);
bitter2.setBit(3,0);
cout << "bitter1 has value "<< bitter1<< endl;
cout << "bitter2 has value "<< bitter2<< endl << endl;
cout << "setting the 11th bit of bitter1 to 1"<< endl;
if(bitter1.setBit(11,1)==-1){
cout << "you are out of index: 11>="<< bitter1.getSize()<< endl;
} else {
cout << "set is done successfully "<< endl;
cout << "bitter1 has value "<< bitter1<< endl << endl;
}
cout << "negating the bits of bitter1"<< endl;
bitter1.negate();
cout << "bitter1 has value "<< bitter1<< endl << endl;
cout << "shifting bitter13 to the left and put 1 for the new bits" << endl;
bitter1.shiftLeft(3,1);
cout << "bitter1 has value "<< bitter1<< endl << endl;
cout << "shifting bitter23 to the right and put 0 for the new bits" << endl;
bitter2.shiftRight(3,0);
cout << "bitter2 has value "<< bitter2<< endl << endl;
cout <<"we are using an iterator to obtain the decimal value of bitter1"<< endl ;
BITerator btr(bitter1);
unsigned long long value;
value =0;
for(btr.init(); btr.hasMore(); ){
value += btr.current();
btr.next();
if(btr.hasMore()){
value *=2;
}
}
cout << "value for "<< bitter1<<" is "<< value << endl;
bitter2.negate();
value =0;
for(btr.init(); btr.hasMore();){
value += btr.current();
btr.next();
if(btr.hasMore()){
value *=2;
}
}
cout << "value for "<< bitter1<<" is "<< value << endl << endl;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!