Question: Project Description: In this project, you will design and implement a program to perform any of the following commands on strings. The command is chosen

Project Description:

In this project, you will design and implement a program to perform any of the following commands on strings. The command is chosen by typing in the string in square brackets at the input prompt. All the commands are case insensitive.

[new] New String: Prompts the user for a string and stores it as the current string.

Initially the current string is empty.

[list] List: Prints the current string to the screen.

[find] Find: Prompts the user for a character and prints out the number of times the character exists in the current string.

[toggle] Toggle: Prints the current string by toggling the case, i.e., Convert upper case letter to lower case letter and vice versa.

[rev] Reverse: Prints the current string in the reverse order, character by character.

[replace] Replace: Replaces the current string with the output of the last string modification command.

[stat] Statistics: Prints the statistics of the current string in terms of the length of the string, the number of words, the frequency of each letter of the alphabet, etc.

[help] Help: Lists the different commands and their descriptions.

[hist] History: Prints a list of the past N commands to screen.

[quit] Quit: Quits the program.

Project Design:

You program will print a welcome message, and then display a prompt cmd> and wait for the user to enter a command. If the command is an empty command, i.e. the user presses the enter key, or if the command is invalid, you need to display the prompt again on the next line. In the beginning, the current string is empty. To start playing with strings, you need to use the new command to store a new string into the current string.

new

The new command is used to take from the user a new string to play with.

cmd> new

Enter new string: This is my first string

list

The list command will print out the current string to the screen. If the current string is empty, nothing will be displayed.

cmd> list

This is my first string

find

The find command takes an argument character and prints out the number of times it exists in the current string. The find command is case sensitive.

cmd> list

This is my first string cmd> find Enter a character to find: i

Character i exists 4 times in the current string. cmd> find Enter a character to find: w Character w exists 0 times in the current string.

toggle

The toggle command toggles the case of the current string and prints it to the screen. It doesnt change the current string. If the current string is empty, display nothing.

cmd> list

This is my first string cmd> toggle tHIS IS MY FIRST STRING cmd> list

This is my first string

rev

The reverse command prints the current string in reverse order character by character. It doesnt change the current string.

cmd> new

Enter new string: This is my first string

cmd> rev

gnirst tsrif ym si sihT

cmd> list

This is my first string

cmd> new

Enter new string: my string

cmd> rev

gnirts ym

replace

The replace command takes the resulting string of the last string modification command (toggle, rev) and copies the result into the current string.

cmd> new

Enter new string: This is my first string cmd> toggle tHIS IS MY FIRST STRING cmd> replace cmd> list tHIS IS MY FIRST STRING cmd> new

Enter new string: This is my test cmd> list

This is my test

Statistics

The statistics command prints the statistics of the current string in terms of its length in characters, in words, and the frequency of the different characters in the string. cmd> stat Statistics:

length: 23

word: 5

Frequency:

frequency of f: 1

frequency of g: 1

frequency of h: 1

frequency of i: 4

frequency of m: 1

frequency of n: 1

frequency of r: 2

frequency of s: 4

frequency of t: 2

frequency of y: 1

frequency of T: 1

Help

The help command prints a list of commands to the screen.

cmd> help

[new] Enter New String

[list] List Current String

[find] Find the Occurrence of a Character in Current String

[replace] Replace Current String with Output of Last Command

[toggle] Toggle the Case of Current String

[rev] Print Current String in Reverse Order Character By Character

[stat] Print Statistics of Current String

[help] Print This Help Screen

[hist] Print a History of Commands Entered

[quit] Quit Program

History

The history command prints to the screen the last HISTORY_SIZE (defined as a preprocessor constant as 10) commands entered by the user. Each time when a command is entered (except empty command), you should update your history and the current history table size. If the history is full, you should discard the oldest history and insert the newest command into the history. Empty commands are not counted and should not be stored in your history.

Quit

The quit command terminates the program.

Project Requirements:

1. The program must be properly indented and documented.

2. The program must use the required functions as given in the project.

3. The program needs to be thoroughly tested for different cases including normal inputs and error handling cases.

4. The program must provide a makefile such that the program can be build using make command.

5. When submitting your project, please submit an archive of your entire project directory

6. Grading guideline:

-- Correctness of the program 90%

-- Proper indentation and documentation 5%

5% - makefile

Required Header File: You are required to use the following function prototypes (but not limited to these) in your program.

#define MAX_HISTORY_SIZE 10 /*the maximum size of the history*/

#define MAX_STR_LEN 100 /*the maximum size of strings*/

#define MAX_CMD_LEN 10 /*the maximum size of a command*/

/* Print a listing of the different commands */ void printHelp(void);

/* Toggle the case of the string */

void toggleString(const char *current, char *result);

/* Reverse the string character by character*/ void reverseString (const char *current, char *result);

/* Replace the current string with the last result */ void replaceString (char *current, char *result);

/* User inputs a character and prints and number of times it appears in the current string */

void findString (const char *current);

/* Print the statistics of the current string */ void printStatistics (const char *current);

/* Add a command to the history table if command is not empty. If the history table is full, discard the oldest command. Function takes three arguments: history table, the command to be added into the table, and the current history table size. The function returns the updated history size. */

int updateHistory (char history[MAX_HISTORY_SIZE][MAX_CMD_LEN], char command[], int historySize);

/* Print a history of the commands */

void printHistory(char history[MAX_HISTORY_SIZE][MAX_CMD_LEN], int historySize);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!