CSCI 150, Spring 2003

Home | | Course Schedule | | Assignments | | Lecture Notes

CSCI 150 Homework 4

How Much Can You Buy for a Dollar?

Due Friday, February 28, at the beginning of class.

Introduction
In this assignment, you will write a program to aid a consumer who wishes to know which items for sale are within his or her price range. The customer can type in the amount he or she wishes to spend and the program will print out the name and price of each item with a price that is less than or equal to that amount. The goal of this assignment is to gain familiarity with "for loops" and arrays in pascal.

Program Description
The program will begin by initialing two arrays. One array, named item, will contain strings that are the descriptions of the items for sale. The second array, named price, will contain real numbers that are the prices of those items. The arrays will be set up so that the price of the first element in the item array will be the first element of the price array. In other words, the price of item[1] will be price[1], the price of item[2] will be price[2] and so on.

Once these arrays have been initialized, which you can do by copying and pasting the code given below, the program should prompt the user for an amount that they wish to spend. Once the user has entered the amount, the program will print out the name and price of each item whose price is less than or equal to that amount.

Project Specifications
Place all your code in a file named <username>_price.pas, where refers to your own username. For example, Professor Royden's file would be named croyden_price.pas.

  1. Declare variables for the two arrays and the amount the user wishes to spend.
  2. Initialize the arrays with the items and prices given below.
  3. Prompt the user to enter the amount he or she wishes to spend and read it in.
  4. Based on the amount, the computer should list the name and price of every item whose price is less than or equal to the amount entered by the user.
  5. Write your code to assure that the text that appears on the monitor looks like that displayed in the section below called Specifications for Output.
You may copy and paste the following pascal code to set up your arrays with prices and items:
	item[1] := 'Toothpaste';
	price[1] := 2.75;
	item[2] := 'Batteries';
	price[2] := 7.25;
	item[3] := 'Picture Frame';
	price[3] := 8.37;
	item[4] := 'Hair brush';
	price[4] := 12.95;
	item[5] := 'Candy bar';
	price[5] := 0.75;
	item[6] := 'Gift Wrap';
	price[6] := 5.00;
	item[7] := 'Soap';
	price[7] := 1.15;
	item[8] := 'Video';
	price[8] := 14.95;
	item[9] := 'Shampoo';
	price[9] := 3.15;
	item[10] := 'Pencils';
	price[10] := 1.40;
	item[11] := 'Film Pack';
	price[11] := 6.10;
	item[12] := 'Vitamins';
	price[12] := 13.60;
	item[13] := 'Lollipop';
	price[13] := 0.50;
	item[14] := 'Glue Stick';
	price[14] := 1.35;
	item[15] := 'Calendar';
	price[15] := 3.75;

Specifications for Documentation and Format.
Fully correct documentation for Project 1 must include:

Specifications for Output.
Directly below, you can see an example of the display that will appear on the monitor screen for several sample runs of the program.

To Submit Your Finished Project:
1. Hand in a hard copy of the file <username>_price.pas. Hand this to your instructor in class on the project's due date.

3. Hand in a printout of 2 sample runs like those shown above. Hand this to your instructor in class on the project's due date.

4. Print your name at the top of the cover page and staple it to the top of your hard copy.

5. In addition to the hard copy listed above, email your <username>_price.pas file to me at croyden@mathcs.holycross.edu

Get started early and have fun!