Lab2 - Western Washington University Computer Science...

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

View Full Document Right Arrow Icon
Western Washington University Computer Science Department CSCI 141 Computer Programming I Fall 2011 Laboratory Exercise 2 Objectives 1. Practice in use of the procedures from packages Ada.Text_IO and Ada.Integer_Text_IO. 2. Practice in use of selection and interaction constructs of the Ada language. 3. Practice in producing zipped tar files in Linux. Submitting Your Work In this lab exercise you will create 2 or 3 Ada programs. At the end of the lab exercise you will find instructions on how to put those files into a single zipped (compressed) tar (tape archive) file. Save your program files as the zipped tar file Wnnnnnnnn.tar.gz (where Wnnnnnnnn is your WWU W-number) and submit the file via the Lab Exercise 2 Submission item on the course web site. You must submit your file by 4:00pm on Friday, October 7. The Exercise In this lab exercise, you will develop a calculator in the Ada language. You will develop 2 or 3 versions of the calculator, making each version more tolerant of user errors and more versatile than the previous version. This lab exercise is to be completed in the Linux operating system. If your computer is currently running Windows, restart it in Ubuntu Linux. Calculator 1 1. The first version of the calculator will accept as input from the user an integer number, an operator and another integer number and will then display the result. The valid operators are '+' for addition, '-' for subtraction, 'x' or '*' for multiplication and '/' for integer division. A working calculator is shown in the screen capture below. DB 9/30/11 Page 1 of 8
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/03/2011 for the course CSCI 141 taught by Professor Ural during the Fall '08 term at Western Washington.

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 Right Arrow Icon
Ask a homework question - tutors are online