Question

In: Computer Science

Create a program that accepts in a string of 2 or more words. The program then...

Create a program that accepts in a string of 2 or more words. The program then copies the entered string changing the alpha characters into digits representing characters with acsenders, descenders and nonascender/desender characters; uppercase characters should be treated as lower case. The characters with descenders (gjpqy) should be replaced with a 1. The characters with ascenders (dbfhklt) should be replaced with a 2. The rest of the alpha characters should be replaced with a 3. The converted string should then be displayed. The program should also prompt the user if they would like to enter another string. If they answer y or Y, loop back to the beginning of the program. If they answer n or N, exit the program. All user input should be validated. The word string should have at least one space in it. The Yes or No input must be y, Y, n or N. Do not create an SDM for this lab.

Output Layout:

Please enter a string of at least 2 words: Fred

Please enter a string of at least 2 words: Garrett Phelps

Garrett Phelps

1333322 123213

Would you like to enter another string (y or n): q

Would you like to enter another string (y or n): y

Please enter a string of at least 2 words: I'm Doug

I'm Doug

3'3 2331

Would you like to enter another string (y or n): n

bye!

8. Other:

Try replacing the "123" as shown below

'1' can use static_cast(220) '2' can use static_cast(223) '3' can use static_cast(254)


in C++

Solutions

Expert Solution

#include <iostream>

using namespace std;

bool twoWord(string str);

string changer(string str);

intmain(){

                string str1 , str2;

                char c ;

                while(true){

                                while(true){

                                                cout<<"Please enter a string of atleast 2 words:"<<endl;

                                                cin>>str1>>str2;

                                                cout<<changer(str1)<<" "<<changer(str2)<<endl;

                                                break;

                                                }

                                cout<<"would you like to enter another string(y or n)"<<endl; //asking if a user wants to convert more strings.

                                cin>>c;

                                if(c == 'n' || c == 'N'){

                                                cout<<"bye";

                                                break;

                                }

                }

               

}

bool twoWord(string str){ //checking if the words in string are atleast 2.

                for(inti = 0 ; i<str.size() ; i++){

                                if(str[i] == ' '){

                                                return true;

                                }

                }

                return false;

}

string changer(string str){// changing string of with accenders and descenders.

                for(inti = 0 ; i<str.size() ; i++){

                                if(str[i] >= 'A' &&str[i] <= 'z' ){

                                                if(str[i] == 'g' || str[i] == 'j' || str[i] == 'p' || str[i] == 'q' || str[i] == 'y'){

                                                                str[i] = '1';

                                                }

                                                else if(str[i] == 'd' || str[i] == 'b' || str[i] == 'f' || str[i] == 'h' || str[i] == 'k' || str[i] == 'l'|| str[i] == 't' ){

                                                                str[i] = '2';

                                                }

                                                else {

                                                                str[i]='3';

                                                }

                                }

                }

                return str;

}

COMMENT DOWN BELOW FOR ANY QUERIES AND,

LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.


Related Solutions

Write a program that accepts a string and character as input, then counts and displays the...
Write a program that accepts a string and character as input, then counts and displays the number of times that character appears (in upper- or lowercase) in the string. Use C++ Enter a string: mallet Enter a character: a "A" appears 1 time(s) Enter a string: Racecar Enter a character: R "R" appears 2 time(s)
CREATE A NEW Java PROGRAM that demonstrates : 1.1 numeric and 1 string exception 2. Create...
CREATE A NEW Java PROGRAM that demonstrates : 1.1 numeric and 1 string exception 2. Create your own user defined exception, COMMENT it well, and add code so that it is thrown.
Create a method named stringOperations () that accepts a string variable. This method must perform the...
Create a method named stringOperations () that accepts a string variable. This method must perform the following operations:                Split the sentence into an array                Display each element in the array on a seprate line using “ForEach”                Print the first element in the array, using the array syntax                Tell the user where the second word starts                Display the first 3 characters of the second word In your man method, ask the user to enter a sentence...
C++ ONLY WITH COMMENTS Question: Producer / Consumer Create a program where the application accepts 2...
C++ ONLY WITH COMMENTS Question: Producer / Consumer Create a program where the application accepts 2 arguments form the command line. The first one is a number where it is a producer of threads and the second one is number of consumer threads. You are allowed to use vector as a buffer and if so then please consider it as the buffer infinite. The producers will create the widgets and will put them on the buffer however the consumer will...
program c Write a program called filesearch that accepts two command-line arguments: A string A filename...
program c Write a program called filesearch that accepts two command-line arguments: A string A filename If the user did not supply both arguments, the program should display an error message and exit. The program opens the given filename. Each line that contains the given string is displayed. Use the strstr function to search each line for the string. You may assume no line is longer than 255 characters. The matching lines are displayed to standard output (normally the screen).
Your code needs to do the following: Create a function called pigLatin that accepts a string...
Your code needs to do the following: Create a function called pigLatin that accepts a string of English words in the parameter sentence and returns a string of those words translated into Pig Latin. English is translated to Pig Latin by taking the first letter of every word, moving it to the end of the word and adding ‘ay’. For example the sentence “The quick brown fox” becomes “hetay uickqay rownbay oxfay”. You may assume the words in the parameter...
Create program which sorts letters of a string based on ASCII value. The program will then...
Create program which sorts letters of a string based on ASCII value. The program will then print the sorted string to stdout. Use C programming language. - Only use stdio.h - Input prompt should say "Enter string of your choice: " - Remove any newline \n from input string - Implement sorting operation as a function. Should use selection sort algorithm, but you may use a different algorithm - Output should print sorted string on new line Example:     Enter...
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String...
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns the ArrayList in reserve order in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the...
In C++, write a program that accepts a text file of ASCII words from standard input...
In C++, write a program that accepts a text file of ASCII words from standard input and store them and the amount of times the word appears in the file in a hash table using external chaining. Then print the words and their counts sorted based on alphabetical order and print them again in decreasing numerical order based on the amount of times the word appears in the file. Space, tab, and new line all count as space characters. The...
Objective: Create a program that uses the methods in the String and Math classes to do...
Objective: Create a program that uses the methods in the String and Math classes to do the following: Ask the user to enter two nouns Tell the user how many letters the nouns are from eachother in the dictionary. Tell the user the last letter of each of the nouns Tell the user the position of the letter "e" in each of the nouns, -1 if no "e" exists in the word. For full credit, you must use quotations around...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT