UMBC CMSC 104 * CSEE | 104 | current 104

CS 104 Fall 1998 Project 3

CMSC 104 -- Sections 103 and 301 -- Fall 1998
Project 3 - A calculator

  1. Purpose
  2. This project will introduce you to nested control structures (while and switch) which are required to implement a user menu and to introduce you to C functions and the C math library.

  3. The project specifics
  4. In this project, you will implement a rudimentary calculator. This calculator will get input from the user and perform the requested mathematical operation. Your program will support the following operations:

    Project 3 Operations
    User InputOperation
    +
    Addition
    -
    Subtraction
    *
    Multiplication
    /
    Division
    ^
    Exponentiation
    R or r
    Square Root
    V or v
    Absolute Value
    C or c
    Clear value
    E or e
    Exit

    Your program will NOT support operator precedence.
    You should initialize the value of the expression to 0.
    Operations will be performed in the order they are entered. After each operation is performed, the current value of the expression will be displayed (show 2 decimal places). Your program should prompt the user for input as needed. Command input should be validated. When an invalid command is entered, an error message should be display that includes the invalid command character and the user asked for another input.

    You will write a C function for each operation. That function will take the the current value of the expression as a parameter, prompt for additional input (if needed), perform the operation and return the new value of the expression to the caller. The function should also print a message indicating the operation being performed and the value of the operands. For example, the addition function might print: Adding 6 to 19. The square root, absolute value and exponentation operations will be performed by using the appropriate math library func tion.

  5. Compiling your program
  6. In order to use the functions found in the math library, you must define them in your program and included them when you compile. To include their prototypes in your program, use #include <math.h>.
    To include the actual functions in your program, type the following at the end of you command line when compiling: -lm.

  7. Submitting your project
  8. Once you have coded and tested your program with user input, you will start the Unix script feature and run the following commands (assuming your Unix prompt is %)
    
    % script
    % cc project3.c -lm
    % a.out < /afs/umbc.edu/users/d/e/dennis/pub/cs104/proj3/proj3.dat
    % exit
    % mv typescript project3.out
    
    If you are in section 103, submit your project with the command
    	% submit cs104-103 proj3 project3.c project3.out
    
    If you are in section 301, submit your project with the command
    	% submit cs104-301 proj3 project3.c project3.out
    
    

  9. Sample Output
  10. Some sample output follows. This output does NOT show all required operations.
    retriever[102] a.out
    starting total is 0.00
    
    Input operation: +
    Input value: 10
    adding 10.00 to 0.00
    subtotal = 10.00
    
    Input operation: -
    Input value: 3
    subtracting  3.00 from 10.00
    subtotal = 7.00
    
    Input operation: /
    Input value: 2
    dividing 7.00 by 2.00
    subtotal = 3.50
    
    Input operation: *
    Input value: 5
    multiplying 3.50 by 5.00
    subtotal = 17.50
    
    Input operation: k
    invalid command: k
    subtotal = 17.50
    
    Input operation: E
    Exiting
    subtotal = 17.50
    
    total is 17.50
    
    retriever[103]
    
    

  11. Project Grading
  12. Project 3 is worth 100 points. Correct implementation of each operation will be worth 10 points each (total of 80 points). Correct error handling will be worth 5 points. The other 15 points will encompass design, coding style and documentation.

UMBC CS 104
UMBC CMSC 104 * CSEE | 104 | current 104