confused how to begin this program

Reply

Join Date: Dec 2004
Posts: 3
Reputation: mak 23 is an unknown quantity at this point 
Solved Threads: 0
mak 23 mak 23 is offline Offline
Newbie Poster

confused how to begin this program

 
0
  #1
Dec 10th, 2004
i am taking a cpsc 140 class and i'm a little confused how to begin my assignment. Write a C++ program that reads in an unknown number of characters from the a text file, count the number of words, and print each word in reverse to the screen.
Words are delimited by blanks, tabs, newlines and the end of file. Note that mulitple whitespace characters should only count one word. Hint: You can use the get method to enter whitespace . i dont recall what the get method is. if anyone can start me out i would be greatly appreciated. thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 35
Reputation: serfurj is an unknown quantity at this point 
Solved Threads: 2
serfurj's Avatar
serfurj serfurj is offline Offline
Light Poster

Re: confused how to begin this program

 
0
  #2
Dec 10th, 2004
int fgetc(FILE* stream);
Returns next character from (input) stream stream, or EOF on end-of-file or error.
http://www.infosys.utas.edu.au/info/...C/CStdLib.html
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 3
Reputation: mak 23 is an unknown quantity at this point 
Solved Threads: 0
mak 23 mak 23 is offline Offline
Newbie Poster

Re: confused how to begin this program

 
0
  #3
Dec 10th, 2004
could you help me get started on this program. i dont want u write the program for me, i just would like to know what steps i have to take to figure it out on my own
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,303
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 227
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: confused how to begin this program

 
0
  #4
Dec 10th, 2004
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. int main(void)
  6. {
  7. std::ifstream file(__FILE__);
  8. std::string word;
  9. while ( file >> word )
  10. {
  11. std::cout << word << std::endl;
  12. }
  13. return 0;
  14. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,842
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 862
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: confused how to begin this program

 
0
  #5
Dec 11th, 2004
Just a little help ...
[php]// pulls the words out of a text stream
string get_word(istream& in)
{
char ch;
string s;

while(in.get(ch))
{
// these characters separate the words
if (ch == ' ' || ch == ',' || ch == '.' || ch == '\n' || ch == '\t')
break;
s.push_back(ch); // build the word
}
return s;
}
[/php]
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: confused how to begin this program

 
0
  #6
Dec 11th, 2004
steps:
1) order a large amount of coffee
2) order some pizzas
3) kickstart your brain
4) start thinking how you would solve it
5) write down your solution in words on a piece of paper
6) translate that into a flowchart and/or other diagrams
7) translate that into a functional model of your application
8) translate that into code
9) test and fix until working
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 3
Reputation: mak 23 is an unknown quantity at this point 
Solved Threads: 0
mak 23 mak 23 is offline Offline
Newbie Poster

Re: confused how to begin this program

 
0
  #7
Dec 13th, 2004
thanks for all the help..the only thing i cant figure out now is how to put the actual text file in. the text is :

this is a file containing lots of
words with whitespace such as tabs and
endoflines and blanks but no
punctuation
you should be counting the
words and reversing each word before
echoing this tothescreen at the end
print the number of words in the file


is there a way for me to put this in without actually putting all this text in my code?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: confused how to begin this program

 
0
  #8
Dec 13th, 2004
Sure, and that's exactly how you should do it:

Create a textfile on disk.
Read in the file in your program. C(++) has full facilities for reading and writing any kind of file built right into the core language.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,842
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 862
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: confused how to begin this program

 
0
  #9
Dec 13th, 2004
Originally Posted by mak 23
thanks for all the help..the only thing i cant figure out now is how to put the actual text file in. the text is :

this is a file containing lots of
words with whitespace such as tabs and
endoflines and blanks but no
punctuation
you should be counting the
words and reversing each word before
echoing this tothescreen at the end
print the number of words in the file


is there a way for me to put this in without actually putting all this text in my code?
Select the text in your editor and save it as test.txt then read it into your program as a text file. You can separate the text into words with strtok(), setting the appropriate delimiters. It's up to your genius to spell each word in reverse.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC