Consider the following non-negative integer functions: s(i) – returns the successor of i//implemented as++i p(i)-returns the predecessor of i.//implemented as –i padd(i, j) = {i j = 0 padd(s(i), p(j) j
Expert Answer
main.cpp
#include <iostream>
#include “PeanoArithmetic.cpp”
using namespace std;
int main(){
int m=2,n=3;
PeanoArithmetic peanoCalc;
peanoCalc.seti(m);
peanoCalc.setj(n);
cout<<“m^n=”<<peanoCalc.ppwr(m,n);
return 0;
}
PeanoArithmetic.h
#pragma once
#ifndef PEANOARITHMETIC_H
#define PEANOARITHNETIC_H
class PeanoArithmetic
{
private:
int i;
int j;
public:
PeanoArithmetic();
~PeanoArithmetic();
void seti(int);
void setj(int);
int geti();
int getj();
int s(int);
int p(int);
int padd(int,int);
int pmul(int,int);
int ppwr(int,int);
};
#endif
PeanoArithmetic.cpp
#include “PeanoArithmetic.h”
PeanoArithmetic::PeanoArithmetic()=default;
PeanoArithmetic::~PeanoArithmetic()=default;
void PeanoArithmetic::seti(int i){
this->i=i;
}
void PeanoArithmetic::setj(int j){
this->j=j;
}
int PeanoArithmetic::geti(){
return i;
}
int PeanoArithmetic::getj(){
return j;
}
inline int PeanoArithmetic::s(int i){
return ++i;
}
inline int PeanoArithmetic::p(int i){
return –i;
}
int PeanoArithmetic::padd(int i,int j){
if(j==0)
return i;
else if(j>0)
return padd(s(i),p(j));
};
int PeanoArithmetic::pmul(int i,int j){
if(j==1)
return i;
else if(j>1)
return padd(i,pmul(i,p(j)));
}
int PeanoArithmetic::ppwr(int i,int j){
if(j==1)
return i;
else if (j>1)
return pmul(i,ppwr(i,p(j)));
}
Output: