Read in a single string entered from the keyboard in the form last_name,first_na
ID: 3622052 • Letter: R
Question
Read in a single string entered from the keyboard in the form last_name,first_name with no embedded blanks. A comma separates the two pieces. Have it store this input as a single string (NOTE THAT YOU DON’T HAVE TO READ THE STRING IN 1 CHAR AT A TIME,, BUT SHOULD READ IT IN ALL AT ONCE!)
Break the string up and store the first_name and last_name separately as 2 separate strings.called FIRST and LAST (Have it capitalize the first letter of each if they are not already capitalized)
Have it print out each together with the number of characters in each.
Then have program create a new string called THE_NAME that looks like first_name last_name (Note the blank between the first and last names) Have your program print out THE_NAME
Explanation / Answer
sorry about tha
please rate - thanks
#include <iostream>
#include <cstring>
using namespace std;
int main()
{string input,FIRST,LAST,THE_NAME;
int comma,m,len;
cout<<"Enter last_name,first_name with no embedded blanks. A comma separates the two pieces: ";
getline(cin,input);
cout<<"As input: "<<input<<endl;
len=input.length();
comma=input.find(',',0);
FIRST=input.substr(comma+1,len-comma+1);
LAST=input.substr(0,comma);
FIRST[0]=toupper(FIRST[0]);
LAST[0]=toupper(LAST[0]);
cout<<"Last name: "<<LAST<<"--first name: "<<FIRST<<endl;
THE_NAME=FIRST+" "+LAST+'';
cout<<"last name "<<comma<<" characters--first name "<<len-comma-1<<" characters ";
cout<<"The name: "<<THE_NAME<<endl;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.