Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overload the binary XOR operator ^ . Overload the binary AND operator & . Overload a COMBO combination of AND , XOR to change it

Overload the binary XOR operator ^.
Overload the binary AND operator &.
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
Overload a COMBO2 combination of XOR, AND to change its behavior.
o Instead of doing the binary operations do a three element subtraction.
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
// Binary
#ifndef BINARY_H
#define BINARY_H
struct Binary;
struct XOR;
struct AND;
struct COMBO;
struct COMBO2;
struct Binary
{
// Cannot modify these operators
Binary();
Binary(unsigned int _x);
Binary(const Binary &r);
~Binary();
Binary operator =(const Binary &r);
// add / modify methods here:
// HINT: you might need to delete the next three methods
// start doing your proxy with a empty Binary class
// easier than trying to refactor...
XOR operator ^(const Binary& r) const;
AND operator & (const Binary& r) const;
operator unsigned int() const;
// Data: (do not add or modify the data)
unsigned int x;
};
#endif
//--- End of File ---
#include "Binary.h"
#include "AND.h"
#include "XOR.h"
#include "COMBO2.h"
Binary::Binary()
{
this->x =0;
}
Binary::Binary(unsigned int _x)
{
this->x =_x;
}
Binary::Binary(const Binary &r)
{
this->x = r.x;
}
Binary::~Binary()
{
}
Binary Binary::operator =(const Binary &r)
{
this->x = r.x;
return *this;
}
XOR Binary::operator ^(const Binary& r) const
{
return XOR(*this, r);
}
AND Binary::operator & (const Binary& r) const
{
return AND(*this, r);
}
Binary::operator unsigned int() const
{
return this->x;
}
//--- End of File ---
// AND
#ifndef AND_H
#define AND_H
struct Binary;
struct XOR;
struct AND;
struct COMBO;
struct COMBO2;
struct AND
{
AND(const Binary& a, const Binary& b);
operator Binary() const;
operator unsigned int() const;
private:
unsigned int result;
};
#endif
//--- End of File ---
#include "AND.h"
#include "Binary.h"
#include "COMBO.h"
// Add methods here:
AND::AND(const Binary& a, const Binary& b)
: result(a.x& b.x)
{
}
AND::operator Binary() const
{
return Binary(result);
}
AND::operator unsigned int() const
{
return result;
}
//--- End of File ---
// XOR
#ifndef XOR_H
#define XOR_H
// forward declaration
struct Binary;
struct XOR;
struct AND;
struct COMBO;
struct COMBO2;
struct XOR
{
XOR(const Binary& a, const Binary& b);
operator Binary() const;
operator unsigned int() const;
private:
unsigned int result;
};
#endif
//--- End of File ---
#include "XOR.h"
#include "Binary.h"
// Add methods here:
XOR::XOR(const Binary& a, const Binary& b)
: result(a.x^ b.x)
{
}
XOR::operator Binary() const
{
return Binary(result);
}
XOR::operator unsigned int() const
{
return result;
}
//--- End of File ---
// COMBO
#ifndef COMBO_H
#define COMBO_H
struct Binary;
struct XOR;
struct AND;
struct COMBO;
struct COMBO2;
struct COMBO
{
// TODO
};
#endif
//--- End of File ---
#include "COMBO.h"
#include "Binary.h"
// TODO
//--- End of File ---
// COMBO2
#ifndef COMBO2_H
#define COMBO2_H
struct Binary;
struct XOR;
struct AND;
struct COMBO;
struct COMBO2;
struct COMBO2
{
// TODO
};
#endif
//--- End of File ---
#include "COMBO2.h"
#include "Binary.h"
// TODO
//--- End of File ---
Should see something like this sample codes:
Binary b1(0xa);
Binary b2(0x6);
Binary b_Binary;
unsigned int b_Value;
// Normal
b_Binary = b1^ b2;
b_Value = b1^ b2;
b_Binary = b1 & b2;
b_Value = b1 & b2;
Binary a1(0x1);
Binary a2(0x2);
Binary a3(0x5);
Binary a_Binary;
unsigned int a_Value;
// Combo
a_Binary = a1 & a2^ a3;
a_Value = a1 & a2^ a3;
Binary c1(0xF);
Binary c2(0x7);
Binary c3(0x5);
Binary c_Binary;
unsigned int c_Value;
// Combo2
c_Binary = c1^ c2 & c3;
output :
b1-->0xa
b2-->0x6
b_Binary = b1^ b2-->0xc
b_Value = b1^ b2-->0xc
b_Binary = b1 & b2-->0x2
b_Value = b1 & b2-->0x2
a1-->0x1
a2-->0x2
a3-->0x5
a_Binary = a1 & a2^ a3-->0x8
a_Value = a1 & a2^ a3-->0x8
c1-->0xF
c2-->0x7
c3-->0x5
c_Binary = c1^ c2 & c3-->0x3
c_Value = c1^ c2 & c3-->0x3

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

More Books

Students also viewed these Databases questions

Question

1. Discuss the four components of language.

Answered: 1 week ago

Question

a. How many different groups were represented?

Answered: 1 week ago