## PART A

DO ONLY 2 QUESTIONS FROM THIS PART

### QUESTION A‑1 [ SAVE ON DISK AS "QA.l" ]

Write a program which accepts as input, a list of positive integers (length unknown to a maximum of 100), termInated by a negative number. The output should be the second largest number entered. The program must NOT sort the entire set of data and the data may be only entered once.

### QUESTION A‑2 [ SAVE ON DISK AS "QA.2" ]

Create a diamond pattern as shown below.  The input should be the maximum width of the diamond.

eg. an input of 3 gives the output   an input of 4 gives the output

`        ``*````                                         ````*`

`      ``*``   ``*````                                     ````*``   ``*`

`    ``*``   ``*````   ````*````                                 ````*``   ``*``   ``*`

`      ``*``   ``*````                                 ````*``   ``*``   ``*``   ``*`

`        ``*````                                     ````*``   ``*````   ````*`

```                                      ````          ``*``   ``*`

```                                                  ````*``    `

### QUESTION A‑3 [ SAVE ON DISK AS "QA.3" ]

Write a program that inputs a string of arbitrary length and removes all blanks from it and compacts all the non blank characters. The use of any built in search‑and‑replace functions is NOT allowed. The output should be the compacted string.

eg. an input of "The lazy dog sat." should produce the output

Thelazydogsat.

### QUESTION A-4   [ SAVE ON DISK AS "QA.4" ]

Write a program that calculates the sum of the series

3      13      28     3n2 + 1

16  +   36  +   64  +  4(n+1)1   + ....

ln one of two ways.

Your program should give the user the choice of inputting the number of terms to be included ln the sum, or, the desired accuracy. If the user chooses the desired accuracy option, the accuracy should then be entered as the NUMBER OF DECIMAL PLACES.

The output should be the sum as calculated.

### QUESTION A‑5 [ SAVE ON DISK AS "QA.5" ]

The input will be a dollar value between \$0.00 and \$5.00. The outPut should indicate the

number of \$2.00 bills,

number of loonies,

number of quarters,

number of dimes,

number of nickels,

and the number of pennies.

which should be given as change from a \$5 bill, where the change is given using the largest denominations possible.

## PART B

DO ONLY 1 QUESTION FROM THIS PART

### QUESTION B‑1 [ SAVE ON DISK As "QB.1" ]

This program simulates a fare meter in a TAXI. All taxi trips include a starting fare of \$2.50. The meter keeps track of the number of kilometres completed in the trip. A trip fare of \$1.10 per kilometre is added to the starting fare and then a premium is calculated on the entire cost according to the table below:

0601h‑1800h weekdays      0.0%

1801h‑2400h weekdays      10.0%

0001h‑0600h all days      20.0%

1801h‑2400h sat/sun       15.0%

The cab driver inputs the number of the day of the week (ie. l=‑sun, 2=mon, 3=tues ...), the time of day in 24 hour format, and the number of kilometres travelled. The output should be the total charge to the passenger.

### QUESTION B‑2 [ SAVE ON DISK AS "QB.2" ]

Write a program which stores 10 words into a string array. Each word is to be randomly scrambled (ie. the letters mixed up). A "player" is then shown the scrambled word on the screen and asked to enter it unscrambled within a preset time limit. Report how many of the 10 words which are unscrambled within the time limit.

### QUESTION B‑3 [ SAVE ON DISK AS "QB.3" ]

Prepare a program which will simulate the "QUICK PICK" option of LOTTO 649. The program should display six random numbers in the range of 1 to 49 inclusive, with NO TWO BEING THE SAME. The program should then ask the user if he wishes to have another QUICK PICK and proceed accordingly.

## PART C

DO ONLY 1 QUESTION FROM THIS PART

#### QUESTION C‑1 [ SAVE ON DISK AS "QC.1" ]

Two positive integers are said to be friendly if each one is equal to the sum of the divisors (including 1, excluding the number itself) of the other. For example, the numbers 220 and 284 are friendly since:

the sum of the divisors of 220 is:

1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110 = 284

and the sum of the divisors of 284 is:

1 + 2 + 4 + 71 + 142 = 220

Write a program which finds and outputs all pairs of friendly numbers such that BOTH numbers are less than N. N is a value entered by the user.

### QUESTION C‑2 [ SAVE ON DISK AS "QC.2" ]

This program simulates a slot machine. On one pull of the NSBCC slot machine, four single digit numbers appear. The machine pays according to the following chart.

RESULT       PAYOFF (in dollars)

4 of a kind 400 + lOOd

3 of a kind 300 + 50d

2 pairs      100 + 40(d1+d2)

1 pair       100 + 50d

4 different O

Note:     in each case 'd' represents the digit appearing a multiple number of times. 'dl' and 'd2' represent the digits appearing as pairs in the 2 pair case.

eg. A pull resulting in 8 2 8 8 would pay ... 300 + 50(8) = 700

Write a program which shows 15 random pulls, calculates and outputs the payoffs for each, and gives the total earnings won or lost based on a charge of S10 per pull.

### QUESTION C‑3 DO ALL THREE PARTS TO THIS QUESTION

Part 1 [ SAVE ON DISK AS "QC.31" ]

Write a program which creates a MASTER DATA FILE named MAST.dat The file contains a record of each salesperson of the XYZ Co and a dummy record used as an end of file marker. Each record contains the following fields:

Employee Number

Name

Commission Rate

Use the following data to create the file:

Employee Number    Name      Commission Rate

1             Jones         0.30

2             Carter        0.31

3             Black         0.29

4             Anderson      0.25

5             Lawson        0.34

_999          zzzz          0     (dummy record)

Part 2 [ SAVE ON DISK AS "QC.32" ]

Write a second program which creates a TRANSACTION DATA FILE named TRANS.dat The file contains the sales made by each salesperson during the week and a dummy record used as an end of file marker. (NOTE: some salespersons were on vacation during the week). Each record contains the following fields:

Employee Number

Dollar Sales

Use the following data to create the file:

Employee Number   Dollar Sales

1             10000.00

3             20000.00

4             15000.00

-999               0    (dummy record)

Part 3 [ SAVE ON DISK AS "QC.33" ]

Write a third program which reads the MASTER FILE created in part A and the TRANSACTION FILE created in part B and generates an on screen report as shown below.

`     ``XYZ Co. `

` `

`     ``COMMISSION REPORT`

` `

` ``    ````EMPLOYEE ````     ``DOLLAR ``       ``COMMISSION`

` ``    ````NAME ````         ``SALES ``        ``EARNED`

`     ``=================================================`

`     `

`     ````Show only the employees who were NOT on vacation. ```

`     ``=================================================`

` `

`     ``Summary Information`

` `

`     ````Total Dollar Sales xxxxxx.xx```

`     ````Total Commission xxxxxx.xx```

` `

`     ````Average Commission per salesperson xxxxx.xx```