60 515
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #25038 in C++ for hanrik

Question #25038
Write a C++ program that speaks pig-latin. Words in pig-latin taken from English. To form a word in pig-latin, the first letter of the English word beginning with a consonant is removed and added at the end of the word, adding the letters ay after the moved consonant. Words that begin with a vowel are simply appended with ay. Thus, in pig-latin, pig-latis is igpay-atinlay.



Your program will read a sentence. It is to parse the words intro strings. As words are parsed, they are to be converted to pig-latin and printed.
Expert's answer
// Pig Latin.cpp : Defines the entry point forthe console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
//Create class Lisk list
class linklist
{
private:

struct node //Node of list
{
int data; //data of list
node *link; //reference to node link
}*p;

public:

linklist();
void append( int num );//Append strind to lisk list
void add_as_first( int num );// add element as first
void addafter( int c, int num );//add after some element
void del( int num );//delete elevent from list
void display();

};

linklist::linklist()
{
p=NULL;
}
//Functron appent element
void linklist::append(int num)
{
node *q,*t;

if( p == NULL )
{
p = new node;
p->data = num;
p->link = NULL;
}
else
{
q = p;
while( q->link != NULL )
q = q->link;

t = new node;
t->data = num;
t->link = NULL;
q->link = t;
}
}
//Add as first element to list
void linklist::add_as_first(int num)
{
node *q;

q = new node;
q->data = num;
q->link = p;
p = q;
}
//Add elelent after first element in list
void linklist::addafter( int c, int num)
{
node *q,*t;
int i;
for(i=0,q=p;i<c;i++)
{
q = q->link;
if( q == NULL )
{
cout<<"
There are less than "<<c<<"
elements.";
return;
}
}

t = new node;
t->data = num;
t->link = q->link;
q->link = t;
}
//Function delete element
void linklist::del( int num )
{
node *q,*r;
q = p;
if( q->data == num )
{
p = q->link;
delete q;
return;
}

r = q;
while( q!=NULL )
{
if( q->data == num )
{
r->link = q->link;
delete q;
return;
}

r = q;
q = q->link;
}
cout<<"
Element "<<num<<" not Found.";
}
//Display element
void linklist::display()
{
node *q;
cout<<endl;

for( q = p ; q != NULL ; q = q->link )
cout<<endl<<q->data;

}


//Main function
int main() {
char choice;
do{
cout<<"1-Enter String
";
cout<<"2-Exit
";
cout<<"Your choice is ";
cin>>choice;
if(choice=='1'){
string wordToConvert;//String that enter user
int temp;
bool isTrue=false;
string piglatinword;
cout<<"Enter string: ";
cin>>wordToConvert;
linklist wordLisnList;
for(int i=0;i<wordToConvert.length();i++){
wordLisnList.append(i);
}
if(wordToConvert[0]=='a'||
wordToConvert[0]=='e'||
wordToConvert[0]=='i'||
wordToConvert[0]=='o'||
wordToConvert[0]=='u'||
wordToConvert[0]=='1'||
wordToConvert[0]=='2'||
wordToConvert[0]=='3'||
wordToConvert[0]=='4'||
wordToConvert[0]=='5'||
wordToConvert[0]=='6'||
wordToConvert[0]=='7'||
wordToConvert[0]=='8'||
wordToConvert[0]=='9'){
wordToConvert.append("-way");
piglatinword =wordToConvert;
cout<<piglatinword+"
";
}else{
wordToConvert.append("-");
for(int i=0;i<wordToConvert.length();i++){
if(wordToConvert[i]=='a'||
wordToConvert[i]=='e'||
wordToConvert[i]=='i'||
wordToConvert[i]=='o'||
wordToConvert[i]=='u'||
wordToConvert[i]=='y'){
temp = i;
isTrue=true;
break;
}
}
if(isTrue==true){
for(int k=temp;k<wordToConvert.length();k++){
piglatinword+=wordToConvert[k];
}
for(int i=0;i<temp;i++){
piglatinword+=wordToConvert[i];
}
piglatinword.append("ay");
cout<<piglatinword+"
";
}else{
wordToConvert.append("-way");
piglatinword =wordToConvert;
cout<<piglatinword+"
";
}
}
}
}while(choice!='2');
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions