Practice Assignment 3 - Introductory Programming and Problem Solving | ECS 030, Assignments of Computer Science

Material Type: Assignment; Class: Intro Prog&Prob Solving; Subject: Engineering Computer Science; University: University of California - Davis; Term: Unknown 2002;

Typology: Assignments

Pre 2010

Uploaded on 07/31/2009

koofers-user-xph-1
koofers-user-xph-1 🇺🇸

5

(1)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
H
OMEWORK
3 ECS 30-A — S
PRING
2002
Version of April 18, 2002 4:59 pm Page 1 of 2
Homework 3
Due Date:
Monday, May 13, 2002,
at 11:59PM
Points
: 100
UNIX System
1. (
10 points
) What is the parent directory of /?
2. (
15 points
) The file /usr/share/dict/words contains a list of English words and abbreviations, one per line. How
many words and abbreviations does it have? List all words in it with the trigram "gry" in them.
C Programming
3. (
30 points
) Write a program that reads words from the standard input and prints them in sorted order (use ASCII
ordering). Use a linked list to do this. The structure of a node in the linked list is to be:
struct lnode {
char *word; /* pointer to word */
struct lnode *nxt; /* pointer to next entry in linked list */
}
You will need to use the function
malloc
(3) to allocate both space for the word and space for the nodes. If a word
occurs more than once, list each occurrence seperately. A “word” is a maximal sequence of letters and digits.
Your program should print one word per line. For example:
Sample stdin Corresponding stdout
Hello, there, my old friend! Goodbye
How are you today? Hello
I am very well, thank you! How
Goodbye ... I
am
are
friend
my
old
thank
there
today
very
well
you
you
4. (
30 points
) Please make two modifications to the program you wrote for part 3:
a. Change the program so the user can name one or more files on the command line, and the program will take
input from those files. If no files arenamed, the program should read from the standard input.
b. Add a command-line option
–r
that causes the words to be printed in
reverse
order. (
Hint
: use recursion.)
.Debugging
5. (
15 points
) The program
getbit.c
(available on the class website) reads in two numbers,
n
and
b
. It returns the
b
th
bit of integer
n
, where the smallest (rightmost) bit is bit number 0. Rather, it is
supposed
to. But it doesn’t work.
Please debug it.
pf2

Partial preview of the text

Download Practice Assignment 3 - Introductory Programming and Problem Solving | ECS 030 and more Assignments Computer Science in PDF only on Docsity!

H O M E W O R K 3 E C S 3 0 - A — S P R I N G 2 0 0 2

Version of April 18, 2002 4:59 pm Page 1 of 2

Homework 3

Due Date: Monday, May 13, 2002, at 11:59PM Points : 100

UNIX System

  1. ( 10 points ) What is the parent directory of /?
  2. ( 15 points ) The file /usr/share/dict/words contains a list of English words and abbreviations, one per line. How many words and abbreviations does it have? List all words in it with the trigram "gry" in them.

C Programming

  1. ( 30 points ) Write a program that reads words from the standard input and prints them in sorted order (use ASCII ordering). Use a linked list to do this. The structure of a node in the linked list is to be: struct lnode { char word; / pointer to word */ struct lnode nxt; / pointer to next entry in linked list */ } You will need to use the function malloc (3) to allocate both space for the word and space for the nodes. If a word occurs more than once, list each occurrence seperately. A “word” is a maximal sequence of letters and digits. Your program should print one word per line. For example: Sample stdin Corresponding stdout Hello, there, my old friend! Goodbye How are you today? Hello I am very well, thank you! How Goodbye ... I am are friend my old thank there today very well you you
  2. ( 30 points ) Please make two modifications to the program you wrote for part 3:

a. Change the program so the user can name one or more files on the command line, and the program will take input from those files. If no files arenamed, the program should read from the standard input. b. Add a command-line option –r that causes the words to be printed in reverse order. ( Hint : use recursion.)

.Debugging

  1. ( 15 points ) The program getbit.c (available on the class website) reads in two numbers, n and b. It returns the b th bit of integer n , where the smallest (rightmost) bit is bit number 0. Rather, it is supposed to. But it doesn’t work. Please debug it.

H O M E W O R K 3 E C S 3 0 - A — S P R I N G 2 0 0 2

Version of April 18, 2002 4:59 pm Page 2 of 2

Extra Credit

  1. ( 10 points ) In your program for problem 3, change the way you handle repeated words as follows. Suppose the word hello occurs 3 times. Instead of printing it 3 times, print it as follows: hello (3) Hint : You will need to change the structure of the node to include a counter.