hi. you will write a program that prompts the user to input 3 lower -case string
ID: 3529035 • Letter: H
Question
hi. you will write a program that prompts the user to input 3 lower -case strings(of the type string). the program should then report a series os statistics about these strings .Specifically , the program should report which of the three strings is the last alphabetically, which one is the longest in length and finally a concatenation of the three strings( in alphabetical order) HINTS: (1) string concatenation ( the proccesing of appending one string to the back of another) (2) you need to make sure you include the string library. make sure you make good use of if and else statements to make decisions regarding the input string thank youExplanation / Answer
//using no arrays
#include<iostream>
#include<string>
using namespace std;
int main(){
string str1,str2,str3;
string AlphaLast;
string longest;
string combined;
//get 3 strings
cout<<"You would need to enter three lower-case strings separately. ";
cout<<"Enter string #1: ";
getline(cin,str1);
cout<<"Enter string #2: ";
getline(cin,str2);
cout<<"Enter string #3: ";
getline(cin,str3);
//get alpahbetical last
if(str1.compare(str2)>=0 && str1.compare(str3)>=0){//str1 last
AlphaLast=str1;
if(str2.compare(str3)>=0)
combined=str3+str2+str1;
else
combined=str2 + str1 + str1;
}
else if(str2.compare(str1)>=0 && str2.compare(str3)>=0){//srt 2 last
AlphaLast=str2;
if(str3.compare(str1)>=0)
combined=str1 + str3 + str2;
else
combined=str3 + str1 + str2;
}
else{//str3 last
AlphaLast=str3;
if(str1.compare(str2)>=0)
combined=str2 + str1 + str3;
else
combined=str1 + str2 + str3;
}
//get longest
if(str1.length()>str2.length())
longest=str1;
else
longest=str2;
if(longest.length()<str3.length())//if str3 is greater
longest=str3;
//print stats
cout<<"statistics: ";
cout<<"longest string: "<<longest<<endl;
cout<<"alphabetically last: "<<AlphaLast<<endl;
cout<<"concatenation alphaetically: "<<combined;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.