Assignment Set Two

The requirements for this assignment set are:

C REQUIREMENTS

Complete any program and seven other activities

B REQUIREMENTS

Complete any program and eight other activities

A REQUIREMENTS

Complete Item I and eight other activities

In this assignment set, the conventional grading system requires that you do Item A on the computer.

Bonus:

If you hand this assignment in ON TIME, you get four activity bonus.
This problem is being given out at the beginning of the semester nad as such, is relatively easier. Thus it is not eligible for the one letter grade bonus.

ITEM a.

Write a program that will read in three numbers from a file called CLASS.201

It should read in three numbers from a file called LEFF.DR

It should read in three numbers from a file called RIGHT.ON

It should put the sum of the three numbers from CLASS.201 in a file called SPRING.93

It should put the product of the numbers from LEFF.DR in a file called WIU.CS

It should print the sum of all nine numbers from all three input files in a file called BIG.SUM

So, if CLASS.201 contained '1 3 7', LEFF.DR contained '4 5 9', and RIGHT.ON contained '8 10 11', then SPRING.93 should contain '29'. WIU.CS should contain '180'. Finally, BIG.SUM should contain '58'.

ITEM b.

Write a program that should read two numbers from a file called FIRST.FIL, two numbers from a file called SECOND.FIL, and two numbers from a file called THIRD.FIL

It should create two output files.

OUT1.NUM which should contain the first number from FIRST.FIL, the first number from SECOND.FIL, the second number from FIRST.FIL, the second number from SECOND.FIL

OUT2.NUM which should contain the product of all the numbers from FIRST.FIL, the sum of all the numbers from SECOND.FIL, and difference of the first and second numbers from THIRD.FIL

Example:

If FIRST.FIL contained '1 2 ', SECOND.FIL contained '10 20 ', and THIRD.FIL contained '5 4 ', then OUT1.NUM should contain '1 10 5 2 20 4 ' and OUT2.NUM will contain '2 30 1'.



ITEM A.

You are now an FBI agent tapping the phone line of a money launderer. You know the numbers for various banks (you will make these numbers up and put them in BANKS.IN).

As each bank number is read from banks.in, you will "listen" to your wire tap until you hear that bank number and the amount of money to be laundered through that bank. Read in that amount of money from the keyboard. Then write the bank name and the amount of money that will be laundered through that bank to an output file called FBI.OUT

