Write a program that inputs two string variables, first and last, each of which
ID: 3531568 • Letter: W
Question
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. Yourprogram should then create a new string that contains the full namein pig latin with the first letter capitalized for the first andlast name. The rules to convert a word into pig latin are asfollows:
1 - If the first letter is a constant, move it to the end and add"ay" to the end.
2 - 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 newstring with the text "Erinway Onesjay" and print it..
?
Explanation / Answer
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char first[20];
char last[20];
bool existVowel;
int length1=0;
int length2=0;
char vowel[5]={'a','e','i','o','u'};
cout<<"enter the first name"<<endl;
cin>>first;
cout<<"enter the last name"<<endl;
cin>>last;
for(int i=0;first[i];i++,length1++)
if((first[i]>='A')&&(first[i]<='Z'))
first[i]=first[i]+32;
for(int i=0;last[i];i++,length2++)
if((last[i]>='A')&&(last[i]<='Z'))
last[i]=last[i]+32;
existVowel=false;
for(int i=0;i<5;i++)
if(first[0]==vowel[i])
{
strcat(first,"way");
existVowel=true;
break;
}
if(existVowel==false)
{
int i;
char temp=first[0];
for(i=0;first[i];i++)
first[i]=first[i+1];
first[length1-1]=temp;
first[length1]='';
strcat(first,"ay");
}
existVowel=false;
for(int i=0;i<5;i++)
if(last[0]==vowel[i])
{
strcat(last,"way");
existVowel=true;
break;
}
if(existVowel==false)
{
char temp=last[0];
int i;
for(i=0;first[i];i++)
last[i]=last[i+1];
last[length2-1]=temp;
last[length2]='';
strcat(last,"ay");
}
first[0]=first[0]-32;
last[0]=last[0]-32;
cout<<first<<" ";
cout<<last;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.