d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help Me Out > Please :)
12Next
Add Reply New Topic New Poll
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
Jun 10 2012 05:48am
Hey guys, I have an assignment to do but I really don't know how to go about starting it. If anyone can give me some pointers on how to go about starting it please let me know!

My assignment:
Write a c++ program to analyze a stream of text read from a data file and create an output file. The input text consists of words separated by any number of blanks or one of the characters ' - ' or ' ? '. Each sentence tsends with a period or a question mark.

Your program should create an output file that contains modified version of the input text. The input text may be in lower case or uppercase or mixed. Your program should generate a copy of the input text in lowercase where the first word of each sentence begins with an uppercase letter.

Each line of the output should contain approximately but no more than 60 characters. You need to keep track of the character count for the current line and current word. Remember to include the blanks and other punctuation characters in your counts.


Should also provide the following information
Number of sentences in the text
Number of words in the text
Average number of words per sentence


I know its long, but if you can give some help on how to go about doing this I would appreciate it. Thanks
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 10 2012 10:34am
1. read file until you see . or ?
2. as you read, add each word (separated by spaces) to a queue.
3. when you see the punctuation, you know this is your full sentence. capitalize the first word and lower case the rest.
4. the size of this queue is the number of words in this sentence. this answers #2 and #3
5. number of times you repeat this entire loop is the number of sentences. this answers # 1
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
Jun 10 2012 07:36pm
Quote (carteblanche @ Jun 10 2012 11:34am)
1. read file until you see . or ?
2. as you read, add each word (separated by spaces) to a queue.
3. when you see the punctuation, you know this is your full sentence. capitalize the first word and lower case the rest.
4. the size of this queue is the number of words in this sentence. this answers #2 and #3
5. number of times you repeat this entire loop is the number of sentences. this answers # 1



char word[60]; // variable for input value

indata.getline(word, 61, '\n');
cout << word << end;

would this work?

I'm sorry I'm just having issues grasping this
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
Jun 10 2012 09:10pm
so if anyone can answer me


while (!infile.eof())
{
condition that makes letters capital / lowercase?
}


Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
Jun 10 2012 10:00pm
I feel like there is no simple way to do this and my teacher hasnt even gone over any of the suggestions im seeing on google


:wallbash: :wallbash: :wallbash:
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Jun 10 2012 10:16pm
Quote (SlayingWhileInt0xicated @ Jun 11 2012 12:00am)
I feel like there is no simple way to do this and my teacher hasnt even gone over any of the suggestions im seeing on google


:wallbash: :wallbash:  :wallbash:


ill do it for 25 fg


edit:: basically you need a couple vars to hold your data ex: total words, total sentences, avg words per sentence. and then you simply create a loop that reads in the text file character by character (which is the simplest for you seeing how you are already lost). another better more effiecient way is to read in data in chunks and then search your buffer for punctuation. and then calculate everything you need up to the punctuation and once you are done remove everything up to it from the buffer and shift the remaining data down to the beginning of the buffer.


ex: say if the text was


i love big black. do you love black horses? i know i do.

and you read in 10 characters at a time. your logic flow would be

Code
buffer[512]

while(not end of file)
{
buffer = read 10 chars
//buffer is now 'i love big'
if(search punctuation(buffer))
{
  ///punctuation was found
  sentences++;
  //count words in sentence for avg words per sentence.
  remove sentance(buffer) //remove up to the punctuation and shift remander down.
  //buffer now equals ' do'
}
else
{
  buffer = read 10 more chars
  //buffer now equals 'i love big black. do'
}
}


then again this is way to complicated for you and i just suggest go through char by char adding it to the buffer and checking if it equals any of your checks.

This post was edited by AbDuCt on Jun 10 2012 10:33pm
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
Jun 10 2012 10:30pm
Quote (AbDuCt @ Jun 10 2012 11:16pm)
ill do it for 25 fg


nvm he works with C

This post was edited by SlayingWhileInt0xicated on Jun 10 2012 10:36pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 10 2012 11:00pm
Quote (SlayingWhileInt0xicated @ Jun 11 2012 12:30am)
nvm he works with C


for 25 fg, you should take the offer just to get the logic, then convert whatever few snippets need to be corrected.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Jun 10 2012 11:03pm
Quote (carteblanche @ Jun 11 2012 01:00am)
for 25 fg, you should take the offer just to get the logic, then convert whatever few snippets need to be corrected.


slowly explaining him the basic logic.
i dont think he knew how to read a file or something gave him links + simple logic snippets.
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
Jun 10 2012 11:04pm
Quote (carteblanche @ Jun 11 2012 12:00am)
for 25 fg, you should take the offer just to get the logic, then convert whatever few snippets need to be corrected.


problem is abduct is doing everything in C :/
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll