Project 7, Program Design Solution

$35.00 $29.05

You'll get a: . zip file solution, download link after Payment

Description

Standard telephone keypads contain the digits 0 through 9. The numbers 2 through 9 each have three letters associated with them, as is indicated by the following table:

Digit

Letter

Digit

Letter

2

A B C

6

M N O

3

D E F

7

P R S

4

G H I

8

T U V

5

J K L

9

W X Y

Write a program that translate seven-letter words in a file to their corresponding phone numbers.

  1. Name your program phone_numbers.c

  2. The program reads the content of the file and translate the seven-letter words into their corresponding phone numbers, then writes the phone numbers to a file with the same name but an added extension of .cvt. For example, if the original file name is

phone_list.txt, then the corresponding phone numbers will be stored in a file named phone_list.txt.cvt. Assume the file name is no more than 100 characters.

Enter the file name: phone_list.txt

Output file name: phone_list.txt.cvt

3. The program should include the following function:

void translate(char *word, char *phone_number);

The function expects word to point to a string containing the seven-letter words to be translated; phone_number represents the pointer pointing to the string storing the phone number. For example, if the word is TAKEOUT, the function will store 8253688 pointed by phone_number.

Before you submit:

1. Compile with –Wall. Be sure it compiles on circe with no errors and no warnings.

gcc –Wall phone_numbers.c

  1. Be sure your Unix source file is read & write protected. Change Unix file permission on Unix:

chmod 600 phone_numbers.c

3. Test your program with the shell scripts on Unix:

chmod +x try_phone_nnumbers

./try_phone_numbers

Total points: 100

    1. A program that does not compile will result in a zero.

    2. Runtime error and compilation warning 5%

    3. Commenting and style 15%

    4. Functionality 80%

  1. (Extra credit: 40 points)

Write a program that reads in a line of text and computes the frequency of the words in the text. Assume that the input contains words separated by white spaces, comma, period, or exclamation point. Sample input/output:

Input: I came, I saw, I conquered!

Output:

I

3

came

1

saw

1

conquered

1

  1. Name your program frequency.c.

  1. Assume input is no longer than 1000 characters. Assume the input contains no more than 1000 words. Assume each word is no more than 50 characters.

  1. Store a word into a string array when it is first encountered. Create a parallel integer array to hold a count of the number of times that each particular word appears in the input. If the word appears in the input multiple time, do not add it to the string array, but make sure to increment the corresponding word frequency counter in the parallel integer array.

  1. You may use any string library functions such as strtok, strcmp, and strcpy.

  1. To read a line of text, use the read_line function in the lecture notes.

Before you submit:

  1. Compile with –Wall. Be sure it compiles on circe with no errors and no warnings.

  1. Be sure your Unix source file is read & write protected. Change Unix file permission on Unix:

chmod 600 frequency.c

3. Test your program with the shell scripts on Unix:

chmod +x try_frequency

./try_frequency

4. Submit frequency.c together with the program for project 7 on Canvas.

Programming Style Guidelines

The major purpose of programming style guidelines is to make programs easy to read and understand. Good programming style helps make it possible for a person knowledgeable in the application area to quickly read a program and understand how it works.

  1. Your program should begin with a comment that briefly summarizes what it does. This comment should also include your name.

  1. In most cases, a function should have a brief comment above its definition describing what it does. Other than that, comments should be written only needed in order for a reader to understand what is happening.

  1. Information to include in the comment for a function: name of the function, purpose of the function, meaning of each parameter, description of return value (if any), description of side effects (if any, such as modifying external variables)

  1. Variable names and function names should be sufficiently descriptive that a knowledgeable reader can easily understand what the variable means and what the

function does. If this is not possible, comments should be added to make the meaning clear.

  1. Use consistent indentation to emphasize block structure.

  1. Full line comments inside function bodies should conform to the indentation of the code where they appear.

  1. Macro definitions (#define) should be used for defining symbolic names for numeric constants. For example: #define PI 3.141592

  1. Use names of moderate length for variables. Most names should be between 2 and 12 letters long.

  1. Use underscores to make compound names easier to read: tot_vol or total_volumn is clearer than totalvolumn.