1 / 8

Case studies over structure types and strings

Case studies over structure types and strings . Instructor – Gokcen Cilingir Cpt S 121 (July 21, 2011) Washington State University. Problem 1.

haroun
Télécharger la présentation

Case studies over structure types and strings

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Case studies over structure types and strings Instructor – GokcenCilingir Cpt S 121 (July 21, 2011) Washington State University

  2. Problem 1 Problem statement: Write a program that reads a paragraph from a text file and produces the list of words read from the file in the order of last word first. Output should be written to both standard output and to a file.

  3. Problem 1 (cont’d) Functional decomposition: intreadWord(FILE * infile, char *word) – takes string formatted input from a file and places it into the given string. void readWordList(FILE * infile, char wordList[][MAX_WORD_LENGTH], int *size) – repetitively takes string formatted input from a file (until EOF) and places them into the given string array. Returns as output parameter the size of the list. void customPrint (char *str, FILE * outfile) – writes the given string both to standard output and to the given file.

  4. Problem 2 Problem statement: Extend the program you’ve written for problem 1 such that each word is displayed stating it’s length. For example, if the word is “Write”, than “Write (5)” should be displayed.

  5. Problem 3 Problem statement: Extend the program you’ve written for problem 2 such that each word is right-stripped from punctuation. Additional function to write: void rightStripFromPunctuation(char *str) – Alters the given string such that it is stripped from preceding punctuation

  6. Problem 4 Problem statement: Write a program that takes nouns and forms their plurals on the basis of these rules: a. If noun ends in “y” remove the “y” and add “ies” b. If noun ends in “s” , “ch”, or “sh”, add “es” c. In all other cases, just add “s” Print each noun and its plural. Try the following data: chair dairy boss circus fly dog church clue dish

  7. Problem 5 Problem statement: Numeric addresses for computers on the international network internet are composed of four parts ,separated by periods of the form xx.yy.zz.mm where xx, yy, zz, and mm are positive integers. Locally, computers are usually known by a nickname as well. • Design a program to process a list of internet addresses, identifying all pairs of computers from the same locality. • Create a structure type called address_twith components for the four integers of an internet address and a fifth component in which to store an associated nickname of 10 characters.    • Your program should read a list of up to 100 addresses and nicknames from an input file.

  8. Problem 5 (cont’d) • Sample Data 111.22.3.44                    platte 555.66.7.88                    wabash 111.22.5.66                    green 0.0.0.0                            none The program should display a list of messages identifying each pair of computers from the same locality-that is , each pair of computers with matching values in the first two components of the address. In the messages, the computers should be identified by their nicknames.

More Related