Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will write a program that mimicks a simple calculator that can do adding, multiplication, or modulo of 2 integers. The program takes 3 arguments

image text in transcribedimage text in transcribed

You will write a program that mimicks a simple calculator that can do adding, multiplication, or modulo of 2 integers. The program takes 3 arguments at the command line: an integer, a character, and another integer. The character can be one of only 3 types:"+, X, or %. The program then returns either the sum, the product, or the modulo of the 2 integers. The program should be able to verify that 1) the user has exactly 3 arguments. 2) the operator used is one of the 3 allowed operators and nothing else. 3) when using modulo, the second integer is not zero (otherwise, you would divide by zero). For each of these conditions, the program should print out a specific error message (called USAGE messages) and exit. For each condition, the error message should be: 1) Number of arguments is incorrect. 2) Bad operation choice. 3) Cannot divide by zero. Hint: you have to use cerr instead of cout to output the usage messages. Do not use cerr for any other outputs the program makes. While cerr and cout are alike in that they direct values to standard output, we usually use cout for the standard output, but use cerr to show or report errors to the user and the system You may use the exit(1) statement when exiting from giving some of the error messages. The instructor will demonstrate the proper use of exit(1) and cerr in class on Tuesday

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_2

Step: 3

blur-text-image_3

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

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

Timeline for final evaluation

Answered: 1 week ago

Question

1. Diagnose and solve a transfer of training problem.

Answered: 1 week ago