Lab 10 - Arithmetic

Overview | Requirements | Compile | Example | Extra Credit | Turn In Work 

Overview

Given a simple mathematical expression on the command line, you should evaluate the expression and output the result to stdout

Your goal is to error check the input and to convert command line arguments in argv[ ] to floats and char as appropriate. Several techniques exist for converting strings to numerical data types: sscanf will allow format conversions similar to scanf, while atof and atoi convert strings to floating point type double and integer types respectively. The sscanf function works in a manner that is analogous to fscanf and supports the same set of format codes (%d, %f, %c, %s, etc). The only difference is that sscanf reads from a NULL terminated string that is already present in memory instead of a file.

.

Requirements

Your program should accept a mathematical expression in one of these forms

 float operator float            //ex: calc 5.3 + 2.0 or calc 5 + 2.0
int operator int                //ex: calc 5 + 2
intOperator                     //ex: calc 5!

on the command line.

Compilation Instructions

Name your program calc.c. You can compile your program with: Eclipse.

Example Usage

Your program should work as the sample below:
 

>calc 5 + 4
9
>calc 5 + 4.0
9.0
>calc 5.9 - 0.3
5.6
>calc 4 / 2
2
>calc 5 x 4
20
>calc 5!
120
>calc 5 % 3
2

Extra Credit

You can receive a maximum of 3 points extra credit, just by making all six operations work, including error reporting for ill formed problems only if your work in turned in on time.

Turn In Work

After you have completed the arithmitic program and have an output similar to the example usage, please submit your work via UNCW webmail by following these simple steps.

  1. calc.c source code attachment
  2. copy and paste this subject line: CSC 112 Lab 10 calc.c

Confirmations: A student can then be assured that their assignment has been submitted based on the return email which is sent only if the above requirements are met. The student should not delete the confirmation email.  Any work submitted after 11:59 PM on Friday November 14th will be late.