Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 14, 2013, 07:00 AM   #1
mnmn
macrumors newbie
 
Join Date: Jan 2013
hep me please

in this code i have to what the comment said i did but i got error can you help me.....
this is my code
Code:
#include "ReadWords.h"

/**
 * Constructor. Opens the file with the given filename.
 * Program exits with an error message if the file does not exist.
 * @param - filename, a C string naming the file to read.
 * After a successful open, the constructor reads the first of the strings,
 * and initialises the eoffound flag.
 */
ReadWords::ReadWords(char *filename)
{   wordfile.open(filename);//open file
    if (!wordfile)
    {   cout << "cannot open " << filename << endl;
        exit(1);
    }
    wordfile >> nextword;
    eoffound = false;
}

/**
 * Closes the file.
 */
void ReadWords::close()
{   wordfile.close();
}

/**
 * Returns true if there is a further word in the file, false if we have reached the
 * end of file.
 * @return - bool - !eof
 * eoffound will have been set by getNextWord
 */
bool ReadWords::isNextWord()
{   return !eoffound;
}

/**
 * Eliminates punctuations at the beginning and the end if any.
 * @param - string to be fixed.
 * @return - string fixed.
 */
string ReadWords::fix(string word)
{   string s=word;
    int len = s.size();
    string answer = "";

    bool t = false;
    for (int i=0; i<len; ++i)
    {   if(isalnum(s[i])) //find the first alphanumeric character and set the boolean t as true
            t=true;

        if(t)
            if(isalnum(s[i]))
                answer += s[i];
            else if(i!=0 && i!=len-1) // if it is not the first and the last, just store it.
               answer += s[i];
    }

    if(answer.size()>0) //remove punctuations at the end of a word, i.e., "sing...."==>>"sing"
    {   int length = answer.size();
        while(!isalnum(answer[--length]))
            answer.erase(length,1); //remove the last character if it is not alphanumeric
    }

    return answer;
}

/**
 * Returns a string, being the next word in the file.
 * @return - string, fixed nextword.
 */
// note that this function could return an empty string
// if the "word" is a sequence of non-alphanumeric characters the fix function will remove everything!

string ReadWords::getNextWord()
{    string word = nextword;
     wordfile >> nextword;

     if(wordfile.eof()) //nextword doesn't exist.
         eoffound=true;

     return  fix(word);
}

/**
 * Returns a string, being the next word in the file that satisfies the filter.
 * @return - string - next word that satisfies the filter, or an empty string if there is no such word
 */
string ReadWords::getNextFilteredWord()
{
    string word = nextword;
    // you have to write the body for this
    // it should loop, calling getNextWord repeatedly until either
    while(1)
    {
      getNextWord();
      //   (a) the word returned by getNextWord satisfies the filter - in which case the word should be returned
      if (fix(word))
      {
          return word;
          }
          // or
    //   (b) the value returned by isNextWord() becomes false - in which case an empty string should be returned
          else if (!eoffound)
          {
              return "";
              }
     }
}


----------

i got error in string ReadWords::getNextFilteredWord() function ???
mnmn is offline   0 Reply With Quote
Old Feb 10, 2013, 06:23 PM   #2
numero
macrumors member
 
Join Date: Jul 2002
Location: OR
Looks like school work to me. In my school if you are caught doing this you are kicked out. Not out of the class. Out of the school. No second chances, no refunds, no diploma. Good luck getting accepted by another school after that.
numero is offline   1 Reply With Quote
Old Feb 11, 2013, 04:35 AM   #3
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
@mnmn - We're going to need to know more. What error are you getting? It looks to me like your "else if (!eoffound)" should be "else if (eoffound)", maybe...

@numero - Since when is asking for help on homework an issue? Asking other people to do it for you is an issue, or asking for help on an exam is an issue, but for help on homework? MR's forums is generally where I stop by when I get stuck on my x86 assembly homework...

Last edited by ArtOfWarfare; Feb 11, 2013 at 04:41 AM.
ArtOfWarfare is offline   0 Reply With Quote
Old Feb 11, 2013, 06:31 AM   #4
LPZ
macrumors 65816
 
Join Date: Jul 2006
Quote:
Originally Posted by ArtOfWarfare View Post
@mnmn - We're going to need to know more. What error are you getting? It looks to me like your "else if (!eoffound)" should be "else if (eoffound)", maybe...
He's long gone. His assignment was due almost a month ago.
LPZ is offline   1 Reply With Quote
Old Feb 11, 2013, 05:09 PM   #5
numero
macrumors member
 
Join Date: Jul 2002
Location: OR
Quote:
Originally Posted by ArtOfWarfare View Post
@numero - Since when is asking for help on homework an issue? Asking other people to do it for you is an issue, or asking for help on an exam is an issue, but for help on homework? MR's forums is generally where I stop by when I get stuck on my x86 assembly homework...
In the academic world I view the, "This is broken. What's wrong?" question completely different than the, "I'm getting a segmentation fault when I blah, blah, blah." In the first case there is no understanding of the problem. Any help will only solve the problem for the assignment, not offer any long-term knowledge. In the second case the student has shown they know what the problem is, but they don't understand what to do about it. I helped plenty of people in the lab when I was in school. I would talk through a problem with anyone. I wouldn't step in and just provide a block of code that fixed their problem.

That was my point. As harsh as it was.
numero is offline   1 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Need hep with the scroll bar tpcollins MacBook Pro 1 Dec 2, 2012 12:48 PM
Website too wide for iPad - any hep out there? magnet1234 Web Design and Development 6 Oct 30, 2012 04:28 PM
Hep !! Does iOS6 map have Offline navigation?? No Data Plan! tomhwcheung iOS 6 15 Jul 14, 2012 11:22 AM
New and need hep with iPhone 4. Wmturner iPhone Tips, Help and Troubleshooting 3 Jun 12, 2012 02:19 PM

Forum Jump

All times are GMT -5. The time now is 07:57 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC