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;
// TODO : COMBO operator
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
{
// TODO: COMBO
};
#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;
}
// TODO: COMBO
//--- End of File ---
```
Sample Test Code :
#include "Binary.h"
#include "AND.h"
#include "XOR.h"
#include "COMBO.h"
#include "COMBO2.h"
TEST(Test_Proxy_Combo_Enable, TestConfig::ALL)
{
#if Test_Proxy_Combo_Test_Enable
Binary a1(0x1);
Binary a2(0x2);
Binary a3(0x5);
Binary a_Binary;
unsigned int a_Value;
a_Binary = a1 & a2^ a3;
a_Value = a1 & a2^ a3;
CHECK(a_Binary.x ==0x8);
CHECK(a_Value ==0x8);
#endif
} TEST_END
Please Modify Binary.h, Binary.cpp. must pass Sample Test Code.
Do Not Modify Test Code.

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

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions