Write a program that inputs two string variables first and l

Write a program that inputs two string variables, first and last, each of which the user should enter with his or her name. First, convert both strings to all lowercase Your program should then create a new string that contains the full name in pig Latin with the first letter capitalized for the first and last name The rules to convert a word into pig latin are as follows: If the first letter is a consonant, move it to the end and add \"ay\" to the end. If the first letter is a vowel, add \"way\"\' to the end. For example if the user inputs \"Erin\" for the first name and \"Jones\" for the last name then the program should create a new string with the text \"Erinway Onesjay\" and print it

Solution

#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
string convert(string data){
char vowels[] = {\'a\',\'e\',\'i\',\'o\',\'u\'};
int flag = 1;
// convert to lowercase
transform(data.begin(), data.end(), data.begin(),::tolower);
//check if firstletter is vowel
for(int i=0;i<5;i++){
if(vowels[i]==data[0]){
flag = 0;
break;
}
}
// replace letters
if(flag==1){
int len = data.length();
data = data.substr(1,len) + data[0] + \"ay\";
}
else{
data = data + \"way\";
}
// convert firstchar to uppercase
data[0] = toupper(data[0]);
return data;
}
int main() {
string firstName,lastName,name;
cout<< \"Enter firstName:\";
cin>>firstName;
cout<<\"Enter lastName:\";
cin>>lastName;
name = convert(firstName)+\" \"+convert(lastName);
cout<<name;
}


/*
sample output
Enter firstName: erin
Enter lastName: jones
Erinway Onesjay

*/

 Write a program that inputs two string variables, first and last, each of which the user should enter with his or her name. First, convert both strings to all

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site