Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment you will use what you have learned in the lecture material and practice problems to create the BitsByte class. You will use
In this assignment you will use what you have learned in the lecture material and practice problems to create the BitsByte class. You will use good Object Oriented Programming techniques to demonstrate your understanding of classes and class construction. This project will have a few different tasks for you to complete. A task is a task not a separate project. All tasks in the assignment should be in the same project.
Activity Objectives
This activity is designed to support the following Learning Objectives:
Compose computer programs using a high level programming languages as a means of problem solving. This includes abstract data types, inheritance, and polymorphism
Evaluate the advanced features of an object oriented programming language including arrays, pointer manipulation, recursion, and object oriented programming.
Instructions
Task 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 bits. To store these 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 integer values to store the s and s for the Byte.
As an example, if we were to store the values in the data section of our class. The int array will hold
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 setValueint 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 has a binary value of
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 atint 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. Please note that with binary values they are in the opposite order from the way we are storing them. The array has index going from left to right and binary numbers has bit to the right going right to left. This means you will have to reverse the array when creating the 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 just the default constructor for now:
BitsByte Default constructor that sets all bits to You should delegate this constructor so that it calls BitsByteint val We want to keep one code path wherever possible.
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;
forint i ; i ; i
cout bite.ati endl;
cout "Int: bite.toInt endl;
cout "String: bite.toString endl;
return ;
Java
public static void mainString args
BitsByte bite new BitsByte;
bite.setValue;
forint i ; i ; i
System.out.println bite.ati;
System.out.printfInt: d
bite.toInt;
System.out.printfString: s
bite.toString ;
Output
Int:
String:
Press any key to close this window
Task Constructors
For the BitsByte class add the following constructors in addition to the default constructor above:
Constructors:
C
BitsByteint ar Sets the data section with the value found in the array. Note: the array should be a size of and should hold a binary representation of a whole number
BitsByteint val Sets the data section to val
BitsBytestring val Sets the value of the data section to the value found in val. Note: val shoul
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started