Docsity

COMP 110 Spring 2007 Assignment 2: First Program - Conversions, Assignments of Computer Science

Toggle sidebar
bg1
COMP 110
Spring 2007
Assignment 2: First Program -- Conversions
Due: Mon. Feb 12 at 4:00 pm
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.
Specs
Use a simple text editor to create this program. Do not use Web generation tools.
You program will be somewhat similar to the conversion example we did in class. Your
program, however, will allow the user to select from 4 different conversions. When it
first runs, the program will ask the user to enter a number 0 to 4. Then it will perform
these conversions based on that input:
0. end the program
1. convert feet to meters
2. convert meters to yards
3. convert gallons to liters
4. convert pounds to kilograms
Once the requested conversion is done, the program will loop back and ask for another
conversion selection. Do this looping until the user enters the flag value “0”, at which
time the entire program will end. Note that after asking for this selection, to do the actual
conversion your program will be requesting more input from the user.
For any one requested conversion, perform the appropriate arithmetic and then report the
results to the user with the “alert” feature in JavaScript. Make your output read nicely,
and make sure it explains the conversion. For example, if the user asks to convert 15 feet
into meters, don’t print “4.572”… instead print “15 feet is 4.572 meters”
For input, use the “prompt” statement, and for output use the “alert” statement.
Bones of the Algorithm
This assignment will require to use a loop, conditional statements (if then else), input
(prompt), output (alert), assignment statements, and constants.
pf2

Partial preview of the text

Download COMP 110 Spring 2007 Assignment 2: First Program - Conversions and more Assignments Computer Science in PDF only on Docsity!

COMP 110

Spring 2007

Assignment 2: First Program -- Conversions

Due: Mon. Feb 12 at 4:00 pm 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.

Specs

Use a simple text editor to create this program. Do not use Web generation tools. You program will be somewhat similar to the conversion example we did in class. Your program, however, will allow the user to select from 4 different conversions. When it first runs, the program will ask the user to enter a number 0 to 4. Then it will perform these conversions based on that input:

  1. end the program
  2. convert feet to meters
  3. convert meters to yards
  4. convert gallons to liters
  5. convert pounds to kilograms Once the requested conversion is done, the program will loop back and ask for another conversion selection. Do this looping until the user enters the flag value “0”, at which time the entire program will end. Note that after asking for this selection, to do the actual conversion your program will be requesting more input from the user. For any one requested conversion, perform the appropriate arithmetic and then report the results to the user with the “alert” feature in JavaScript. Make your output read nicely, and make sure it explains the conversion. For example, if the user asks to convert 15 feet into meters, don’t print “4.572”… instead print “15 feet is 4.572 meters” For input, use the “prompt” statement, and for output use the “alert” statement.

Bones of the Algorithm

This assignment will require to use a loop, conditional statements (if then else), input (prompt), output (alert), assignment statements, and constants.

Here is a basic “algorithm” (recipe for the computation): // define conversion constants // declare the variables you need // make a main loop // first get input item (prompt), tells what conversion to do // if this item is 0, stop // if this item is not 0, then we need to do the work // get more input (prompt)… get the number to convert // apply the proper conversion factor to the number // print the result (alert) // end of loop

Turn in

A paper copy of your HTML/JavaScript file, due at the Sitterson front desk by 4:00pm on Sept. 18. Paper should be 8 ½ by 11 inches, stapled and not folded. Be sure your ONYEN and your secret filename are clearly written at the top of the paper. A stapler will be available at the front desk. If you turn in something larger than this, I reserve the right to trim it to 8 ½ by 11 and grade what’s left. You should also have the electronic copy in place by then. We will check for your pages that afternoon.

Header:

**Put this header at the TOP of your HTML file. We must have a standard format and location in order to sort out this large class.