1.11 Assignments

Questions

1. What is the difference between top-down and bottom-up design?

2. What are the major steps that must be undertaken to solve problems using top-down design?

3. "Driving a car is an abstraction." Explain.

4. What is an abstraction?

5. "A human being is more than just a machine made of meat." Comment on this statement in the light of this chapter, and your own knowledge of the state-of-the-art of computational machine capabilities.

6. Elaborate on the contention that money--however expressed--is an abstraction of wealth.

7. What is a paradigm? a model? a world view? a meme?

8. "Abstractions are intellectual creations; they are not discoveries." Comment on this statement made in the text. Perhaps you have a different view of the matter.

9. Into what two major categories do the abstractions of interest to the study of computing fall? Break each of the categories into two major sub-categories as well.

10. What is the difference between data and information?

11. Classify as compound or atomic entities: (a) a class of students, (b) the number 4.5, (c) a book, (d) a computer program, (e) the slope of a line, (f) the slope of a line when expressed as rise/run.

12. Classify according to unsigned whole number, signed whole number, real, character, string or boolean types. (Some might be more than one; some might be compound types.)

	(a) 23.589
	(b) 4
	(c) (3, 4)
	(d) "Yesterday, today and forever"
	(e) -12
	(f) 5 < 2
	(g) 15 - 9
	(h) 4.3 - 1.3
	(i) (6 < 2) and (5 > -12)
	(j) {1, 2, 5, 7, 11}
	(k) y2 - y1

13. What is an abstract data type?

14. Why is there a difference between an abstract data type and the representation of one?

15. What is the difference between a variable and a named constant?

16. What is an expression? How is it assigned a type?

17. What are the major tasks of the computing hardware?

18. What is the difference between ROM and RAM?

19. What is the difference between hardware and firmware?

20. What is meant by the term "virtual machine?"

21. What are the major tasks of an operating system?

22. Who was the inventor of two major programming languages, and which ones are they?

23. What language is principally used for business applications?

24. What is the difference between a compiler and an interpreter?

25. Explain the five principal abstractions for structuring programs.

26. Explain, with examples, the difference between top-of-loop and bottom-of-loop testing.

27. What are the advantages of writing out programs in pseudocode before coding them in an actual programming notation?

28. What is an algorithm?

29. What is the difference between the syntax and the semantics of a notation?

30. What are the two major sources of errors in computer programs, and how are they best prevented?

Problems

31. Evaluate the following expressions, giving the value produced for the variable. You may assume that the variable is of the correct type to name the simplified entity from the expression. If any cannot be evaluated for some reason, indicate why not.

	(a) x = 12 + 34 * 15
	(b) y = 1.2 - 3.4 / 1.7
	(c) t = 3 + 5 * 8 - 6 / 2 + 7
	(d) m = (1 < 5) and (-2 < 0)
	(e) b = (3 <= 3) or false
	(f) r = (not (5 + 4 < 2)) and (5 / 1 < 1)
	(g) c = 15 < true
	(h) q = (1.5 * 106) * 1000
	(i) n = ((15 - 2 * 3) < 4) or not (62 - 10)
	(j) Z = 4.5 / 1.5 + float (4)

32. Write an algorithm in pseudocode to write out the first twenty squares. Use a loop.

33. Write an algorithm in pseudocode to test whether a number is even or odd.

34. What is the output of the pseudocode:

	for i = 1 to 10
		for j = 1 to i
			write the value of i
			write a comma and a space
			write the value of j
		go to the next line
		end "for j" loop
	end "for i" loop

35. Write an algorithm in pseudocode to add the squares of the first n positive integers, where the number n is determined by asking the user of the program.

36. Write an algorithm in pseudocode to add ten numbers, each of which is typed by the user.

37. Write an algorithm in pseudocode to add n numbers, each of which is typed by the user. The user must first be asked for n.

38. Modify the algorithm in #37 to add the squares of the numbers as well as the numbers themselves in separate totals.

39. Write an algorithm in pseudocode to sort three numbers in order from smallest to largest.

40. The following piece of pseudo-code is meant to be an algorithm to compute the average of a sequence of real numbers. However, it will not work as shown. Make one correction so that it will.

	Compute Average
		read n (* number of reals to do *)
		set count to 1
		set partial sum to 0
		while count <= n
			read currentReal
			add currentReal to partial sum
			add 1 to count
		end while
		set average to partial sum/ count
		write out average
	end Compute average

41. Write an algorithm to find the largest and the smallest number of a sequence of numbers.

42. Combine the corrected algorithm for #40 and #41 to produce a single piece of pseudo code to examine a sequence of numbers and determine the largest, smallest, and average of the numbers.

43. A matrix is a rectangular array of numbers, such as:

	1	4	9	-7	6
	3	2	89	5	34
	1	-56	7	8	13

This particular one is a three row by five column matrix. Write an algorithm for adding together all the cells of the matrix.

44. Generalize the pseudo code for the last problem by having the number of rows and the number of columns as named constants numrows & numcols rather than as specific numbers (three and five.)

45. You have a column of numbers a1, a2, a3 through a12 that represent the monthly profits of your organization. You want to project these to the following year by adding 5% to each one and putting the result into another column numbered b1, b2,... through b12. Write the pseudocode for this. (Note that the two columns constitute a matrix.)

46. You have three columns of numbers labelled revenue, expense and net profit. Each row is numbered 1,2,3,... lastItemNumber. Assume the first two columns are already filled in with data. Write the pseudocode to construct the third.

47. As in #46 above, but the columns are labelled price, GST (tax) and total. Only the first column is filled in. The second is constructed by finding 7% of the number in the first, and the third by taking the total of the first two. Write pseudocode to do this.

48. There are five columns of numbers labelled first, second, third, max, and average. The rows are numbered 1,2,3,... lastItemNumber. The first four columns are filled in. Write the pseudocode to fill in the last two columns of each row with the maximum and average of the first three in that row.

49. As in #48 above, but there are only three columns labelled first, second, and third. Write the pseudocode to obtain those numbers from a user and to put them into sorted order in the table. You can do this in one combined piece of code, or in two stages.

50. A vector is an array of numbers that has only one row (or column, as the case may be). If two vectors have the same length, their dot product is defined as the sum of the products of their respective components. That is, the dot product of (2, 3, 5) with (1, -7, 9) is 2 + (-21) + 45, a total of 26. Write the pseudocode to read in the values of two vectors, check to see if they are the same length, and if so, compute their dot product. If not output an error message.


Contents