Question & Answer: f i//implemented as++i p(i)-returns the predecessor of i.//implemented as –i padd(i, j) =…..

You have to use a .h file for class definitions and at least one.cpp file for the C++ implementation. Please submit enough screenshots showing compiling and execution under Linux. a. b. Assignment Instructions: Consider the following non-negative integer functions: // implemented as++i /implemented as-1 1. s(i) - returns the successor of i 2. p(i)-returns the predecessor of 1· 3. padd(i,j)=ipadd(s(i),p(j) // This recursive function returns 丨+) 4. prmul(i,j)- // This recursive function returns i × j ppwrGJ-ipmul((i, ppwr(i, p(j)) This recursive function returns l j < 1 Your task is to write a class referred to as Peano-Arithmetic The class should have at least two private integer members (e.g., int i; int j;) At the minimum, the class should include all the above operations ((1) to (5)) as public methods. At the minimum, the class should have a constructor and a destructor as well as a getter and a setter for its two private members (listed above). At the minimum, methods (1) and (2) should be in-line methods . . . . Test the class with a main function that sets an integer variable, m, to 2 and an integer variable, n, to 3 Next, the program calculates and outputs m using the Peano-Arithmetic class via the method that corresponds to ppwr(m, n)

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:

Still stressed from student homework?
Get quality assistance from academic writers!