Goal

This programming assignment exercises how to construct abstract data types through implementing a finite data structure class in C++. It also reviews operator overloading, and input/output including the friend concept.

Overview of FakeFinite Ring Class

Your data structure shares some similarities with rings, integral domains, and fields in finite mathematics, but differs from these slightly for the sake of complexity. Finite mathematics is the fundamental basis for many types of cryptography such as AES and RSA. Finite Rings consist of a finite set, R and two operators referred to as and x. In this assignment, + and x will represent modulo arithmetic operators for Plus and Multiply.

The class you will design should have the following features.

Constructor

Your constructor requires 2 integer arguments, a value and an order. The order must be greater than 2. Throw an exception if this is not true. If the value argument is outside of the range of 0 <= value <= order -1 then store a congruent value within that range instead of the value that was passed as a parameter.

Data members

The FakeFinite Ring has two members which must be an integer type. These are the value and the order.

Member functions

Provide the following two member functions:

  • order() - returns the order of the field
  • value() - returns the value as an integer

Math operators

The class must implement binary arithmetic operations: addition, subtraction, multiplication. You will overload standard c++ operators (+, -, *).

Addition (+)

Perform modular addition between the lefthand and righthand side. At least one of the two values is of type FakeFiniteRing, but one of them may be an integer. If the two FakeFinite Rings are not of the same order then throw an exception.

LefthandValue + RighthandValue mod Order

Subtraction(-)

Performs modular subtraction, subtracting the righthand side from the lefthand side. At least one of the two values is of type FakeFinite Ring, but one of them may be an integer. If the two FakeFinite Rings are not of the same order then throw an exception.

LefthandValue - RighthandValue mod Order

Multiplication(*)

Performs modular multiplication, multiplying the left hand side by the right hand side. At least one of the two values is of type FakeFinite Ring, but one of them may be an integer. If the two FakeFinite Rings are not of the same order then throw an exception.

Comparison

The class must implement overloaded ==. !=. This will imply mathematical congruence between two values. At least one of the two values is of type FakeFiniteRing, but one of them may be an integer. If the two FakeFinite Rings are not of the same order then throw an exception.

Assignment

The class must implement overloaded +=, -=, *-

Stream I/O

The class must implement the overloaded << and >> operators:

Input

Take two integer values as the value and the order.

Output in the format:

[Value, Order]

Statement of Work

Design and implement a FakeFiniteRing class to work with FFRDriver.cpp

#include < iostream >
#include "FakeFiniteRing.h"
using namespace std;
int main( ) {


FakeFiniteRing ffr3(5, 10);
FakeFiniteRing ffr4(8, 10);
FakeFiniteRing ffr5(15, 10);
FakeFiniteRing ffr6(8, 15);

try {
FakeFiniteRing ffr7 = ffr3 + ffr6;
}
catch (...) {
cout << "Caught bad addition" << endl;
}

try {
FakeFiniteRing ffr7 = ffr3 - ffr6;
}
catch (...) {
cout << "Caught bad subtraction" << endl;
}
try {
FakeFiniteRing ffr7 = ffr3 * ffr6;
}
catch (...) {
cout << "Caught bad multiplication" << endl;
}
try {
if (ffr4 == ffr6);
}
catch (...) {
cout << "Caught bad equivalence" << endl;
}
try {
if (ffr4 != ffr6);
}
catch (...) {
cout << "Caught bad non equivalence" << endl;
}


cout << "ffr3 = " << ffr3 << endl;
cout << "ffr5 = " << ffr5 << endl;
cout << "ffr3 + ffr4" << ffr3 + ffr4 << endl;
cout << "ffr3 * ffr4" << ffr3 * ffr4 << endl;
cout << "ffr3 - ffr4" << ffr3 - ffr4 << endl;
cout << "ffr3 + 8" << ffr3 + 8 << endl;
cout << "ffr3 * 8" << ffr3 * 8 << endl;
cout << "ffr3 - 8" << ffr3 - 8 << endl;
ffr3 += ffr4;
cout << "ffr3 += ffr4" << ffr3 << endl;
ffr3 *= ffr4;
cout << "ffr3 *= ffr4" << ffr3 << endl;
ffr3 -= ffr4;
cout << "ffr3 -= ffr4" << ffr3 << endl;
ffr3 += 8;
cout << "ffr3 += 8" << ffr3 << endl;
ffr3 *= 8;
cout << "ffr3 *= 8" << ffr3 << endl;
ffr3 -= 8;
cout << "ffr3 -= 8" << ffr3 << endl;

if (ffr3 == ffr5) {
cout << "ffr3 == ffr5" << endl;
}

if (ffr3 != ffr4) {
cout << "ffr3 != ffr4" << endl;
}

cout<< "Value of ff4 is " << ffr4.value() <cout<< "Order of ff4 is " << ffr4.order() <

cout << "type two ints for ffr3: ";
cin >> ffr3;

cout << "ffr3 = " << ffr3 << endl;

return 0;

}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.