The contract grading system requirements for this assignment set are:
C REQUIREMENTS
Complete any one program on the computer and any other nine activities.
B REQUIREMENTS
Complete 3 B Level Activities and an A Level Activity. Also, complete any one
program from Items A through E, J, K, L, or M. You must complete a total of ten
activities.
A REQUIREMENTS
Complete one A Level Activity and any four B Level Activities. Also, complete any one program from Items H through M or Items Q through R. You must complete a total of ten items.
Bonus:
If you hand this assignment in ON TIME, you get one letter grade higher than indicated above. You can get an A+ by meeting the A requirements, which is averaged one letter grade higher than an A.
You also get four activities.
If you hand this assignment in SLIGHTLY LATE, you get four activity bonus. However, you don't get the one letter-grade bonus.
The dates for ON TIME and SLIGHTLY LATE will be announced in class when we discuss a few problems.
In this assignment set, the conventional grading system requires that you do Item E and R on the computer.
ITEM A. B Level Activity
Read in two numbers from the keyboard. Call them A and B. You may assume that A < B.
Read in a list of lists of numbers from the file MAXRANGE.IN
Each list ends with a -1.
The number at the end of the file will be 100.
Determine which list has the most numbers that are between the values of A and B.
Print out the count of such values for the list having the most values.
Be sure to ignore in the count, the -1 and 100 used to indicate the end of each list and the entire data file, respectively.
For example, suppose A and B were 4 and 15 and MAXRANGE.IN was
'1 7 13 2 19 -1<
+ 8 11 14 -1<
+ 2 3 -1<
+ 100' where '<
+' represents the end-of-line character.
The answer would be 3; the second list contained 8, 11, and 14; all of which were between 4 and 15. (The first list only had two such numbers, 7, and 13. and the third list had no such numbers).
ITEM B. Counts as 2 B Level ActivitiesYou are to read in numbers representing the closing dowjones index for successive trading days of the New York Stock Exchange. A bull market is defined as a series of consecutive days where the closing market increased. A bear market is defined is where the index went down each day.
This input can be found in DOW.IN and the last number will be followed by a sentinel of zero.
You are to print out for each bull market, the word BULL, the total number of days and the total increase. You should do similarly for each bear market.
At the end, you should print out the longest BULLmarket, the longest BEAR market, the largest BULL market in terms of increase and the largest BEAR market in terms of decrease.
This should go in BEARBULL.OUT
For example, if DOW.IN contained:
4000
4005
4200
4199
4198
4197
4196
4195
4196
4197
4198
4199
4200
4202
4100
4000
0
the output BULLBEAR.OUT should be
BULL 3 200
BEAR 6 5
BULL 6 7
BEAR 3 202
LONGEST BULL -- 6
LARGEST INCREASE IN BULL 200
LONGEST BEAR -- 6
LARGEST DECREASE IN BULL 7
The first line represents the increase from 4000 to 4200 in three days.
The next line represents the drop from 4200 to 4195 in 6 days.
The third line represents the increase from 4195 to 4202 in 6 days. The last line
represents the drop from 4202 to 4000 in only three days.
ITEM C. Level B homework assignment
Read in a list of pairs of X and Y values from PAIRS.XY, the input file. They will be arranged in ascending order of X values. They represent a graph of Y versus X. Use real numbers as the values might not be integers.
The pair of numbers will be (0, 0) and will not count in the final response.
Determine the smallest peak and the highest trough. A peak would be a local maximum (in calculus terminology) and a trough is a local minimum. Print out the X and Y coordinates for the smallest peak and the highest trough (clearly labeled).
Don't count the first or last values of Y as peaks or troughs.
Suppose pairs.xy contains '1 3<
+ 4 5<
+
5 3<
+ 6 2<
+ 7 4<
+
8 1<
+ 9 3<
+ 0 0' where '<
+' represents the end-of-line marker.
The peaks would be at (4,5) and (7,4).
The smallest peak would be at (4,5)
The troughs would be at (6,2) and (8,1).
The highest trough is (6,2).
The answers output should be (4,5) and (6,2).
ITEM D. Level B homework assignment
Read in the value for N and A from the screen. Compute and print the following sum.
See Unit 4.15 which may or may not be covered in class.
SUM FROM {i=1} TO n {[ PI FROM {j=i} TO {j=i+A} {( i+1 )} PI FROM {j=2*i} TO
{j=2*i+A} { [ SUM FROM {k=j} TO {k=j+A+i} ijk] ] }}
(1)(Use real numbers or longint (a type of integer) so as to avoid overflows)
ITEM E. Level B homework assignment
Read in a set of four-tuples from the file TUPLE.4 (a four-tuple is a ordered list of four numbers). The end of the four-tuples is indicated '0 0 0 0'.
The first three numbers in each set corresponds to the values A, B, C in the recurrence
series:
X sub i = A X sub {i-1} + B X sub {i-2} + C X sub {i - 3}
(2)The fourth number corresponds to the integer N.
For each four-tuple, compute the nth number in the indicated recurrence series. Then print it out.
At the end of the data print out the largest number indicated.
Suppose TUPLE.4 contains '2 3 4 6<
+ 1 1 0 7<
+ 0 0 0 0' where '<
+' represents the end-of-file marker.
The first tuple (with A, B, and C equal to 2, 3, and 4) would result in the following calculations:
X4 = A * 1 + B * 1 + C * 1 = 2 + 3 + 4 = 9
X5 = A * 9 + B * 1 + C * 1 = 2 * 9 + 3 * 1 + 4 * 1 = 25
X6 = A * 25 + B * 9 + C * 1 = 2 * 25 + 3 * 9 + 4 * 1 = 81
The second tuple (with A, B, and C equal to 1, 1, and 0) would result in the calculations:
X4 = 1 * 1 + 1 * 1 + 0 * 1 = 2
X5 = 1 * 2 + 1 * 1 + 0 * 1 = 3
X6 = 1 * 3 + 1 * 2 + 0 * 1 = 5
X7 = 1 * 5 + 1 * 3 + 0 * 2 = 8
(Note that these numbers are essentially a Fibonnacci series)
Your program would print out '81 8 81'
Hint: Look at section 4.11 which I may or may not have time to cover in class.
ITEM F. Level A homework assignment
You are to write a program that will transfer the files in a hard disk or network subdirectory to diskettes. The files on the diskette are to be in regular MS-DOS format. You may need more than one diskette. You may assume that each file is in ASCII format, that each file will individually fit on a diskette, and there are no subdirectories within the directory.
After the program is completed, all the files will be removed from the original subdirectory and will be on in the diskettes.
Your program should prompt each time a new diskette is needed and should wait for the user to press a key prior to starting filling the new diskette. The program may assume that the user has pre-formatted the diskettes.
It can be proved mathematically that it is impossible to develop an algorithm to determine an assignment of files to the diskettes so as to minimize the number of diskettes used. (Actually, it is impossible to find such an algorithm that will run in a reasonable amount of computer time). The problem is said to be NP-complete. (You will learn more about this concept in a graduate algorithms course, a theoretical computer science course, or a computer security course.)
However, the following heuristic, although surprisingly simple, does an excellent job, and no better algorithm can be found. This problem is a case of the bin-packing problem, one that is much studied in computer science. Variations of it show up in such areas as determining the logistics of loading up air freight and cutting patterns out of sheet metal.
Algorithm:
prompt the user to enter the first diskette
while there are files in the directory on the hard disk
for each file on the hard disk directory
see if there is room for the file on the diskette
if there is
copy the file to the diskette
remove the file from the hard drive
endif
end;
if there are still files in the directory on the hard disk
prompt user to remove the existing diskette and insert new
diskette in drive
end;
Read up on FindFirst, FindNext, Erase, and DiskFree in the Turbo Pascal 6.0 Library Reference Manual.
The copying can be done by a loop that reads each line or character and transfers it or it can be done using the Exec procedure, also defined in the Turbo Pascal 6.0 Library Reference Manual and Chapter 11 of the Turbo Pascal 6.0 Programmer's Guide. (Those using Exec will need to free up memory using the {$m} compiler directive discussed in the Turbo Pascal 6.0 Programmer's Guide.)
Note: if you use Exec, you should use COMMAND.COM's full path in the string passed to Exec.
There will be a modification of this program in Assignment Seven--so hold on to your code.
ITEM G. C Level ActivityWrite a program that would read in a list of numbers from a file called input1.text. Print out the minimum number between the first positive value and the next positive value that is less than four in the file. Let the sentinel be -1.
For example, if one would have the following data in input1.text:
-2
6
5
7
3
1
4
-1
The program should report the minimum number to be 5 since five is the smallest number between the first positive value, 6 in this case, and the next positive value that is less than four, 3 in this case, of the file input1.text. Note that 3 is the first positive value that is less than 4 and hence we stop at 3 and not at 1. Hence, we exclude 1.
ITEM H. C Level ActivityYou need to write a program that would read in the data from a file called input2.text. Print out the maximum number between the first negative value and the next positive value that is less than 3 in input2.text. Let -1 be the sentinel.
For example, if one were to have the following data in the input2.text:
7
-4
5
4
2
-1
The program should report the maximum number to be 5 since five is the largest number between the first negative number, -4 in this case, and the next positive value that is less than 3, 2 in this case, in input2.text.
ITEM I. C Level Activity
This program is supposed to read in a list of numbers from a file called input3.text. Then, it should print out the average value between the first negative value and the next value that is greater than 7 in the file input3.text. Let -1 be the sentinel.
For example, if we were to have the following data in
input3.txt:
3
-2
6
4
2
8
-1
The program should print out 6 since the values between the first negative value, -2 in this case, and the next value that is greater than 7 is 8, in this case, are 6, 4 and 2. The average of the three numbers is 6. Hence, the program should print out 6.
ITEM J. C Level Activity
You need to write a program that will read in a bunch of numbers from a file called input4.text. It needs to compute the sum of all the numbers between the first 5 and the first 10 that follows the 5. Let -1 be the sentinel.
Say for example, we were to have the following numbers in
input4.text:
3
4
5
6
7
8
9
10
2
11
-1
The program should print out 30 since there is 6, 7, 8 and 9 between the first 5 and 10. Please note that 2 and 11 are not included in the sum.
ITEM K.
(B-level special)
Note: this is similar to a problem from the previous assignment set.
You are to read from three files data about pools for sale at the Mid-Illinois Spa &
Pool Company. There are three files to contain this information. They are
names.in, prices.in and
capacity.in. They contain the name of the pools, their prices
and the capacity in gallons. They are in matching order. That is, the first line of
names.in will be the name of the first pool. The first number in
prices.in will be the price for that pool. The first number in
capacity.in will be the capacity of the first pool. Likewise, the
second line of names.in, the second number in
prices.in and the second number
capacity.in all correspond to the same pool, etc.
There will be one entry in names.in that won't have corresponding entries in prices.in and capacity.in. This will be at the end, and will be the name stop.
You are to report the following information for the set of pools:
1) the name of the least expensive pool (and it's price)
2) the name of the largest pool (and it's capacity in gallons)
3) the best value for pools, its price and capacity.
The valueof the pool is measured by dividing the capacity by the cost.
Example, if the files contained the following:
names.in
Lamoine River Special
Great Lake Special
Olymptic Special
stop
prices.in
1000
10000
5000
capacity.in
2000
30000
7500
Least Expensive Pool: Lamoine River Special,
$2000
Largest Pool: Great Lake Special, 30000 gallons
Best Value: Olympic Special, $7500,
Capacity 5000 gallons
Note that the values for the pools above are $2.00 per gallon, $3.00 per gallon and $1.50 per gallon. Thus Olympic Special has best value.
ITEM L.
(A-level problem)
You are to read in from rect1.in data about one rectangle. Then
you should read in data about other rectangles from the file rects.in.
Each rectangle's data consists of four numbers. These are the x and y
coordinate for the lower left hand corner and the width and height.
To indicate the end of the rectangle data in rects.in, you will find four zeros.
You are to draw the single rectangle in rect1.in in a white outline on the graphics screen.
Each rectangle in rects.in should be drawn in solid color as follows:
If the rects.in rectangle intersects the first, it will be drawn in yellow. If it is inside the first rectangle, draw it in green. Otherwise, draw it in red.
Ms. Tabrizi, set up example and figure for this problem.
ITEM M.
(B-level problem)
The file triple.in contains sets of three numbers. This is followed
by a single -1
that will indicate the end of data.
You are to create three files:
firsts.dat which will be the first number of each triple
seconds.dat which will contain the second number of each
triple
thirds.dat which will contain the third number of each triple
Example, if
triple.in
contained:
1 2 3
7 100 3
5 95 8
-1
firsts.dat would contain
1
7
5
seconds.dat would contain:
2
100
95
thirds.dat would contain:
3
3
8
ITEM N.
(B-level problem )
This problem is based on Assignment Set 5A Supplementary Template
You are to read in data describing temperature data from the file temper.in. It has one average value for each day. The end of the numbers is indicated by a -1.
Winter is defined as the period when the temperature first termperature gets below 20 degrees to the time it next rises to above 50 degrees.
Count how many winter days there are in the sequence of readings.
Example, if the input were:
70 60 50 40 30 21 19 23 35 15 45 52 35 70 60 50 41 32 55 19 17 32 35 45 60 -1
The answer would reflect the following days in the first winter.
19 23 35 15 45
and the second winter:
19 17 32 35 45
Thus the answer would be ten.
ITEM O.
(B-level problem )
This problem is based on Assignment Set 5A Supplementary Template
You are to read in data describing temperature data from the file summer.in. It has one average value for each day. The end of the numbers is indicated by a -1.
Summer is defined as the period when the termperature first gets above 70 degrees to the time when the termperature falls below 65 degrees.
Determine the average temperature for all the summer days.
Example, if the input summer.in cntained:
20 30 40 50 60 72 67 75 80 70 65 61 40 30 20 40 50 68 68 68 72 80 68 68 73 63 50 30 -1
The first summer would be the data:
72 67 75 80 70 65
The second summer would be the data:
72 80 68 68 73
These would be averaged to give the final answer.
Ms. Tabrizi -- compute the final answer
ITEM P.
(A-level problem)
Data about whether is stored in the files temps.in. Data about the rainfall is sotred in the file rainfall.in the rainfall data is in the corresponding position as the temperature data. Thus, the third number in temps.in would give the tmperature on for the same day as the third number in rainfall.in would give the rainfall data.
There is an extra -1 at the end of the data in temps.in to indicate the end of the file.
Summer is defined as the period when the termperature first gets above 70 degrees to the time when the termperature falls below 65 degrees.
Determine the total rainfall for all summer periods.
Example, if the input temps.in contained:
20 30 40 50 60 72 67 75 80 70 65 61 40 30 20 40 50 68 68 68 72 80 68 68 73 63 50 30 -1
and rainfall.in contained:
0.20 0.30 0.40 0.50 0.60 0 0 1.0 0 0 0.5 0.61 0.40 0.30 0.20 0.40 0.50 0.68 0.68 0.68 0.11 0.11 0.11 0.11 0.22 0.63 0.50 0.30
The first summer would be the data:
72 67 75 80 70 65
which would corresopnd to the rainfall data:
0 0 1.0 0 0 0.5
The second summer would be the data:
72 80 68 68 73
which would correspond to the rainfall data:
0.11 0.11 0.11 0.11 0.22
Thus, the total rainfall for the summer days would be 2.16 inches.