[urgent]about C++.please help!

Started by
10 comments, last by Yann L 16 years, 1 month ago
This is my assignment question: Small advertisements in newspapers often abbreviate words in order to save space. Typically this is done by removing the vowels from the words except for the vowels if it starts a word. For example, the advertisement "3 bedroomed flat very good condition inspection anytime" would be abreviated to "3 bdrmd flt vry gd cndtn inspctn anytm". Write a program which enables a user to input a string (on a line) and which produces as output the input string with the vowels removed in the manner just described. The program continues until there is no more user input. You may assume that the words in the input string are separated by single space characters and that the string contains at least one character. In your program, you should process the string as a vector of characters and you should not use functions in <string> except for declaring the string variables, outputting strings by using insertion operator (<<), inputting strings by using extraction operator (>>) or function getline() and array subscript operator [] (inside a loop) which allows the string to process as a vector of characters. I have no idea about it .Please help!
Advertisement
If you are unable to propose even a partial solution for this (for instance, reading a string and then outputting it back), then you should follow a C++ course or tutorial, first.

If you are unwilling to propose even a partial solution for this, I see no reason for us to do your homework.
Quote:Original post by ToohrVyk
If you are unable to propose even a partial solution for this (for instance, reading a string and then outputting it back), then you should follow a C++ course or tutorial, first.

If you are unwilling to propose even a partial solution for this, I see no reason for us to do your homework.


you are right.i have designed the algorithm before.But I have some problem.I want to make a function to break down the whole sentense into word and asign it to vector.I don't know how to do.But my author don't allow me to use array.Can you solve these?
Do you really need to store the individual words? The only word-related information you need is whether a letter is at the beginning of a word.
you could read the string into an array then use a loop to filter out the vowles, starting the loop at 1 instead of 0 to skip that first letter.

Also be careful about posting homework questions on here, they usually only will help you if you have 99.999% of the code already written and your just stuck on a section or if its an assignment already turned in and graded your just asking for extra critique.
Another tactic to try would be to break it all down on paper either in a flowchart or pseudocode. Some people would argue that its overkill for a small program but I completely disagree. You can usually figure out a lot better way of solving a problem this way then from writing the code off the top of your head.
Quote:Original post by Chrono1081
you could read the string into an array then use a loop to filter out the vowles, starting the loop at 1 instead of 0 to skip that first letter.

Also be careful about posting homework questions on here, they usually only will help you if you have 99.999% of the code already written and your just stuck on a section or if its an assignment already turned in and graded your just asking for extra critique.


Oh,sry about it.I don't know this forum has this rule.Thanks a lot!
Quote:Original post by Chrono1081
you could read the string into an array then use a loop to filter out the vowles, starting the loop at 1 instead of 0 to skip that first letter.

Also be careful about posting homework questions on here, they usually only will help you if you have 99.999% of the code already written and your just stuck on a section or if its an assignment already turned in and graded your just asking for extra critique.


Oh,sry about it.I don't know this forum has this rule.Since this is my first time to here.Thanks a lot!
It's not easy to help you out without giving the entire solution, but perhaps I can help you start thinking in the right direction.

I assume you already have a way to detect whether a character is a vowel or not. So if the assignment would be remove all the vowels in a sentence that shouldn't pose a problem, right? You'd go through all the characters in a line, see if it's a vowel, and if it is you remove it.

Now the actual question is only slightly more complicated: remove the vowels, unless is starts a word. Your initial idea was to split the line up into words and put them in an array. How would detect a word in a sentence? Probably by looking for a sequence of characters that is preceded by a space (unless it's the very first word). So as you're iterating through the characters in the sentence you encounter the start of a word, you could save and use that information to determine whether you can remove a possible vowel or not.
-delete-

[Edited by - snowman88 on March 1, 2008 12:56:35 PM]

This topic is closed to new replies.

Advertisement