Simple Arithmetic Calculator - Introduction to Programming - Assignment | COMP 110, Assignments of Computer Science

Material Type: Assignment; Professor: Stotts; Class: Introduction to Programming; Subject: COMPUTER SCIENCE; University: University of North Carolina - Chapel Hill; Term: Fall 2008;

Typology: Assignments

Pre 2010

Uploaded on 03/11/2009

koofers-user-cmx
koofers-user-cmx 🇺🇸

8 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COMP 110
Fall 2008
Assignment 3: Simple Arithmetic Calculator
Due: Mon. Sept 22 at 12:00 midnight
For this assignment you will create a web page with an embedded JavaScript program.
You will store this program as an HTML file in your UNC web space, and you will give
it an 8-character or more filename that only you know. Then we can retrieve, run, and
grade it by pointing our browser www.unc.edu/~ yourOnyen/yourSecretName.html but no
one else can see it without making a really good guess at what you named it.
This program will exercise the concepts you have been learning to date. It will require
you to write a loop, use conditional (if) statements, do input via prompt, do output via
alert, create named constants, produce arithmetic expressions, do assignment to variables.
Specs
Use a simple text editor to create this program. Do not use Web generation tools.
You are to write a program that will act like a simple 5-function calculator. The user is
able to get 5 different kinds of arithmetic operations: addition, subtraction, multiplication,
division, and square roots. When the program first runs, it will ask the user to enter a
number 0 to 5. Then it will perform the operation corresponding to that input value
based on this table:
0. end the program
1. do addition
2. do subtraction
3. do multiplication
4. do division
5. do square root
So, for example, if the user gives the number 2, your program will do a subtraction. To
accomplish this, the program will ask the user for two more numbers; it will then perform
the appropriate arithmetic operation on that number and then report the results to the user.
Make your output read nicely, and make sure it explains the activity. For example, if the
user asks to multiply, and gives the numbers “5” and “2.3” don’t write “11.5”…instead
print “5 times 2.3 is 11.5”
Once the requested operation is done, the program will loop back and ask for another
operation selection. Do this looping/computing until the user enters the flag value “0”,
at which time the entire program will end. Note that if the user selects operation 5
(square root) the program only needs to ask for 1 additional number.
For input, use the “prompt” statement, and for output use the “alert” statement.
pf3

Partial preview of the text

Download Simple Arithmetic Calculator - Introduction to Programming - Assignment | COMP 110 and more Assignments Computer Science in PDF only on Docsity!

COMP 110

Fall 2008

Assignment 3: Simple Arithmetic Calculator

Due: Mon. Sept 22 at 12:00 midnight For this assignment you will create a web page with an embedded JavaScript program. You will store this program as an HTML file in your UNC web space, and you will give it an 8-character or more filename that only you know. Then we can retrieve, run, and grade it by pointing our browser www.unc.edu/~ yourOnyen/yourSecretName.html but no one else can see it without making a really good guess at what you named it. This program will exercise the concepts you have been learning to date. It will require you to write a loop, use conditional (if) statements, do input via prompt, do output via alert, create named constants, produce arithmetic expressions, do assignment to variables.

Specs

Use a simple text editor to create this program. Do not use Web generation tools. You are to write a program that will act like a simple 5-function calculator. The user is able to get 5 different kinds of arithmetic operations: addition, subtraction, multiplication, division, and square roots. When the program first runs, it will ask the user to enter a number 0 to 5. Then it will perform the operation corresponding to that input value based on this table:

  1. end the program
  2. do addition
  3. do subtraction
  4. do multiplication
  5. do division
  6. do square root So, for example, if the user gives the number 2, your program will do a subtraction. To accomplish this, the program will ask the user for two more numbers; it will then perform the appropriate arithmetic operation on that number and then report the results to the user. Make your output read nicely, and make sure it explains the activity. For example, if the user asks to multiply, and gives the numbers “5” and “2.3” don’t write “11.5”…instead print “5 times 2.3 is 11.5” Once the requested operation is done, the program will loop back and ask for another operation selection. Do this looping/computing until the user enters the flag value “0”, at which time the entire program will end. Note that if the user selects operation 5 (square root) the program only needs to ask for 1 additional number. For input, use the “prompt” statement, and for output use the “alert” statement.

Bones of the Algorithm

This assignment will require you to use a loop, conditional statements (if then else), input (prompt), output (alert), assignment statements, and arithmetic expressions. Here is a basic “algorithm” (recipe for the computation): // declare the variables you need // make a main loop // first get input item (prompt), tells what operation to do // if this item is 0, you are done // if this item is not 0, then do a single operation: // get more input (prompt)… get the numbers to use // apply the proper arithmetic to the number(s) // print the result (alert) // end of main loop… (do it again) // print a message saying its all done

Construction Strategy

Use the basic HTML file structure we developed in class for the program. This is one with the