Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Please i need help with this Assignment!!!! (http://www.programmingforums.org/showthread.php?t=14679)

dammest Dec 4th, 2007 3:57 AM

Please i need help with this Assignment!!!!
 
Write a filter that divides the input text into sentences.
Remarks:
􀂃 Each sentence sends with one of the following characters: '.", '?', or '!'.
􀂃 Use a special function isSentEnd to detect characters ending a sentence.
The isSentEnd function has the following prototype:
bool isSentEnd(int c);
􀂃 The ending character must be included in the sentence. The new line character '\n' follows immediately.
􀂃 Spaces, tabulation and new line characters separating sentences must be omitted.
􀂃 The maximum allowed length of a sentence is 200 characters. Sentences exceeding the limit must be cut into separate parts.
􀂃 The sequences of white space characters (new line '\n' and tabulation '\t' and a regular space ' ' ) inside a sentence should be replaced by a single space.
Test the program using the redirection of standard input and the test.txt file.
How many sentences have the string xxxx inside?

lectricpharaoh Dec 4th, 2007 4:26 AM

Re: Please i need help with this Assignment!!!!
 
We're not going to do your homework for you. Show us some effort on your part first, and we'll be willing to help (in other words, post some code, explain why it's not working, and we'll take a look).

That said, I have a question for you. How is the isSentEnd() function supposed to work? You pass it an int, but does this int represent the character you're testing (ie, it will return true for '.', '!', and '?', and false for everything else), or is it an index that specifies which character to test? If the former, why isn't it char instead of int? If it's the latter, you might consider using an unsigned type instead.

Now, because I'm nice, I'm going to offer a few suggestions as to how you can approach this, but I'm not posting code for it until you do. First, you need a buffer (array of char) to hold your characters; size it appropriately (hint: don't forget the terminator). Then you want to loop while there is still data to be read, and read in a character each time; you can use various approaches to detect the end-of-file. For each character read, you test it, and add it to the buffer (you'll need to track the current buffer index) as long as there is room, and it's not a whitespace character. If it's a whitespace character, you add a space character to the buffer, unless the previously-read character was also whitespace; in this case, you add nothing to the buffer. If it is an end-of-sentence marker or you have filled up the buffer, you do whatever you need to do with the buffer (I'm assuming print it to the screen, but you didn't say), reset your buffer index, and continue.

If you lay this out on paper first, you'll see it's not very complicated at all. It's even easier if you modularize it by breaking it into multiple functions that you can call from the loop.

Ancient Dragon Dec 4th, 2007 4:28 AM

Re: Please i need help with this Assignment!!!!
 
closed because cross-post at DaniWeb (twice I might add).


All times are GMT -5. The time now is 3:53 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC