Amature needs help please!

This is a discussion on Amature needs help please! within the C++ Programming forums, part of the General Programming Boards category; WOW....a lot of people seemed bummed that their school doesn't have computer programming...iwell, 'll be willing to share my class ...

  1. #16
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    WOW....a lot of people seemed bummed that their school doesn't have computer programming...iwell, 'll be willing to share my class with those who are less fortunate to have programming classes over the summer....

  2. #17
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by JoshR
    You'd have to change the if to...

    if charCount is equal to a space or newline or tab or EOF
    Oh yah tab, if charCount is equal to space or tab. Not EOF because the while statement ends when its at the EOF.

    BTW, my school only has 2 computer classes, networking and communications, and computer study, both are just basic crap. No programming classes, the person who said they have c++/java class are lucky.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #18
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by dra
    Not to be an ass or anything but although your code does a few interesting things, it doesn't achieve the topic creator's task which is to count words. althought you could count spaces, then add 1....

    "One Two" <--- one space : 1 + 1 = 2 words. lol. But that's too much work in my opinion.
    He must have editted his post, because he said that he was just giving the topic creator an idea of how to do it, how to count spaces and such will give the topic creator an idea of how to count words. Which is what your topic was like also, to give the topic creator an idea, not give him the complete program.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  4. #19
    *this
    Join Date
    Mar 2005
    Posts
    498
    But...You have to know when the EOF has been found so you can count the last word

  5. #20
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Quote Originally Posted by dra
    althought you could count spaces, then add 1....

    "One Two" <--- one space : 1 + 1 = 2 words.
    Counting spaces does not work.

    How many words are in this file:
    Code:
    one         two          three
    Last edited by Rashakil Fol; 07-10-2005 at 06:12 PM.

  6. #21
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by JoshR
    But...You have to know when the EOF has been found so you can count the last word
    Ohhh yeah you're right you would if you were counting by spaces. In that case I'd use dra's code, count strings, thats the one I was thinking of cause I was playing with that code myself, it works well and easily.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  7. #22
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    dae...how do you write the code if it counts the strings?

  8. #23
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by jaybo684
    dae...how do you write the code if it counts the strings?
    I dont know how I can help without giving you the program, its pretty much exactly what dra's code is:

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main(){
        
        string s;
        int i = 0;
        while ( cin >> s ){
              
              i++;
        }
        
        cout << "You entered " << i << " words.";
    }
    Open the file, and instead of cin.. use the file. I dont know if using a string is more efficient than using a char and counting words based on spaces/tabs/n/and eof, but it works and the code is simple.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  9. #24
    dra
    dra is offline
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166
    Quote Originally Posted by Rashakil Fol
    Counting spaces does not work.

    How many words are in this file:
    Code:
    one         two          three
    it was just a suggestion....

    besides, assuming the sentences are properly written, as in one space between each word, and two after a sentence, he could probably get away with it.

    But even then, it's too much work. Letting the library do all the work is best. lol.
    Last edited by dra; 07-10-2005 at 11:54 PM.

  10. #25
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    5.4 and 5.5 is what I have to do...

    http://www.santarosa.edu/~ssarkar/ci.../cis10/a5.html

  11. #26
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I would just use a char array for 5.5

    technically, you'd be reading it in character by character
    Last edited by major_small; 07-11-2005 at 12:27 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  12. #27
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    With all the "hints" given on this topic and on that actual page, theres a hints link, you should be able to figure it out. Dra's code implimented with what I said to do is 5.4 (with the addition of "asking for the filename to be opened (stored in a string)"). In 5.5 you simply do the same thing but instead of taking a string at a time from the file, take a char (as it says to do), and test if its a space, tab, end of line, or end of file, if it is then you add 1 to wordCount. In addition you could use a char array to store the output for 5.5, but thats pointless for this program as you can simple cout it 1 char at a time as it comes out.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assembly amature question: prog errors
    By geek@02 in forum Tech Board
    Replies: 1
    Last Post: 10-03-2008, 02:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21