When your program concludes, your file FBI.OUT should contain the numbers for all the banks and the money that was to be laundered through each bank. (We're assuming that you were lucky enough to hear an amount for each bank!)

You will need to put the total amount laundered from all banks put together in the a file called BANKTOT.OUT

So, if BANKS.IN contained: '1187 9012 4312 6544', and you determined (made up and read in from keyboard) that each respective bank laundered 10000, 25000, 86541, and 97010, your output file, FBI.OUT, should contain '1187 10000 9012 25000 4312 86541 6544 97010'
BANKTOT.OUT should contain '218551'.

ITEM B.

This program will read an integer from NUMBERS.1 and another from NUMBERS.2.

You will perform each of the mathematical operations on four integers (add, subtract, multiply, divide) and write the results respectively to four output files (ADD.OUT, SUB.OUT, MUL.OUT, and DIV.OUT).

So, if numbers.1 contains '1 12 4 7', and NUMBERS.2 contains '2 8 1 6', then output files should contain '3 22 5 13', '-1 4 3 1', '2 96 4 42', and '0 1 4 1'

Note: NUMBERS.1 and NUMBERS.2 must contain 4 numbers each.

ITEM C.

This program will read integers from four input files, and write sums to four output files.

Your input files should be named NUMSIN.1, NUMSIN.2, NUMSIN.3, and NUMSIN.4 respectively.

Your output file should be named NUMSOUT.1, NUMSOUT.2, NUMSOUT.3, and NUMSOUT.4 respectively.

Procedure:
read in an integer from NUMSIN.1
start your sum
write your sum to NUMSOUT.1
read in an integer from NUMSOUT.2
add to your sum
write your sum to NUMSOUT.2
-continue in this fashion with an integer from NUMSIN.3 and
NUMSIN.4

Perform the above procedure four times (once for each for row of numbers in the input files).

Hint: Remember to reset your sum to zero before starting the procedure again. Each input file must have four numbers.

So, if NUMSIN.1 contains '1 2 3 4', NUMSIN.2 contains '4 3 2 1', NUMSIN.3 contains '10 9 8 7', and NUMSIN.4 contains '1 5 7 9', then the output files should contain '1 5 15 16', '2 5 14 19', '3 5 13 19', and '4 5 12 21' respectively.

ITEM D.

In this problem you will have three input files: TRICK1.IN (which contains 7 numbers), TRICK2.IN (which contains 2 numbers), and TRICK3.IN (which contains 1 number).

Copy the numbers from TRICK1.IN into TRICK3.OUT
Copy the numbers from TRICK2.IN into TRICK2.OUT
Copy the number from TRICK3.IN into TRICK1.OUT

Put the sum of all the numbers in TRICK1.IN and TRICK2.IN, minus the number in TRICK3.IN into TRICKZ.OUT.

Put the sum of all the numbers in TRICK2.IN and TRICK3.IN into another output file called TRICKY.OUT.

So, if TRICK1.IN contains '3 2 1', and TRICK2.IN contains '5 1', and TRICK3.IN contains '7', then the output files should contain '7' in TRICK1.OUT, '5 1' in TRICK2.OUT, '3 2 1' in TRICK3.OUT, '5' in TRICKZ.OUT, and '13' in TRICKY.OUT.

ITEM E.

Read in five integers from INTFILE.1 and five integers from INTFILE.2.

Print the five integers in order from INTFILE.2 into a file called
INTOUT.1

Also put the five integers in INTFILE.1 into INTOUT.1, but in reverse order as they appear in INTFILE.1

Print the five integers in order from INTFILE.1 in a file called INTOUT.2

Also put the five integers in INTFILE.2 into INTOUT.2, but in reverse order as they appear in INTFILE.2

So, if INTFILE.1 contains '4 1 5 4 3', and INTFILE.2 contains '78 12 3 9 0', then the output files should contain '78 12 3 9 0 3 4 5 1 4', and '4 1 5 4 3 0 9 3 12 78' respectively.

ITEM F.

Read in two one-digit numbers from DIGIT1.IN, and two one-digit numbers from DIGIT2.IN.

Put into an output file COMBO.OUT all legal possible combinations of the numbers from set from DIGIT1.IN combined with the set from DIGIT2.IN

For this problem, legal combinations must contain a number of set DIGIT1.IN as the first number in COMBO.OUT, and a number from DIGIT2.IN as COMBO.OUT's second number. A set may not be combined with itself.

So, if DIGIT1.IN contains '1 2', and DIGIT2.IN contains '3 4', then COMBO.OUT should contain '1 3 <
+ 2 4 <
+ 1 4 <
+ 2 3' where "<
+" separates legal combinations and represents a end-of-line character.

ITEM G.

This problem is similar ITEM H except that all combinations are possible, including combining a set with itself. Use the file-definitions that are stated in ITEM H.

So, if DIGIT1.IN contains '1 2', and DIGIT2.IN contains '3 4', then COMBO.OUT should contain '1 2 <
+ 2 1 <
+ 3 4 <
+ 4 3 <
+ 3 1 <
+ 1 4 <
+ 1 3 <
+ 2 3 <
+ 2 4 <
+ 3 1 <
+ 3 2 <
+ 4 1 <
+ 4 2' where "<
+" separates legal combinations and represents a end-of-line character.

ITEM a. Level A Homework Assignment

Read two integers from the file RECT.1
These will be the height and width of a rectangle

Read two more integers from the file RECT.2
These will be the height and width of a second rectangle.

Write two numbers into PERIM.OUT, an output file. These will be the perimeter of the first rectangle followed by the perimeter of the second rectangle.

Into the output file AREA.REC, write two numbers. These will be the area of the first rectangle followed by the perimeter of the second rectangle.

Then draw on a graphics screen (using the techniques of Unit 1.6), a red rectangle as indicated by the height and width from RECT.1
and a blue rectangle as indicated by the height and width from RECT.2

Read up on the SetColor command in the Turbo Pascal manuals.

Specifically read page 129 of the Turbo Pascal Library Reference and Chapter 12 of the Turbo Pascal Programmer's Guide.

These are both available in the Stipes 304 lab. Ask the lab assistant for them. Make sure you use the manuals for the current version of Turbo Pascal which is numbered 6.0.