Previous: 9.8 Exercises
Up: 9.1 Two Dimensional Arrays
Previous Page: 9.8 Exercises

9.9 Problems

  1. Read id numbers, project scores, and exam scores in a two dimensional array from a file. Compute the averages of each project and exam scores; compute and store the weighted average of the scores for each id number.

  2. Repeat 1, but sort and print the two dimensional array by weighted average in decreasing order. Sort and print the array by id numbers in increasing order. Use an array of pointers to sort.

  3. Repeat 2, but plot the frequency of each weighted score.

  4. Combine 1-3 into a menu-driven program with the following options: read names, id numbers, and scores from a file; add scores for a new project or exam; save scores in a file; change existing scores for a project or an exam for specified id numbers; delete a data record; add a data record; compute averages; sort scores in ascending or descending order by a primary key, e.g. id numbers, weighted scores, etc.; compute weighted average; plot frequency of weighted scores; help; quit.

  5. Write a function that uses binary search algorithm to search an array of strings.

  6. Write a function that sorts strings by selection sort in either increasing or decreasing order.

  7. Write a program that takes a string and breaks it up into individual words and stores them.

  8. Repeat 7 and keep track of word lengths. Display the frequency of different word lengths.

  9. Repeat 7, but store only new words that occur in a string. If the word has already been stored, ignore it.

  10. Write a function that checks if the set of words in a string, s, represents a subset of the set of words in a second string, t. That is, the words of s are all contained in t, with t possibly containing additional words.

  11. Write a menu-driven spell check program with the following options: read a dictionary from a file; spell check a text file; add to dictionary; delete from dictionary; display text buffer; save text buffer; help; quit.

    The dictionary should be kept sorted at all times and searched using binary search. Use an array of pointers to sort when new entries are inserted. In the spell check option, the program reads in lines of text from a file. Each word in a line is checked with the dictionary. If the word is present in the dictionary, it is ignored. Otherwise, the user is asked to make a decision: replace the word or add it to the dictionary. Either replace the word with a new word in the line or add the word to dictionary. Each corrected line is appended to a text buffer. At the quit command, the user is alerted if the text buffer has not been saved.

  12. Write a simple macro processor. It reads lines from a source file. Ignoring leading white space, each line is examined to see if it is a control line starting with a symbol # and followed by a word "define". If it is, store the defined identifier and the replacement string. Each line is examined for the possible occurrence of each and every defined identifier; if a defined identifier occurs in a line, replace it with the replacement string. The modified line must be examined again to see if a defined identifier exists; if so, replace the identifier with a string, etc.

  13. Write a lexical scanner, scan(), which calls nexttok() of Problem to get the next token from a string. Each new token or symbol of type identifier, integer, or float that is found is stored in a symbol table. The token is inserted in the table if and only if it was not already present. A second array keeps track of the type of each token stored at an index. The function scan() uses srcharay() to search the array of tokens, uses inserttok() to insert a token in an array, and uses inserttype() to insert type of a token.

    The function scan() returns a token in a string, type of the token, and index where the token is stored in the array. If the array is filled, a message saying so must be displayed.

    Write a program driver to read strings repeatedly. For each string, call scan() to get a token. As scan() returns, print the token, its type, and index. Repeat until an end of string token is reached. When the end of file is encountered, print each of the tokens, its type, and index.

  14. Write routines for drawing lines and rectangles. Write a program that draws a specified composite figure using a character '*'. Allow the user to specify additions to the figure and display the figure when the user requests.

  15. Modify 14 to a menu-driven program that allows: draw horizontal and vertical lines, horizontally oriented rectangles, filled rectangles, display figure, help, and quit.

  16. Write a program that plays a game of tic-tac-toe with the user. The game has three rows and three columns. A player wins when he succeeds in filling a row or a column or a diagonal with his mark, '0'. The program uses '*'. Write and use the following functions:

    init_board():
    initialize the board
    display_board():
    dispays the board
    enter_move():
    for user to enter a move in row and col
    state_of_game():
    test state, finish or continue

  17. Modify the Gauss Method so that a pivot with the largest magnitude is used in converting the array of coefficients to an upper triangular form.

  18. Modify 17 to a menu-driven program that allows the following commands: Get coefficients, display coefficients, solve equations, display solution, verify solution, help, and quit. Write and use functions get_coeffs(), display_coeffs(), solve_eqns(), display_soln(), verify_soln(), help().

  19. Modify 18 so that the input data is in the form:

    a00 x0 + a01 x1 + a02 x2 = b1

  20. Modify 19 so that display coefficients displays equations in the above form.

  21. Write a simple menu driven editor which allows the following commands: text insert, display text, delete text, delete lines, insert lines, find string, find word, replace string, replace word, help, and quit. A window should display part of the text when requested.



Previous: 9.8 Exercises
Up: 9.1 Two Dimensional Arrays
Previous Page: 9.8 Exercises

tep@wiliki.eng.hawaii.edu
Wed Aug 17 09:20:12 HST 1994