Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im needing help with a calculator program in C++ that that takes command-line arguments, performs simple arithmetic, and produces the result in the base desired.

Im needing help with a calculator program in C++ that that takes command-line arguments, performs simple arithmetic, and produces the result in the base desired.

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:

+: addition

-: subtraction

After that is a mandatory sequence of at least one integer, of the form:

0xdigits: a hexadecimal integer, containing digits 0123456789abcdef.

0bdigits: a binary integer, containing digits 01.

0digits: an octal integer, containing digits 01234567.

digits: (not matching any of the above patterns) a decimal integer, containing digits 0123456789.

Requirements

Perform truncation in integer division using the / operator.

Use int for 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., 0x123456789, is undefined.

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.

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions