Question: Assignment 4, String Shortener Instructions In many methods of communication throughout the last century, from telegrams to SMS messages to tweets, there is a benefit

Assignment 4, String Shortener

Instructions

In many methods of communication throughout the last century, from telegrams to SMS messages to tweets, there is a benefit to reducing message length: either the number of characters is limited or using more characters incurs extra cost. Your job in this assignment is to write a program which takes a message as a string and reduces the number of characters it uses in a set way.

The first thing your program will do is ask the user to type a message which will be stored as a String. If the message contains less than 10 characters the program should print This doesnt need shortening! and finish.

Otherwise, the message should be immediately converted to lowercase as this will make processing much easier. The program should then create a string in which every vowel (a, e, i, o, and u) from the message is removed unless the vowel is at the very start of a word (i.e., it is preceded by a space or is the first letter of the message). The program should also remove every repeated non-vowel character (i.e., if a character appears several times in a row it should only appear once at that location).

Finally, the program should output the shortened message, the number of vowels removed, the number of repeated non-vowel characters removed, and how much shorter the shortened message is than the original message. The exact format in which the program should print this information is shown in the sample runs.

Sample Run 1

Type the message to be shortened This message could be a little shorter Shortened message: ths msg cld b a ltl shrtr Repeated letters removed: 2 Vowels removed: 11 Total characters saved: 13

Sample Run 2

Type the message to be shortened Too small This doesn't need shortening!

Sample Run 3

Type the message to be shortened I will arrive in Mississippi really soon Shortened message: i wl arv in mssp rly sn Repeated letters removed: 6 Vowels removed: 11 Total characters saved: 17

Milestones

As you work on this assignment, you can use the milestones below to inform your development process:

Milestone 1: Set up program which takes a string input, returns This doesnt need shortening! if it has less than 10 characters and otherwise converts all the letters to lowercase.

Milestone 2: Write code which counts the number of vowels and creates a string from the current string with all vowels removed.

Milestone 3: Change the code you write for milestone 2 so that if a vowel appears after a space or if it is the first letter of the message it still gets put in the shortened message and does not get counted as being removed.

Milestone 4: Add code which removes any letters which appear immediately after the same letter in the original string and counts the number of such occurrences. Add print statements to the end to print the letters of the shortened message, the number of vowels and repeats removed, and the total number of letters saved.

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!