Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

In C++ please:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Description 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,0, 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 - : multiplication (remember to quote it) - /: integer division - a: distance from 45 (see below) After that is a mandatory sequence of at least one integer, of the form: - Oxdigits: a hexadecimal integer, containing digits 0123456789 abcdef. - Obdigits: a binary integer, containing digits 01 . - Odigits: an octal integer, containing digits 01234567. - digits: (not matching any of the above patterns) 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. ./hw2 / 1000525 will calculate the result of 1000/5/2/25, or 4 . The result is displayed in the base indicated by the optional first argument. Quotng 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 a 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 runs, where % is my prompt. %./hw2+22%./hw2d+1234515%./hw2-d-1234513%./hw2-h-11710%./hw2-h-100ob1010x1901737%./hw2-o/13007./hw2-o/713%./hw2*21231246%./hw2a30702970%./hw2-0b1001 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. - Creativity is a wonderful thing, but your output format is not the place for it. Your non-error output should look exactly like the output shown above. You have more leeway in error cases. - UPPERCASE/lowercase matters. - Spaces matter. - Blank lines matter. - Extra output matters. - You may not use C-style I/O facilities, such as printf( ),scanf(), fopen ( ), and getchar ( ). - Instead, use C++ facilities such as cout, cerr, and ifstream. - You may not use dynamic memory via new, delete, malloc(),calloc(),realloc(), free (), strdup (), etc. - It's ok to implicitly use dynamic memory via containers such as string or vector. - You may not use the istream: : eof () method. - No global variables. - Except for an optional single global string containing argv [0]. - For readability, don't use ASCll int constants (65) instead of char constants ('A') for printable characters. - We will compile your program like this: cmake . \&\& make - If that generates warnings, you will lose a point. - If that generates errors, you will lose all points. - There is no automated testing/pre-grading/re-grading. - Test your code yourself. It's your job. - Even if you only change it a little bit. - Even if all you do is add a comment. If you have any questions about the requirements, ask. In the real world, your programming tasks will almost always be vague and incompletely specified. Same here. Tar file - For each assignment this semester, you will create a tar file, and turn it in. - The tar file for this assignment must be called: hw2 . tar - It must contain

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

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

3. Test complex thinking, not just skills and factual knowledge.

Answered: 1 week ago

Question

What is the role of the Joint Commission in health care?

Answered: 1 week ago