Problem 2 Replace the Add method with operator+ Replace the Mul method with oper
ID: 3636029 • Letter: P
Question
Problem 2Replace the Add method with operator+
Replace the Mul method with operator*
Overload operator- for ModuloZ objects
Overload the << and >> operators for ModuloZ objects
Read your test values from a file and write your test results to a file.
Problem 3
Refine the ModuloZ class as a template class. Test it for at least 2 numeric classes.
#include "ModuloZ.h"
ModuloZ::ModuloZ(void)
{
_n = 1;
_z = 2;
}
ModuloZ::ModuloZ(int n)
{
_n = n;
_z = 2;
normalize();
}
ModuloZ::ModuloZ(int n, int z)
{
if(z < 2)
z = 2;
_n = n;
_z = z;
normalize();
}
int ModuloZ::N(void) const
{
return _n;
}
int ModuloZ::Z(void) const
{
return _z;
}
void ModuloZ::normalize(void)
{
_n = _n % _z;
if(_n < 0)
_n = _n + _z;
}
ModuloZ ModuloZ::Add(const ModuloZ& b)
{
assert(Z() == b.Z());
int sum = N() + b.N();
ModuloZ c(sum, Z());
return c;
}
ModuloZ ModuloZ::Mul(const ModuloZ& b)
{
assert(Z() == b.Z());
int product = N() * b.N();
ModuloZ c(product, Z());
return c;
}
void ModuloZ::show(ostream& outs)
{
outs << N() << " mod " << Z();
}
---------------------------------------------------------
#ifndef MODULO_Z
#define MODULO_Z
#include <cassert>
#include <iostream>
#include <string>
using namespace std;
class ModuloZ
{
public:
ModuloZ(void);
ModuloZ(int n);
ModuloZ(int n, int z);
int N(void) const;
int Z(void) const;
ModuloZ Add(const ModuloZ& b);
ModuloZ Mul(const ModuloZ& b);
void show(ostream& outs = cout);
private:
void normalize();
int _n;
int _z;
};
#endif
Explanation / Answer
Hi I have done the solution for this in my notebook. But the solution is too big , I cannot type it here because very less time is remaining.. So please rate me Lifesaver and I'll share the answer with you through email or cramster inbox. I don't do this generally, but I have no other option here because there's very less time left... you need not worry as I have the solution ready
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.