Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C++) Please help me implement the BigIntegerArithmetic class: The BigIntegerArithmetic class: this class owns a reference to a ArithmeticExpression object and performs big integer arithmetic

(C++) Please help me implement the BigIntegerArithmetic class:

The BigIntegerArithmetic class:

this class owns a reference to a ArithmeticExpression object and performs big integer arithmetic on the expression

to keep it simple, operands used in tests are all positive so do not worry negative operands in this class!

when handling subtraction, the order of the subtrahend and minuend needs to be reversed when the subtrahend is greater; the sign of the result will be negative and needs to be kept separately in the object; when displaying the result, the operands should be displayed in the original order. Example: 30 - 45 should be internally calculated as -(45 - 30)

You may still get negative results from subtraction and you better store the sign separately

the operandComp method to compare two positive operands; it should return a positive value if the first is greater, return zero if two are the same, return a negative value if the first is less

you can compare the string length first and then use the string::compare method to compare two strings with the same lengths

string::compare only work well with strings with a same length!

the getResults method to return a string with the output in the format described in the project requirement as demonstrated in the following example

12 + 5 17

TEST CASES I HAVE TO PASS:

TEST_CASE("class BigIntegerArithmetic part a") { ArithmeticExpression ae; SECTION ("Simple sum") { ae = ArithmeticExpression("200","100",'+'); BigIntegerArithmetic bia(ae); CHECK(0 < bia.operandComp(ae.getOp1(),ae.getOp2())); CHECK(" 200 +100 300" == bia.getResults()); } SECTION ("Bigger operand second") { ae = ArithmeticExpression("100","200",'+'); BigIntegerArithmetic bia(ae); CHECK(0 > bia.operandComp(ae.getOp1(),ae.getOp2())); } SECTION ("Operands are equal") { ae = ArithmeticExpression("200","200",'+'); BigIntegerArithmetic bia(ae); CHECK(0 == bia.operandComp(ae.getOp1(),ae.getOp2())); } SECTION ("1st operand much larger") { ae = ArithmeticExpression("10000","900",'+'); BigIntegerArithmetic bia(ae); CHECK(0 < bia.operandComp(ae.getOp1(),ae.getOp2())); } SECTION ("2nd operand much larger") { ae = ArithmeticExpression("200","1000",'+'); BigIntegerArithmetic bia(ae); CHECK(0 > bia.operandComp(ae.getOp1(),ae.getOp2())); } }

ArithmeticExpression.hpp:

using namespace std; class ArithmeticExpression{ public: ArithmeticExpression(string op1,string op2, char op); ArithmeticExpression(){}; string getOp1(); string getOp2(); char getOperator(); private: string op1; string op2; char op; };

ArithmeticExpression.cpp:

#include "operand.hpp" ArithmeticExpression::ArithmeticExpression(string op1, string op2, char op){ this->op1 = op1; this->op2 = op2; this->op = op; } string ArithmeticExpression::getOp1(){ if((op2[0] == '-')||(op1[0] == '-')){ if(op2[0] == '-'){ if(op == '+'){ op = '-'; op2.erase(0, 1); }else if(op == '-'){ op = '+'; op2.erase(0, 1); } }else if(op1[0] == '-'){//- op1 //return op1? cout<<"op1 negative"<

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions