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.
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.
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.
The FakeFinite Ring has two members which must be an integer type. These are the value and the order.
Provide the following two member functions:
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.
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.
The class must implement overloaded +=, -=, *-
The class must implement the overloaded << and >> operators:
Take two integer values as the value and the order.
[Value, Order]
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;
}