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.
1
Expert's answer
2013-02-26T09:57:14-0500
// 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();
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;
Comments
Leave a comment