CSCI 150, Spring 2003
Home | | Course Schedule | | Assignments | | Lecture NotesDue 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
Specifications for Documentation and Format.
Specifications for Output.
Sample Run 2:
To Submit Your Finished Project:
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!
Place all your code in a file named <username>_price.pas,
where
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;
Fully correct documentation for Project
1 must include:
Directly below, you can see an example of the display that
will appear on the monitor screen for several sample runs of the program.
Sample Run 1:
How much would you like to spend?
The following items can be bought for $2.00:
2
Item: Candy bar, Price: $0.75
Item: Soap, Price: $1.15
Item: Pencils, Price: $1.40
Item: Lollipop, Price: $0.50
Item: Glue Stick, Price: $1.35
How much would you like to spend?
The following items can be bought for $3.50:
3.50
Item: Toothpaste, Price: $2.75
Item: Candy bar, Price: $0.75
Item: Soap, Price: $1.15
Item: Shampoo, Price: $3.15
Item: Pencils, Price: $1.40
Item: Lollipop, Price: $0.50
Item: Glue Stick, Price: $1.35
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.