Question: In C++ For this assignment, you will write a calculator program that that takes command-line arguments, performs simple arithmetic, and produces the result in the

In C++

In C++ For this assignment, you will write a calculator program that

For this assignment, you will write a calculator program that that takes command-line arguments, performs simple arithmetic, and produces the result in the base desired. Arguments The first, optional argument is one of h,o, or d, signifying an output base of hexadecimal, octal, or decimal. The default is decimal. After that is a mandatory operator, one of: i : addition o : subtraction o *: multiplication (remember to quote it) - f : integer division - (a: distance from 45 (see below) After that is a mandatory sequence of at least one integer, of the form: - Exdigits: a hexadecimal integer, containing digits 8123456789 abcde f. - boligits: a binary integer, containing digits 81. - Odigits: an octal integer, containing digits 81234567. - digits: (not matching any of the above pattems) a decimal integer, containing digits 0123456789. No more arguments should follow. Operation The operation is applied to all the numbers, left to-right. For example, . /hw2 +102030 will calculate the result of 10+20+30, or 60 . . / hwa / 16905225 will calculate the result of 1000/5/2/25, or 4 . The result is displayed in the base indicated by the optional first argument Quoting Unfortunately, the * character is special to bash, and will be replaced by a list of all the files in your current directory. To avoid this, type \* or '*' instead. Distance from 45 The e operator returns one of its operands, namely, the operand that is furthest from 45 . If the operands are equally distant from 45 , the smaller number is returned. Sample Runs Here are sample funs, where s is my prompt. Output in other bases: Observe: Requirements - Perform truncation in integer division using the / operator. - Use int for your calculations. The results of overflow, e.g., by multiplying or adding very large numbers, is undefined. - The result of entering an integer that's too large for an int, e.g., 0123456789, is undefined. - If you type a as an argument without quoting it, that's your problem. - Error messages: - go to standard error. - include the program name, no matter how it was compiled. - include the offending argument - Produce an error message and stop the program if: - not enough arguments are given - incorrect arguments are given - division by zero is attempted. - The output must end with a newline. - Newlines do not seporate lines-newlines torminate lines

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!