Exercises

1:

Use any available manuals and/or explore actual system behavior to develop appropriate descriptive information like that in Table 9-1 for the sscanf function, which reads input from a string already in memory and interprets that string according to a format specification.

2:

Explain what sorts of modifications would be required if SCANTERM were to use Unix system calls instead of C support functions for its I/O. Search in the reference materials accessible to you for relevant technical information.

3:

How does SCANTERM behave if it encounters more than one space between words? Propose an appropriate revision to the program.

4:

Would SCANTERM be appreciably simpler if it performed its input using a control string of "%s" with the scanf function for its input method? Consider revising the program accordingly.

5:

The fgets function truncates input if the caller's declaration of buffer size is too small to hold all characters of input up through a newline. Show how the coding of a program should be amended to handle the contingency of no newline character being brought into the program's buffer.

6:

What would be wrong with putting a test for whether register r25 holds a null at why in SORTSTR, and branching to adjust if so?

7:

Assume that two particular strings exchanged by the loop beginning at swap in SORTSTR each have 79 printing characters, followed by a null. How many instructions does the loop beginning with swap as shown in Figure 9-4 use?

8:

Explain in general terms how SORTSTR would have to be modified to bring two, Two, and TWO into adjacency in the sorted output.

9:

What elements in the typescript file lincoln.txt does the SCANFILE program inaccurately consider to be words? Discuss how a program could better conform to the standard views of what is, or is not, a word. (Actually programming this might be harder than it first seems to be.)

10:

Sometimes the last few passes in a bubble sort are futile because all the data by then are already in the desired order. A flag variable can be used to determine whether the traversals of the inner loop resulted in any exchanges at all (see Knuth). If no exchanges occurred, the outer loop can safely terminate too. Make this improvement in either SORTSTR or SORTINT. You can use printf to print the value of the control variable for the outer loop if you wish to demonstrate that this improvement is working.

11:

Find out what actually happens when SORTINT encounters a decimal point in one of the numbers in its input file (such as 2.71).

12:

Explain what sorts of changes would be required in order to convert SORTINT into a program that could handle real numbers (having decimal points and exponential notation) instead of integers. If your instructor so requires, proceed to implement and test those changes.

13:

Redesign the routine for computing the function N3 + N based on the finite differences algorithm, following these revised specifications:

  1. Input N, the number of values to be computed, as a string of decimal digits entered by the user.

  2. Print each value of the function as soon as it is generated, formatting it as a string of decimal digits on a line by itself.

  3. Print a blank line before going back to input N again. (Quit the program with control-C.)

Test the program using first N=8 and then N=6 (in a single run).

14:

Redesign and extend the routine that tests for palindromes so that it will deal with palindromic sentences. The input is to come from the user in mixed upper/lower case, with appropriate punctuation for reading in the forward direction. If the sentence is a palindrome (ignoring spaces, punctuation, and case), then print "Yes", else print "No". Prompt the user for another line of input. (Quit the program with control-C.)

15:

Write an Itanium assembly language program that will merge two input text files, each containing already-sorted lists of (a) signed integer quantities or (b) signed real numbers, into an output text file. Be sure that the program correctly handles the end of file cases that arise when the second file is shorter than, the same length as, or longer than, the first file.

16:

Write a program that prompts for the name of a text file and reads it sequentially. This program is to calculate the frequency distribution of different word lengths (discarding all punctuation characters). Assume that the word lengths will range from one to 20 letters. Print out into a new text file the name of the input file, a distribution table of word lengths, the average word length (use integer division if you omitted Chapter 8), and the most frequent word length. Run the program with the lincoln.txt file and again with an essay that you have written. (This exercise illustrates the somewhat crude methods of textual analysis that were first employed by scholars in the humanities using 1960-era mainframe computers; newer, more sophisticated methods have been applied to resolving contested issues of authorship.)



ItaniumR Architecture for Programmers. Understanding 64-Bit Processors and EPIC Principles
ItaniumR Architecture for Programmers. Understanding 64-Bit Processors and EPIC Principles
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net