Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C + + ( make it so that there are two source files: Main.cpp and Byte.cpp , and one header file: Byte.h , and

In C++(make it so that there are two source files: Main.cpp and Byte.cpp, and one header file: Byte.h, and include all files in the solution please).
Modify The Menu
In this assignment you are going to modify the menu you created in Assignment 1 and use the modified version to test your Byte class functionality. In main you should add functionality to the menu that will allow you test the add, sub, mul, div functions in the class. For instance, here is an example of how to test your add functionality:
void byteAdd()
{
int val1, val2;
cout << "Enter two whole numbers "<< endl;
// Add code to test your add functionality
m.waitKey();
}
Of course to do this you are also going to need to add this function to your menu:
m.addMenu("1. Add Bytes ", byteAdd);
You are also going to have make a modification to your menu class. Currently it uses an array to hold a fixed amount of menu items. While this may be OK for most applications we want our menu to be as flexible as possible. To make this happen I want you to remove the array of menu items and replace it with a vector.
Modify Byte Class
Replace the int array called bits in the data section of the Byte class with a vector. You should use the vectors constructor to give it a size of 8. At this point it is not going to do much more than the array did but we want to add flexibility for later on.
You also must modify your constructors to set the size of the vector. If this is done correctly no other changes need to be made to your code. You should have four constructors, one of them is delegated. This means you need to add code to three of you constructors to resize the vector.
To do this you want to use the two argument resize function that is in vector. The first argument is the size to give the vector. The second argument is the value to fill it with:
vector v(3,10); // Creates a vector with a size of three each element set to 10
Overloaded Functions
In the Byte class create the following overloaded functions:
add
sub
mul
div
That take as arguments complex types and return complex types. Reminder that a complex type is a class type.
Example Run
#include
#include
#include "Byte.h"
using namespace std;
int main()
{
Byte b1(7);
Byte b2(3);
Byte b3= b1.add(b2);
cout << "Int: "<< b3.toInt()<< endl;
cout << "String: "<< b3.toString()<< endl;
return 0;
}
Int: 10
String: 00001010
Press any key to close this window ...

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 Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions