LBS290F MAKEUP MIDTERM EXAM - II Spring 1992 NAME: ____________________________________________________ STUDENT NUMBER: ______________________ SIGNATURE: _____________________________________________ This exam is closed book, closed notes. There are 4 questions on 5 pages. This exam is worth 20% of your final grade. The questions are equally weighted. Each is worth 25 points. 1. Assume the following variables: Variable Contents Type --------------------------------------- EMPNO Employee Number INTEGER RATE Pay Rate REAL HOURS Hours worked REAL GROSS Gross Pay REAL TAXES Taxes withheld REAL NETPAY Net Pay REAL Write a print statement and format statement which would print the values out in the following columns: EMPNO RATE HOURS GROSS TAXES NETPAY 7 12.50 40.00 500.00 125.00 375.00 123456789012345678901234567890123456789012345678901234567890 Columns 1 2 3 4 5 6 Your code must be able to handle real numbers up to 9999.99 and employee numbers up to 9999. NOTE: The answer to this question is NOT a whole program. It is just two FORTRAN statements. You do not have to read or calculate the values for this question - just print them out in the correct format. 2. The purpose of this program is to print out all of the common factors of two numbers. The common factors are those numbers which can be evenly divided into both of the umbers. If the numbers have no common factors print out a message. Terminate the program when a negative number is entered. At the end of the program print the total number of pairs processed and the number of common factors found. Example execution: $ a.out Welcome to the common factors program written by - Arun Student ENTER TWO NUMBERS 16,48 Common Factors of 16 and 48 2 4 8 16 The numbers 16 and 48 have 4 common factors ENTER TWO NUMBERS 63,71 Common Factors of 63 and 71 These numbers have no common factors ENTER TWO NUMBERS -1,-1 Thank you for using the common factors program. Pairs processed: 2 Factors found: 4 $ 3. READ this question carefully. There are some small differences between this question and the previously assigned program. The purpose of this program is to track an inventory of a small business. The program will track up to 10 parts with part numbers ranging from 1 to 10. Each line read by the program is an inventory control record. The first number indicates the type of transaction - 1 Stock 2 Sell. The second number is the part number. The last number is the number of parts bought or sold. Example input: 1 2 20 Stocked 20 of part 2 2 4 5 Sold 5 of part 4 The program must check for an illegal transaction type. The program must check for an error in the part number. The program also must also not allow product to be sold if there is none in stock. The program will print the ending inventory when CTRL-D is entered. Example execution: $ a.out Enter the inventory control record: 3 0 0 Error - Illegal transaction type Enter the inventory control record: 1 20 90 Error - Part number 20 too large Enter the inventory control record: 2 4 5 Error - current inventory of part 4 is 0, cannot sell 5 Enter the inventory control record: 1 2 20 Enter the inventory control record: 1 4 10 Enter the inventory control record: 2 2 5 Enter the inventory control record: (CTRL-D) PART COUNT ---- ----- 2 15 4 10 Thank you for using the inventory program. Space provided on the following page for the answer. Answer to question 3. 4. The purpose of this program is to list the numbers from 1 to 50 and determine if each number is prime or composite. A composite number is a number which can be evenly divisible by another number. A prime number is one which cannot be evenly divided by any other number. The program will print out the number of prime numbers and the number of composite numbers between 1 and 50. Example output: NUMBER TYPE ------ ---- 1 PRIME 2 PRIME 3 PRIME 4 COMPOSITE 5 PRIME TOTAL PRIME NUMBERS: 14 TOTAL COMPOSITE NUMBERS: 36