Exam #1 Review

(Last Mod: 27 November 2010 21:38:42 )

ECE-1021 Home


Links:

Bookmarks:


Topics Covered


 

Review Questions

  1. Draw the flowchart for an if()/else structure.

  2. Draw the flowchart for a while() loop.

  3. Draw the flowchart for a do/while() loop.

  4. What are the three basic building blocks used to develop structured programs?

  5. There are eleven subgroups of the ASCII character set. What are they?

  6. The string, "Time 2 Go!" is stored at memory location 0xC340. Indicate the values (using the actual numbers - in hex) that are stored in each of the relevant memory locations.

  7. The following bytes are stored beginning at memory location 0xC34D: 0x66, 65, 68, 00, 47, 6F, 6F, 64, 00, 73, 6F, 2D, 73, 6F, 00. What string is stored at memory location 0xC351?

  8. Briefly summarize the key elements of the top-down algorithm development strategy.

  9. To take the negative of a number when using the two's compliment format you can use the simply algorithm where you first invert all of the bits and then add one to the result. Starting with the definition of an "additive inverse", show where this algorithm comes from.

  10. Given two two-byte binary bit strings A and B, what is the practical net effect of executing the following three statements:

    1. A = A^B

    2. B = A^B

    3. A = A^B

Note that '^' indicated bitwise XOR and that these instructions are neither ACME-1021 nor C code. This is a general question regarding the impact of performing three successive XOR operations on the same variables as shown above.

  1. The function PutS() that we have performs a very specific task ? it takes as an argument the address where a string of text is stored in memory, it displays that text on the screen using repeated calls to the putc() function (via the PutC() macro), and it returns the total number of characters output to the screen.

 Our version of PutS() is based on the premise that the string whose address is passed is a null-terminated string. This is not the only way that the string could have been stored. The other common way of representing strings is to prefix them with a character count. In this case, the function would still be passed a pointer to a one-byte integer (i.e., a char) but the bits at that location would be interpreted as the number, N, of characters in the string. The characters themselves are then located in the next N bytes of memory.

For instance, if the string ?Hello World!? were stored at memory location 0x342 under each convention, the memory map in that region might look like:

null-terminated string:

340

341

342

343

344

345

346

347

348

349

34A

34B

34C

34D

34E

34F

68

91

48

65

6C

6C

6F

20

57

6F

72

6C

64

21

00

09

?h?

.

?H?

?e?

?l?

?l?

?o?

SP

?W?

?o?

?r?

?l?

?d?

?!?

NUL

HT

count-prefixed string:

340

341

342

343

344

345

346

347

348

349

34A

34B

34C

34D

34E

34F

68

91

0C

48

65

6C

6C

6F

20

57

6F

72

6C

64

21

09

?h?

.

FF

?H?

?e?

?l?

?l?

?o?

SP

?W?

?o?

?r?

?l?

?d?

?!?

HT

 Write a function called PutSP() that performs the same task as PutS(), but for count-prefixed strings.


This WILL BE the extra credit problem on the exam.

EXTRA CREDIT ? (10 pts) In accounting, it is common practice to indicate negative values by surrounding the absolute value of the number with either parentheses or angled brackets. Write a function called PutV_lfa() that takes a single argument of type double and displays the value to two decimal digits (properly rounded) with a dollar sign preceding the value. If the value is negative, then angle brackets surround everything. The value returned should be the total number of characters printed.

 

Example 1: PutV_lfa(3.4176);     /* Should display:   $3.42  Should return 5  */

Example 2: PutV_lfa(-15.7323);  /* Should display:   <$15.73>  Should return 8  */