Question
C PROGRAMMING AND UNIX COMPILIER: Project Description: In this project, you will design and implement a program to perform any of the following commands on
C PROGRAMMING AND UNIX COMPILIER:
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.
[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.
[append] Append: Prompts the user for a string and adds this string to the end of the current string.
[find] Find: Prompts the user for a string and checks to see if it exists as a sub-word in the current string. If so, prints out the number of times the string entered exists as a sub string.
[replace] Replace: Replace the current string with the output of the last string modification command.
[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: Print the current string in the reverse order, character by character.
[wrev] Word Reverse: Print the current string in the reverse order, word by word.
[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: List 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, you need to display the prompt again on the next line. If the command is invalid, you need to display an error message.
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
Append
The append command takes an argument string and appends it to the end of the current string. The appended string and the old current string are separated by a space. It changes the current string.
cmd> new
Enter new string: This is
cmd> append
Enter string to append: my first string
cmd> list
This is my first string
Before appending a string to the current string, you need to make sure that the length of the new string does not exceed the maximum length of the string (MAX_STR_LEN). If exceeded, an error message should be printed. (No need to provide the testing result on this, but should be considered in the program.)
Find
The find command takes an argument string and checks to see if it occurs as a substring in the current string. If then 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 sub string to find: is
The substring exists 2 times in the current string.
cmd> find
Enter sub string to find: w
The substring 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.
cmd> toggle
tHIS IS MY FIRST STRING
cmd> list
This is my first string
Replace
The replace command takes the resulting string of the last command and copies it into the current string.
cmd> toggle
tHIS IS MY FIRST STRING
cmd> replace
cmd> list
tHIS IS MY FIRST STRING
cmd> toggle
This is my first string
cmd> list
tHIS IS MY FIRST STRING
Reverse
The reverse command prints the current string in reverse order character by character. It doesnt change the current string.
cmd> rev
gnirts tsrif ym si sihT
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
Satistics:
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
Word Reverse
The reverse command prints the current string in reverse order word by word. It doesnt change the current string.
cmd> wrev
string first my is This
Help
The help command prints a list of commands to the screen.
cmd> help
[new] Enter New String
[list] List Current String
[append] Append a String to the End of Current String
[find] Find a String 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
[wrev] Print Current String in Reverse Order Word By Word
[stat] Print Statistics of Current String
[help] Print This Help Screen
[hist] Print a History of Commands Entered
[quit] Quit Program
[palindrome]
History
The history command prints to the screen the last HISTORY_SIZE (defined as a preprocessor constant) commands entered by the user. Each time when a command is entered, 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.
Quit
The quit command terminates the program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started