将 C++ 中的句子转换为 Pig Latin

发布于 2024-12-18 07:50:47 字数 528 浏览 3 评论 0原文

我是一个初学者,我无法找出一种有效或不太复杂的方法来使这个程序工作。

我需要采用数组形式的句子(通过 cin.getline)并编写一个函数,将其转换为第二个数组中的猪拉丁语。

我已经完成输入和第二个数组集的大小,但我遇到了麻烦,因为我想不出一种方法来找到原始数组中单词的开头,将其转换,然后将其放入新数组,而不创建包含 switch 语句的循环,其中每个 case 都包含一堆嵌套循环。

我必须自己创建所有函数,而不使用字符串库文件。

任何帮助、建议、想法或示例将不胜感激。

编辑:

是的,这是一项大学作业,但我不需要答案,我只需要引导到正确的方向,因为我没有想法。

我一直在尝试使用循环来查找每个单词的开头,然后检查该单词的第一个字母是否是元音或辅音,然后使用循环或嵌套循环来移动内容并将其放入新的单词中数组,但我最终使它变得更加复杂。就像,我使用一个循环来查找单词的开头,然后使用一个巨大的 switch 语句来决定 if 是元音还是辅音,然后我最终得到的每种情况都是某种我不需要覆盖的新嵌套循环其本身稍后会进入更大的循环。

I'm a beginner and I cannot figure out an efficient or not overly complicated way make this program work.

I need to take a sentence in the form of an array (via cin.getline) and write a function that converts it into pig latin in a second array.

I have the input done and the size of the second array set, but I'm having trouble in that I can't think of a way to make find the start of the words in the original array, convert it, and put it into the new array without making a loop that contains a switch statement where each case contains a bunch of nested loops.

I have to create all of my functions myself without using a string library file.

Any help, suggestions, ideas, or examples would be appreciated.

edit:

Yes, this is a university assignment, but I don't need the answer I just need to be steered in the proper direction because I'm out of ideas.

I've been trying to use a loop to find the start of each word and then check whether or not the first letter of the word is a vowel or consonant and then use loop or a nested loop to shift things and put it into the new array but I end up making it more complicated. Like, I use a loop to find the start of a word then a HUGE switch statement to decide whether or not if's a vowel or a consonant and then I end up with each case being some kind of new nested loop that I need to not overwrite itself later in the larger loop.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぶ宁プ宁ぶ 2024-12-25 07:50:47

好的,一些随机的想法:

  1. 将一个单词进行猪拉丁化:如果第一个字母是元音,则微不足道;如果没有,找到第一个元音。将字符串分成两部分;输出第二部分加上第一部分加上“ay”。

  2. 要查找辅音,只需测试“不是元音”即可。基本上,您只需要一个 is_vowel() 函数。

  3. 使用std::string。您要做的任何其他事情都不是学习C++。

如果您想剧透,请发表评论。

OK, a few random ideas:

  1. To piglatinze a word: if first letter is a vowel, trivial; if not, find the first vowel. Split the string into two parts; output second part plus first part plus "ay".

  2. To find a consonant, just test for "not a vowel". Basically, you only need one is_vowel() function.

  3. Use std::string. Anything else you'd be doing would not be learning C++.

Leave a comment if you want spoilers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文