Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please comment steps on each line / use camelCasing and explain using Clion C + + , Task 1 - BitsByte class Supplemental Material This

Please comment steps on each line
/
use camelCasing and explain using Clion C
+
+
,
Task
1
-
BitsByte class
Supplemental Material
This assignment is going to require that you read the supplemental lecture material found here.
Class Construction
Create a class called BitsByte that will store one byte of data.
C
+
+
-
You should create a header called BitsByte.h
,
where the class definition will be placed. You should also have a corresponding
.
cpp file called Byte.cpp
Java
-
BitsByte should be a public class and should be in a file named BitsByte.java
Private Data:
From the supplemental material, you should have observed that a byte consists of
8
bits. To store these
8
bits of information, we are going to need an array. In the data section of the class create an array called bits that will hold
8
-
integer values to store the
1
'
s and
0
'
s for the Byte.
As an example, if we were to store the value
6
5
in the data section of our class, The int array will hold
0
1
0
0
0
0
0
1
Create the following utility function:
int bitsToInt
(
)
-
this function will return the bit values stored in the data section as an int
(
whole number
)
value.
Public Methods:
Create the following functions
/
methods :
void setValue
(
int value
)
-
this function will take as an argument an int type. The argument is going to be the value we want to set our bits to
.
To set the bits we are going to have to use some bitwise operators. Here is how it works.
A value like
6
5
has a binary value of
0
1
0
0
0
0
0
1
This will require you to create a loop and use AND along with the left shift operators to determine the value of each bit and store it in the array. Using bitwise operators is a requirement here.
int at
(
int index
)
-
takes as an argument an int value called index. This function will return the bit located in the array at index. This value should be returned as an int.
string toString
(
)
-
returns the array as a string.
int toInt
(
)
-
This function will return the value in the array as a whole number. This function should call the private function bitsToInt.
Constructors
Your BitsByte class should have the following constructors
BitsByte
(
int
*
bits
_
array
)
-
Sets the data section with the value found in the array. Note: the array should be a size of
8
and should hold a binary representation of a whole number
BitsByte
(
int value
)
-
Sets the data section to val
BitsByte
(
string value
_
string
)
-
Sets the value of the data section to the value found in value. Note: value should be a string representation of a binary number.
BitsByte
(
)
-
Default constructor that sets the data section to
0
Testing
Create a file called main.cpp and in it create the main function where you can test your code. Write some code in main that will test all functionality created. I will leave it up to you to one how to do this but you should be as thorough as possible
Example Run:
This is simply an example and does not show all possibilities
C
+
+
#include
#include "BitsByte.h
"
using namespace std;
int main
(
)
{
BitsByte bite;
bite.setValue
(
9
9
)
;
for
(
int i
=
0
; i
<
8
; i
+
+
)
cout
<
<
bite.at
(
i
)
<
<
endl;
cout
<
<
"Int:
"
<
<
bite.toInt
(
)
<
<
endl;
cout
<
<
"String:
"
<
<
bite.toString
(
)
<
<
endl;
return
0
;
}
Java
public static void main
(
String
[
]
args
)
{
BitsByte bite
=
new BitsByte
(
)
;
bite.setValue
(
9
9
)
;
for
(
int i
=
0
; i
<
8
; i
+
+
)
System.out.println
(
"
"
+
bite.at
(
i
)
)
;
System.out.printf
(
"
Int:
%
d
"
,
bite.toInt
(
)
)
;
System.out.printf
(
"
String:
%
s
"
,
bite.toString
(
)
)
;
}
Output
1
1
0
0
0
1
1
0
Int:
9
9
String:
0
1
1
0
0
0
1
1
Press any key to close this window
.
.
.
Task
2
-
Constructors
For the BitsByte class create the following constructors:
Constructors:
Byte
(
)
Default constructor that sets all bits to
0
.
You should delegate this constructor so that it calls Byte
(
int val
)
.
We want to keep one code path wherever possible.
Byte
(
int value
)
Sets the bits correctly for the value being passed in
.
For instance, if you input
7
the bits should be
0
0
0
0
0
1
1
1
or stored as
1
1
1
0
0
0
0
0
Byte
(
int bits
_
array
[
]
)
Stores the values in the array to the appropriate bits. Please note that you need to make sure that each value of the array contains either a
1
or a
0
.
If it does not set all bits to
0
Task
3
-
Functionali

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_2

Step: 3

blur-text-image_3

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

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions