Question

In: Computer Science

use c++ (1) Prompt the user for a string that contains two strings separated by a...

use c++

(1) Prompt the user for a string that contains two strings separated by a comma. (1 pt)

  • Examples of strings that can be accepted:
    • Jill, Allen
    • Jill , Allen
    • Jill,Allen

Ex:

Enter input string:
Jill, Allen


(2) Print an error message if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts)

Ex:

Enter input string:
Jill Allen
Error: No comma in string.

Enter input string:
Jill, Allen


(3) Extract the two words from the input string and remove any spaces. Store the strings in two separate variables and output the strings. (2 pts)

Ex:

Enter input string:
Jill, Allen
First word: Jill
Second word: Allen


(4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit. (2 pts)

Ex:

Enter input string:
Jill, Allen
First word: Jill
Second word: Allen

Enter input string:
Golden , Monkey
First word: Golden
Second word: Monkey

Enter input string:
Washington,DC
First word: Washington
Second word: DC

Enter input string:
q

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

#include<iostream>
#include<iomanip>
#include<sstream>
using namespace std;

int main(){
  
   string fullName;
  
   while(true){
       cout<<"Enter input string:\n";
       getline(cin, fullName,'\n');
      
       if(fullName.find(",")!=string::npos){
           stringstream ss(fullName);
           string firstWord, lastWord;
           getline(ss,firstWord,',');
           getline(ss,lastWord,',');
           cout<<"First word: "<<firstWord<<endl;
           cout<<"Second word: "<<lastWord<<endl;
          
       }else if(fullName.compare("q")==0){
           break;
       }
       else{
           cout<<"Error: No comma in string.\n";
       }
       cout<<endl;
   }


   return 0;
}


Related Solutions

(1) Prompt the user for a string that contains two strings separated by a comma.
(In C)(1) Prompt the user for a string that contains two strings separated by a comma. Examples of strings that can be accepted:Jill, AllenJill , AllenJill,AllenEx:Enter input string: Jill, Allen(2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. Ex:Enter input string: Jill Allen Error: No comma in string. Enter input string: Jill, Allen(3) Extract the two words from the input string and remove any spaces. Store...
(1) Prompt the user for a string that contains two strings separated by a comma. (1...
(1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Print an error message if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts) Ex: Enter input...
6.6 Parsing strings (Java) (1) Prompt the user for a string that contains two strings separated...
6.6 Parsing strings (Java) (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts)...
C code please (1) Prompt the user to enter a string of their choosing. Store the...
C code please (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and...
use c++ (1) Prompt the user for a title for data. Output the title. (1 pt)...
use c++ (1) Prompt the user for a title for data. Output the title. (1 pt) Ex: Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored (2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt) Ex: Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered: Number of novels (3) Prompt the...
*******************In Python please******************* (1) Prompt the user to enter a string of their choosing. Store the...
*******************In Python please******************* (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and more...
In Java please. Prompt the user for two string inputs. Perform the following actions on these...
In Java please. Prompt the user for two string inputs. Perform the following actions on these inputs, and print the result of each action: Part I: Concatenate the two strings into one. Compare the two strings and check whether they are the same (ignore the case). Look up the method equalsIgnoreCase() from Java API Convert all the characters in a string to uppercase Look up the method toUpperCase() from Java API Part II: Replace all the 'd' characters with ‘e'...
Use c programing. Declare a new employee struct. Prompt the user to enter values for two-member...
Use c programing. Declare a new employee struct. Prompt the user to enter values for two-member data of the struct. Store struct data in employee struct. Use the calculate(raise_function) to increase employee salary and store the result in employee structure. Use print_ structure to print employee structure.
6.30 LAB*: Program: Authoring assistant (1) Prompt the user to enter a string of their choosing....
6.30 LAB*: Program: Authoring assistant (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle...
Code in c# Write a recursive method called isReverse(String s1, String s2) that accepts two strings...
Code in c# Write a recursive method called isReverse(String s1, String s2) that accepts two strings as parameters and returns true if the two strings contain the same sequence of characters as each other but in the opposite order and false otherwise. • The recursive function should ignore capitalization. (For example, the call of isReverse("hello", "eLLoH") would return true.) • The empty string, as well as any one letter string, should be its own reverse. Write a driver program that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT