Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( C + + ) Refactor the Binary class to add one or more proxies to generate the desired output. Overload a COMBO combination of

(C++)Refactor the Binary class to add one or more proxies to generate the desired output.
Overload a COMBO combination of AND, XOR to change its behavior.
o Instead of doing the binary operations do a three element addition.
o a & b ^ c a + b + c
Do not ADD any files to the project
No free functions do all overloading inside classes as methods
No modern C++
o No Lambdas, Autos, templates, etc...
o No Boost
NO Streams
o Used fopen, fread, fwrite...
No code in MACROS
o Code needs to be in cpp files to see and debug it easy
Exception:
o implicit problem needs templates
// Binary.h
```cpp
#ifndef BINARY_H
#define BINARY_H
struct Binary
{
Binary();
Binary(unsigned int _x);
Binary(const Binary &r);
~Binary();
Binary operator =(const Binary &r);
struct XOR;
struct AND;
struct COMBO;
XOR operator ^(const Binary& r) const;
AND operator & (const Binary& r) const;
COMBO operator & (const XOR& r) const; // TODO : Need to Fix.
operator unsigned int() const;
// Data: (do not add or modify the data)
unsigned int x;
};
struct Binary::XOR
{
XOR(const Binary& a, const Binary& b);
operator Binary() const;
operator unsigned int() const;
const Binary& a;
const Binary& b;
};
struct Binary::AND
{
AND(const Binary& a, const Binary& b);
operator Binary() const;
operator unsigned int() const;
const Binary& a;
const Binary& b;
};
struct Binary::COMBO {
COMBO(const Binary& a, const XOR& b);
operator Binary() const;
operator unsigned int() const;
const Binary& a;
const XOR& b;
};
#endif
//--- End of File ---
```
// Binary.cpp
```cpp
#include "Binary.h"
Binary::Binary()// DO NOT MODIFY
{
this->x =0;
}
Binary::Binary(unsigned int _x)// DO NOT MODIFY
{
this->x =_x;
}
Binary::Binary(const Binary& r)// DO NOT MODIFY
{
this->x = r.x;
}
Binary::~Binary()// DO NOT MODIFY
{
}
Binary Binary::operator =(const Binary& r)// DO NOT MODIFY
{
this->x = r.x;
return *this;
}
Binary::XOR Binary::operator ^(const Binary& r) const
{
return XOR(*this, r);
}
Binary::AND Binary::operator & (const Binary& r) const
{
return AND(*this, r);
}
Binary::COMBO Binary::operator & (const XOR& r) const // TODO : Need to fix
{
return COMBO(*this, r);
}
Binary::operator unsigned int() const
{
return this->x;
}
Binary::XOR::XOR(const Binary& a, const Binary& b) : a(a), b(b){}
Binary::XOR::operator Binary() const
{
return Binary(a.x ^ b.x);
}
Binary::XOR::operator unsigned int() const
{
return a.x ^ b.x;
}
Binary::AND::AND(const Binary& a, const Binary& b) : a(a), b(b){}
Binary::AND::operator Binary() const
{
return Binary(a.x & b.x);
}
Binary::AND::operator unsigned int() const
{
return a.x & b.x;
}
Binary::COMBO::COMBO(const Binary& a, const XOR& b) : a(a), b(b){}
Binary::COMBO::operator Binary() const {
return Binary(a.x + b.a.x + b.b.x);
}
Binary::COMBO::operator unsigned int() const {
return a.x + b.a.x + b.b.x;
}
//--- End of File ---
```
Sample Test Code :
// Combo
Binary a1(0x1);
Binary a2(0x2);
Binary a3(0x5);
Binary a_Binary;
unsigned int a_Value;
Binary t_Binary;
unsigned int t_Value;
Binary tt_Binary;
unsigned int tt_Value;
Trace::out("a1-->0x%x
", a1.x);
Trace::out("a2-->0x%x
", a2.x);
Trace::out("a3-->0x%x
", a3.x);
Trace::out("
");
a_Binary = a1 & a2^ a3;
a_Value = a1 & a2^ a3;
Trace::out("a_Binary = a1 & a2^ a3-->0x%x
", a_Binary.x);
Trace::out("a_Value = a1 & a2^ a3-->0x%x
", a_Value);
Trace::out("
");
Sample Test Output :
a1-->0x1
a2-->0x2
a3-->0x5
a_Binary = a1 & a2^ a3-->0x8
a_Value = a1 & a2^ a3-->0x8
However, the problem currently occurring in the above code output :
a1-->0x1
a2-->0x2
a3-->0x5
a_Binary = a1 & a2^ a3-->0x5
a_Value = a1 & a2^ a3-->0x5
The test fails, 0x5 is an invalid output.
If I calculate a1 & a2and a2^ a3 separately
a1 & a2-->0x0
a2^ a3-->0x7
it seems like a2^a3 should be calculated first to get the result of 0x8... but I don't know how.
Please modify the COMBO part so that I get the same result as the sample output,
a1 & a2^ a3-->0x8.
!!!NEVER NEVER NEVER Chenge test code to like a1 & (a2^ a3)!!!
Please fix Binary.h and Binary.cpp
Chegg give wrong answer. I didn't ask about Java project in NetBeans

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

Students also viewed these Databases questions

Question

What role does cohesiveness play in team performance?

Answered: 1 week ago

Question

88. In Prob. 87, show that tr (AB) = tr (A) if and only if AB = A.

Answered: 1 week ago

Question

Explain the significance of employee selection.

Answered: 1 week ago

Question

Discuss the performance appraisal process.

Answered: 1 week ago