| | |
confused how to begin this program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 3
Reputation:
Solved Threads: 0
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
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
•
•
•
•
int fgetc(FILE* stream);
Returns next character from (input) stream stream, or EOF on end-of-file or error.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> int main(void) { std::ifstream file(__FILE__); std::string word; while ( file >> word ) { std::cout << word << std::endl; } return 0; }
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]
[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!
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
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
•
•
Join Date: Dec 2004
Posts: 3
Reputation:
Solved Threads: 0
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?
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?
•
•
•
•
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?
May 'the Google' be with you!
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: please help me - extremely clueless :(
- Next Thread: System() Function: Info on uses & Description
| Thread Tools | Search this Thread |
api array beginner bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






