Write a program that prompts the user to input a string and then outputs the str
ID: 3632780 • Letter: W
Question
Write a program that prompts the user to input a string and then outputs the string in the pig Latin form. The rules for converting a string into pig Latin form are as follows:a. If the string begins with a vowel, add the string "-way" at the end of the string. for example, the pig Latin form of the string "eye" is "eye-way".
b. If the string does not begin with a vowel, first ass "-" at the end of the string. Then rotate the string one character at a time; that is, move the first character of the string to the end of the string until the first character of the string becomes a vowel. The add the string "ay" at the end. For example, the pig Latin form of the string "There" is "ere-Thay".
c. Strings such as "by" contain no vowels. In cases like this, the letter y can be considered a vowel. So, far this program the vowels are a, e, i, o, u, y. Therefore, the pig Latin form of "by" is "y-bay".
d. Strings such as "1234" contain no vowels. The pig Latin form of the string "1234" is "1234-way". That is, the pig Latin form of a string that has no vowels in it is the string followed by the string "-way".
Your program must store the characters of a string into a linked list and user the function rotate (function to remove the first node of a linked list and put it at the end of the linked list) to rotate the string.
Explanation / Answer
// Latin.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
bool isVowels(char x);
void Vowel(string changed);
void nonVowel(char begin, string end);
void changeLine (string line);
void printHeader();
int main()
{
char ch;
string word, first, line;
printHeader();
cout <<endl;
cout << "Enter a string. ";
cout << "String shows in Pig Latin. ";
cout <<endl;
getline(cin,line);
cout <<endl;
while (line.length()!= 0)
{
changeLine(line);
cout<<endl;
cout<<endl;
cout << "Enter a string . ";
cout << "String shows in Pig Latin. ";
cout <<endl;
getline(cin,line);
}
return 0;
}
bool isVowels(char x)
{
char low_case = tolower (x);
if (low_case == 'a' )
return true;
else if (low_case == 'e' )
return true;
else if ( low_case== 'i' )
return true;
else if (low_case == 'o' )
return true;
else if (low_case == 'u' )
return true;
else
return false;
}
void changeLine (string line)
{
string word, first;
char ch;
while (line.length() !=0)
{
int wordLen = line.find(' ');
if (wordLen >0)
{
word = line.substr(0,wordLen);
first=word.substr(0,1);
ch = first[0];
string notFirst(word,1);
if (isVowels (ch))
{
Vowel(word);
}
else
{
nonVowel(ch,notFirst);
}
line = line.substr(wordLen+1);
}
else
{
word = line;
ch = line[0];
string notFirst(word,1);
if (isVowels (ch))
Vowel(word);
else
nonVowel(ch, notFirst);
line="";
}
}
}
void Vowel(string changed)
{
string newWord;
newWord=changed+"way";
cout<<newWord<<" ";
}
void nonVowel(char begin, string end)
{
string newWord;
newWord=end+begin+"ay";
cout<<newWord<<" ";
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.