Purpose: To let you demonstrate your ability to manipulate C integers. Assignmen
ID: 3921021 • Letter: P
Question
Purpose:
To let you demonstrate your ability to manipulate C integers.
Assignment: Bit pattern manipulation
Finish the program below that does several bit-wise manipulations of C integers.
Cut and paste the following:
Finish the Program!
You may only use the integer constants given at the beginning. (You may use whatever integers you wish in string constants as long as they are for printf()'s. For example the format string "0x%08X" is useful for printing hexadecimal integers.)
You may only use the following integer operators:
+
-
++
--
<<
>>
~
|
&
<
>
=
!=
==
Sample output (32 bit):
Sample output (64 bit):
Explanation / Answer
include <iostream>
#include <cstdlib>
#include <string>
#include "String.h"
using namespace std;
int main (int argc, char **argv)
{
//Testing Default constructor, length, and print
String one;
cout << "The length of String one is: " << one.length() << endl;
cout << "The value of String one is: ";
one.print();
//Testing Alternate constructor, length, and print
char test[256] = "Hello world";
String two(test);
cout << "The length of String two is: " << two.length() << endl;
cout << "The value of String two is: ";
two.print();
//Testing the overloaded [] operator. This replaces your at() function.
cout << "The first letter is: " << two[0] << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.