9.
b
10.
d
11.
a
12.
d
13.
b
14.
c
15.
a
16.
c
17.
a
18.
d
19.
b
20.
c
1.
c
2.
b
3.
b
4.
d
5.
a
6.
c
7.
a
8.
c
Match the definitions with the appropriate term.
1. Computer system equipment - d. hardware
2. Another word for programs - e. software
3. Language rules
4. Order of instructions
5. Language translator
- b. syntax
- c. logic
- a. compiler
In your own words, describe the steps to writing a computer program.
Answer should describe the six steps in the programming process:
Understand the Problem
Plan the Logic
Code the Program
Translate the Program into Machine Language
Test the Program
Put the Program into Production
3. Would this set of data be suitable and sufficient to use to test each of the following programs? Explain why or why not. a. A program that prints a list of Psychology majors.
Yes, the program can select and print the two records whose major field contains
"Psychology". b. A program that prints a list of Art majors.
No, there are no records whose major field contains "Art". A test would not determine if this field would process correctly. c. A program that prints a list of students on academic probation - those with a grade point average under 2.0.
No, there are no records whose grade point average field contains a value under
2.0. A test would not determine if this field would process correctly. d. A program that prints a list of students on the dean's list.
No, we don't know what value grade point average must be to qualify for the dean's list, so this condition cannot be tested. (Students might argue that they used the dean's list standards used by their institution. This can lead to a discussion about making assumptions.) e.
A program that prints a list of students from Wisconsin.
No, there is no state field, so the program would have no way of knowing what state each student is from. f.
A program that prints a list of female students.
No, there would be no way the program could determine the gender of the student based on the data in the record. Humans could look at the current data and guess if a student was male or female, but they might be wrong. (If the file contained first names such as Terry, Chris and Pat, the task would be even more difficult.)
If a gender field contained an "F" or "M", then a program could select students based on gender.
4.
Suggest a good set of test data to use for a program that gives an employee a $50 bonus check if the employee has produced more than 1,000 items in a week.
Answers may vary, but should include a record where a field called something like itemsProduced is less than 1000, is 1000, and is greater than 1000. The record should also have a way to distinguish one record from another (for example, empName or empNumber). For example: empName
Brown itemsProduced
1000
Walters
Porter
999
1001
5. Suggest a good set of test data for a program that computes gross paychecks (that is, before any taxes or other deductions) based on hours worked and rate of pay. The program computes gross as hours times rate, unless the hours are over 40. Then the program computes gross as regular rate of pay for 40 hours, plus one and a half times the rate of pay for the hours over 40.
Answers may vary, but included in the record layout should be a field for hoursWorked and another for rateOfPay. There should be at least one record where hoursWorked is less than 40, one where it is 40, and where it is greater than 40. The record should also have a way to distinguish one record from another (empName or empNumber). For example: empName
Garcia
Patel
Martin hoursWorked rateOfPay
38 12.55
41
40
13.50
23.00
6. Suggest a good set of test data for a program that is intended to output a student's grade point average based on letter grades (A, B, C, D, or F) in five courses.
Answers may vary, but included in the record layout should be the five grades that will be submitted for averaging. Answers may vary depending on whether the student will input numeric scores (A=4, B=3, etc.) or input letter grades, with the assumption that the program will convert the letter to a numeric score. There should be a variety of grades, and every grade should be used at least once. The record should also have a way to distinguish one record from another (for example, by studentName or studentNumber). For example: stuLastName grade
1 grade
2 grade
3 grade
4 grade
5
Abel
Sager
Thompson
A
F
A
A
F
B
A
F
C
A
F
D
A
F
F
Lee B C A C C
7.
Suggest a good set of data for a program for an automobile insurance company that wants to increase its premiums by $50 a month for every ticket a driver receives in a three year period.
Answers may vary, but included in the record layout should be the insured's premium amount and the number of tickets received. There should be at least one record where ticketsIssued is less than 3, one where it is 3, and where it is greater than 3. The record should also have a way to distinguish one record from another (insuredName or policyNumber). For example: insuredName
Crandell
Byer
Harris
Wu premium ticketsReceived
165.99 0
237.50 3
89.75 4
150.00 1
8.
Assume that a grocery store keeps a file for inventory, where each grocery item has its own record. Two fields within each record are the name of the manufacturer and the weight of the item. Name at least six more fields that might be stored for each record. Provide an example of the data for one record. For example, for one product the manufacturer is DelMonte, and the weight is twelve ounces.
Other fields may include: itemName itemNumber price cost quantityOnHand distributor department aisle
Sample record: itemName: itemNumber: price: cost: packaging: quantityOnHand:
Peaches
12345
1.99
1.70 can
300 packaging isOnSpecial distributor: department: aisle:
Acme
Canned Goods
3 isOnSpecial: Y
9.
Assume a library keeps a file with data about its collection, one record for each item the library lends out. Name at least eight fields that might be stored for each record.
Provide an example of the data for one record.
Fields may include: title
ISBNcode author category normalLoanTerm shelfNumber publisher year isOnLoan dateDue
Sample record: title: author:
The Horse Whisperer
Evans publisher: year: numPages:
ISBNcode: category: isOnLoan: dateDue: isOnReserve: normalLoanTerm: shelfNumber:
Dell
1995
350
0730098712
Fiction
Y
021405
N
21
216 numPages isOnReserve
10.
Match the term with the appropriate shape.
1-c, 2 – d, 3 – a, 4 –b, 5 – e
11.
Which of the following names seem like good variable names to you? If a name doesn’t seem like a good variable name, why not?
Students can have arguments for or against most of these names. The purpose of the exercise is to provoke thought. a.
c – probably too short to be descriptive b.
cost – good, maybe to short? c.
costAmount – good, maybe redundant? d.
cost amount – invalid, space not allowed e.
cstofdngbsns – valid, but difficult to read? f.
costOfDoingBusinessThisFiscalYear – valid, but cumbersome g.
cost2004 – valid. Does 2004 represent a year, an item number, or something else?
12. If myAge and yourRate are numeric variables, and departmentCode is a character variable, which of the following statements are valid assignments? If a statement is not valid, why not? a. myAge = 23 b. myAge = yourRate c. myAge = departmentCode valid valid invalid, mismatched types d. myAge = “departmentCode” e. 42 = myAge f. yourRate = 3.5 g. yourRate = myAge h. yourRate = departmentCode i. 6.91 = yourRate j. departmentCode = Personnel k. departmentCode = “Personnel” l. departmentCode = 413 m. departmentCode = “413” n. departmentCode = myAge o. departmentCode = yourRate p.
413 = departmentCode q.
“413” = departmentCode invalid, mismatched types invalid, constant on left of equal sign valid valid invalid, mismatched types invalid, constant on left of equal sign invalid, character data needs quotes valid invalid, mismatched types valid invalid, mismatched types invalid, mismatched types invalid, constant on left of equal sign invalid, constant on left of equal sign
13. a. Draw a flowchart to represent the logic of a program that allows the user to enter a value. The program multiplies the value by 10 and prints out the result. start get number answer = number *
10 print answer stop b.Write pseudocode for the same problem. start get number answer = number * 10 print answer stop
14. a. Draw a flowchart to represent the logic of a program that allows the user to enter a value that represents the radius of a circle. The program calculates the diameter ( by multiplying the radius by 2), and then calculates the circumference (by multiplying the diameter by
3.14). The program prints both the diameter and the circumference. start get radius diameter = radius * 2 circumference = diameter * 3.14
print diameter, circumference stop b. Write pseudocode for the same problem. start get radius diameter = radius * 2 circumference = diameter * 3.14 print diameter, circumference stop
15. a. Draw a flowchart to represent the logic of a program that allows the user to enter two values. The program prints the sum of the two values. start get value1 get value2 answer = value1 + value2 print answer stop b.
Write pseudocode for the same problem. start get value1 get value2 answer = value1 + value2 print answer stop
16.
a. Draw a flowchart to represent the logic of a program that allows the user to enter three values. The first represents your hourly pay rate, the second represents the number of hours you worked this pay period, and the third represents the percentage of your gross salary that is withheld. The program multiplies your hourly pay rate by the number of hours worked giving the gross pay; then it multiplies the gross pay by the withholding percentage, giving the withholding amount. Finally it subtracts the withholding amount from the gross pay, giving the net pay after taxes. The program prints the net pay. start get hourlyRate, hoursWorked, pctWithholding grossPay = hourlyRate * hoursWorked withholdingAmt = grossPay * pctWithholding netPay = grossPay - withholdingAmt print netPay stop
b. Write pseudocode for the same problem. start get hourlyRate, hoursWorked, pctWithholding grossPay = hourlyRate * hoursWorked withholdingAmt = grossPay * pctWithholding netPay = grossPay – withholdingAmt print netPay stop