-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuccesfull piglatin program.txt
92 lines (69 loc) · 2.1 KB
/
succesfull piglatin program.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include<bits/stdc++.h>
#include <iostream>
#include <string.h>
using namespace std;
string getword(string&);
string trim(string);
string translatepiglatin(string);
void toUpper(char *);
int main()
{
string str;//user input sentence
string piglatin;// tranlated sentence
//get the input
cout<<"Enter the sentence which you want to translate in pig latin"<<endl;
getline(cin,str);
//translate
while(str.size()>0)
{
//get the word from sentence
string word=getword(str);
// translate word into piglatin
word=translatepiglatin(word);
//add the word to translated string
piglatin +=word+" ";
}
//converting piglatin to uppercase
transform(piglatin.begin(),piglatin.end(),piglatin.begin(), :: toupper);
cout<<piglatin<<endl;
}
string getword(string& str)
{
// use trim function to trim down the extra empty spaces from intial address
str=trim(str);
int i=0;
while(str[i] !=' '&& i<str.size())
i++;
string word=str.substr(0,i);
str.erase(0,i);
return word;
}
string trim(string str)
{
// erase 1 character at index if it is space
while(str[0]==' ')
str.erase(0,1);
return str;
}
string translatepiglatin(string word)
{
//get the first character
char firstc=word[0];
// append firstcharacter to the end of word
word.append(1,firstc);
//append KPU in the end of the word;
word.append("KPU");
//delete the first character from word
word.erase(0,1);
return word;
}
void toUpper(char *input) {
int i = 0;
char c;
while (input[i])
{
c = input[i];
putchar(toupper(c));
i++;
}
}