Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Ex. 1 A Simple Interger Calculator (9 Points) In this exercise, you will create a C program to implement a simple integer calculator. Your calculator
Ex. 1 A Simple Interger Calculator (9 Points) In this exercise, you will create a C program to implement a simple integer calculator. Your calculator should accept three arguments as input, x, op, y, where x and y are integers and op is one of the operators +, -, *, / to perform the corresponding arithmetic operations. 1.Use vi to create a C program source file simplecalc.c. 2.(1 Point) The program should include a comment section at the beginning that describes its purpose (couple of lines), the author (your name), your department, a small history section indicating what changes you did on what date. /* Program to implement a simple calculator *************************************************************** * Author Dept. Date Notes *************************************************************** * Joseph D Comp. Science. Feb 10 2020 Initial version. * Joseph D Comp. Science. Feb 11 2020 Added error handling. The code should be properly indented for readability as well as contain any additional comments required to understand the program logic. 3.(1 Point) The source code should be compilable by (exactly) using the command gcc -o simplecalc simplecalc 4.(3 Points) Your program should accept the three arguments mentioned above as its input. If the user does not pass this argument, you should display an error message and terminate with error code 1. $ ./simplecalc Error: usage is simplecalc $ echo $? 5.(4 Points) Your program performs simple arithmetic operations on the input as indicated by the operator and displays the output. You should use a switch statement to decide which operator to execute. You will loose 2 points if you do not use the switch. If the user enters one of the operators not listed above, print an error message and terminate with error code 2. Successfull execution of the program should result in a return code of 0 from the program. $ ./simplecalc 5 + 3 A NA O $ echo $? 0 $ ./simplecalc 5 - 3 2 $ ./simplecalc 5 * 3 15 $ ./simplecalc 5 / 3 1 $ ./simplecalc 5 @ 3 @ not a valid operator $ echo $
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started