Question: Exercise 4.1 (bigint)Write a program that applies the arithmetic operations +, -, *, namely, addition, subtraction, and multiplication, to arbitrary-large pairs of integers in exact

Exercise 4.1 (bigint)Write a program that applies the arithmetic operations +, -, *, namely, addition, subtraction, and multiplication, to arbitrary-large pairs of integers in exact precision. The program prompts the user to enter two (arbitrary-large) integers and a digit, either 0, 1, or 2, that indicates whether to apply addition, subtraction, or multiplication, respectively. The arbitrary-large integers that are operands of the arithmetic operations can be negative. Please use the following phrases (without the double quotes): Please enter the first integer: Please enter the second integer: Please enter the command (0=+, 1=-, 2=*): Examples: > b i g i n t Pl eas e ent e r the f i r s t i n t e g e r : 123456789012345678901234567890 Pl eas e ent e r the second i n t e g e r : 234567890123456789012345678901 Pl eas e ent e r the command (0=+, 1=, 2=): 2 28958998520042688603718947735485444664031397677651425088890 > b i g i n t Pl eas e ent e r the f i r s t i n t e g e r : 11 Pl eas e ent e r the second i n t e g e r : 17 Pl eas e ent e r the command (0=+, 1=, 2=): 1 28 Use the following enumeration called Command to represent the three commands: 1 enum Command { ADD = 0 , SUB, MUL } ; Place the above in the file Command.hpp and use it. Implement a class called Bi g int , objects of which represent arbitrary-large integers. In the private section of the class declare the following two data members: 1 bool m_is_negative ; 2 s td : : l i s t m_digits ; The former indicates whether the number is negative and the latter stores the sequence of decimal digits that comprise the absolute value of the number. Implement the following member functions: 1 bool i s_z e ro ( ) const ; 2 bool i s_ne g a t ive ( ) const ; Also, implement the free (global) functions whose declarations appear below and place their implementations in the file Bigint.cpp together with other private member functions you find useful if any. 1 Bi g int operator+(const Bi g int& a , const Bi g int& b ) ; 2 Bi g int operator(const Bi g int& a , const Bi g int& b ) ; 3 Bi g int operator ( const Bi g int& a , const Bi g int& b ) ; 4 5 s td : : ostream& operator<<(s td : : ostream& out , const Bi g int& b ) ; 6 s td : : i s t r eam& operator>>(s td : : i s t r eam& in , Bi g int& b ) ; The definition of the importer is listed bellow (to get you started). Notice that it throws an exception when the input is invalid. Insert t ry- cat ch blocks in the main ( ) function to handle exceptions thrown by the exporter. 1 s td : : i s t r eam& operator>>(s td : : i s t r eam& in , Bi g int& i ) { 2 char c ; 3 in . ge t ( c ) ; 4 i f ( c == ) i . m_is_negative = true ; 5 el se { 6 i f ( ! s td : : i s d i g i t ( c ) ) throw s td : : runt ime_er ror ( " I n v a l i d input " ) ; 7 i . m_digits . emplace_f ront ( c 0 ) ; 8 } 9 while ( in . ge t ( c ) && ( c != 0xa ) ) { 10 i f ( ! s td : : i s d i g i t ( c ) ) throw s td : : runt ime_er ror ( " I n v a l i d input " ) ; 11 i . m_digits . emplace_f ront ( c 0 ) ; 12 } 13 return in ; 14 }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!