Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1. Standard telephone keypads contain digits 0 through 9. The numbers 2 through 9 each have three or four letters associated with them. The

Part 1.

Standard telephone keypads contain digits 0 through 9. The numbers 2 through 9 each

have three or four letters associated with them. The numbers from 2-9 represent letters as

follows:

2 ABC

3 DEF

4 GHI

5 JKL

6 MNO

7 PQRS

8 TUV

9 WXYZ

Many people nd it hard to memorize phone numbers, so they use the correspondence between

digits and letters to make meaningful words that represent phone numbers. Since multiple

letters map to a single number, a single number may represent multiple words. For example,

the number 2665 represents "book" and "cool", among other possibilities.

In this homework you will assume that the telephone numbers have 5 digits only. You will

write a C-program that will take a 5-digit phone number and print to stdout all the meaningful

words it can represent. In order to decide if a word is meaningful, you will use a dictionary.

I provide two les small-dictionary.txt and dictionary.txt which contains one word per line

(in English). You will use input redirection to redirect the dictionary le into your program

(that means your program will read from standard input), and store each word in an array

of strings. There are 80368 words in the large dictionary I provide, so your array should be

at least of that size. For each word you generate, look it up in the dictionary, if found, print

it to standard output.

Note that, the dictionary is sorted, and you should use binary search when looking up a word

(much faster than sequential search).

The user will enter the telephone number as a commandline argument using the ag

-t

number

. Your program will print ALL possible words for a given telephone number.

For example:

$ hw3 -t 76257 < small-dictionary.txt

1

'rocks'

'socks'

$ hw3 -t 53556 < small-dictionary.txt

'jello'

When testing, use the small dictionary le, and if it works then start using the larger dictio-

nary le.

Part 2.

Now, update your homework in Part 1 so that it uses C's command line arguments to

input a telephone number to process, and some to add other options as described below.

Add the ag

-i

, which prints only one possible word.

$hw3 -t 76257 -i < small-dictionary.txt

'rocks'

Add the ag

-h

, which prints out a Unix-like manual page informing the user how to

use your program and its arguments. Also print this screen whenever improper input

has been detected. Also, if there is a -h ag, it cancels out all others, i.e. help screen

will be printed and nothing else.

These ags can come in any order, i.e.

-i -t 53556

is equivalent to

-t 53556 -i

. Any or

all ags may be omitted. If no ags are given, default is -h. Make sure you error-check

your arguments thoroughly, i.e. illegal/badly-formated options.

Note that the input redirection part of the command is NOT considered a commandline

argument. For now, we will input the dictionary through input redirection, later we will

update this program to directly read from a le (after we learn le I/O).

2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

outline some of the current issues facing HR managers

Answered: 1 week ago