{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lab2 - Western Washington University Computer Science...

This preview shows pages 1–4. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CSCI 141 Computer Programming I – Lab Exercise 2 For this program you will need 5 variables: three integers, one character and one boolean. In this description I will use the names First , Second and Result for the integers, Operator for the character and Valid for the boolean, but you may choose whatever legal names you want. You need packages Ada.Text_IO and Ada.Integer_Text_IO for the input and output. Call your procedure calculator1 and save the file as calculator1.adb . 2. Here is the algorithm for calculator1, expressed in structured English . Set Valid to true Display the prompt “What do you want me to calculate? “ Get the first integer Get the operator Get the second integer If the operator is '+' Set the result to the first integer plus the second integer If the operator is '-' Set the result to the first integer minus the second integer If the operator is '*' or 'x' Set the result to the first integer multiplied by the second integer If the operator is '/' DB 9/30/11 Page 2 of 8
CSCI 141 Computer Programming I – Lab Exercise 2 Set the result to the first integer divided by the second integer If the operator is neither '+', '-', '*', 'x' nor '/' Display the message “Invalid operator “, followed by the operator and end the line Set Valid to false If Valid is true Display the first integer, space, the operator, space, the second integer, space, '=', space and then the result, all on one line and then end the line 3. Write the Ada procedure to implement this algorithm, compile it and test it.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

Lab2 - Western Washington University Computer Science...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online