confused

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 4
Reputation: barbie 2 is an unknown quantity at this point 
Solved Threads: 0
barbie 2 barbie 2 is offline Offline
Newbie Poster

confused

 
0
  #1
Oct 27th, 2007
hi i am writing a program that counts words containing at least 3 different vowels using functions and also input files.i am confused here and don't know what to do.in this program i am to write another function that will output either 1 or 0 when a character is a vowel or not.please help me . this is where i've gotten so far

  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. using namespace std;
  5.  
  6. void vowel(string, string, string)
  7.  
  8. int main()
  9. {
  10. string line,L1,L2,L3;
  11.  
  12. string filename = "vowel.txt";
  13. ifstream inFile;
  14. inFile.open("vowel.txt" , ios::in);
  15.  
  16. if ( !inFile.fail())
  17. {
  18. cout<<"\nThe file has been succesfully opened\n";
  19. }
  20. while(getline(inFile,line))
  21. cout<<line<<endl;
  22.  
  23. vowel(L1, L2, L3);
  24. return 0;
  25. }
  26.  
  27. void vowel(string L1, string L2, string L3)
  28. {
  29. string word;
  30. int count
Last edited by Ancient Dragon; Oct 27th, 2007 at 9:49 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,678
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 263
Lerner Lerner is offline Offline
Posting Virtuoso

Re: confused

 
0
  #2
Oct 27th, 2007
Will the file be one word per line or do you have to parse the line into individual words.

Once you have a single word I'd send it to vowel(). I don't know why you would want to send three strings to vowel(). You don't really need the string word in vowel(). I'd initialize count to zero before I tried to use it. I'd create a string containing all the vowels I'm looking for. Then I'd use a nest loop to compare each letter of the word passed to vowel with each letter in the string of vowels.

PS: Please use code tags when posting code to this board.
Last edited by Lerner; Oct 27th, 2007 at 8:54 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 4
Reputation: barbie 2 is an unknown quantity at this point 
Solved Threads: 0
barbie 2 barbie 2 is offline Offline
Newbie Poster

Re: confused

 
0
  #3
Oct 27th, 2007
i'm supposed to test for three sentences.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,678
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 263
Lerner Lerner is offline Offline
Posting Virtuoso

Re: confused

 
0
  #4
Oct 27th, 2007
So is the file like this:

tweedle dee
Humpty dumpty
Trouble with programming

or like this:

tweedle
dee
humpty
dumpty
Trouble
with
programming
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: confused

 
0
  #5
Oct 27th, 2007
You need to put a return after line 18 is executed because there is no point contuining that function if it fails to open the file.
Last edited by Ancient Dragon; Oct 27th, 2007 at 9:55 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 20
Reputation: tostrinj is an unknown quantity at this point 
Solved Threads: 1
tostrinj's Avatar
tostrinj tostrinj is offline Offline
Newbie Poster

Re: confused

 
0
  #6
Oct 27th, 2007
I have just read the whole thing and I am confused as to what do you have to do here. And I am getting sys. reqs from some crazy manages for a living. So you got to count unique vowels? Can we get an example of the text file? Ancient Dragon is right, got to exit if file is not opened properly, I guess you guys did not study exceptions yet, simple return would do.

Keep in mind, your L1, L2 and L3 are not innitialized and are passed into a your mistery function, that is no good.

While not clearly understanding what do you have to do here, here is my suggestion on how to make at least what you wrote workable:

  1. int main(){
  2. string line,L1,L2,L3;
  3. string filename = "vowel.txt";
  4. ifstream inFile;
  5. inFile.open("vowel.txt" , ios::in);
  6. if ( inFile.fail())
  7. {
  8. cout<<"\nThe file is not there or some other terrible thing had happened in the process
  9. soon we will learn about exceptions and this type of deal would be much easier.\n";
  10. //exiting with -1 would at least indicate that something bad had happened
  11. return -1;
  12. }
  13. cout<<"We are cooking with gas now"<<endl;
  14. //i am not sure on reading a line part, have not touched c++ since school
  15. while(getline(inFile,line))
  16. {
  17. cout<<line<<endl;
  18. //like I mentioned above, your L* are not innitialized
  19. vowel(L1, L2, L3);
  20. return 0;
  21. }
===========================
can you repeat the part of the stuff where you said all about the things?
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