UNIVERSITY OF PITTSBURGH
School of Information Sciences
INFSCI 0015 - Data Structures and Programming Techniques
(Spring 1999, CRN 42232)
Homework #6:
Counting Sold Items
Reading Assignment
Please read Chapter 10, "Arrays", from Koffman's Pascal book.
Exercise 6.1 (8 Points)
Write a program for a shop to compute statistics at the end of each day.
The shop sells 20 different items.
In the morning,
the cashier starts your program.
Whenever an item is sold,
the cashier enters the item number (between 1 and 20)
into the program.
You do not have to handle the case that the item is sold
in a quantity greater than 1.
If the item is sold three times,
the cashier enters its item number three times.
In the evening,
the cashier enters the number 0.
Then the program should print for each item
how often it was sold in that day (and terminate).
You should print only items sold at least once.
So the output should look as follows:
Item Nr. 1: Sold: 3
Item Nr. 2: Sold: 1
Item Nr. 5: Sold: 7
In order to solve this problem,
you might want to declare an array "sold[1..20] of integer".
In the variable sold[i] you count how often
item number i was sold.
- You first need a loop to initialize all 20 counters to zero.
- Then you need a loop over the input values (integers).
This loop should stop as soon as you read the input value 0.
- Finally,
you need a loop to print the resulting statistics.
Note that you must suppress output for item number
i
if sold[i] is zero.
Due Date:
Please submit your solution on Thursday, February 18,
before the lecture.
Stefan Brass
(sbrass@sis.pitt.edu),
February 11, 1999
Original URL:
http://www2.sis.pitt.edu/~sbrass/ds/h6.html
[HTML 3.2 Checked]