Thread: string

  1. #1
    Registered User
    Join Date
    Sep 2001


    #ifndef WORDUTILS_H
    #define WORDUTILS_H

    #include <string>

    std::string lowercase (const std::string& s);
    // Converts all upper-case alphabetic characters in s to the
    // corresponding lowercase characters.
    // Example: lowercase("ABcdE?") should return "abcde?"

    std::string stem (const std::string& word);
    // Tries to guess the stem form of an English word by applying
    // the following rules: (# and % stand for any consonant, and
    // @ for any vowel [aeiou].
    // If word ends in: replace it by: example:
    // ies y flies => fly
    // ied y carried => carry
    // ier y merrier => merry
    // iest y merriest => merry
    // ##ed # hitted => hit
    // ##ing # hitting => hit
    // ##er # hitter => hit
    // ##est # hottest => hot
    // %@#ed %@#e glided => glide
    // %@#ing %@#e gliding => glide
    // %@#er %@#e glider => glide
    // %@#est %@#e palest => pale
    // #ed # barked => bark
    // #ing # boiling => boil
    // #er # colder => cold
    // #est # coldest => cold
    // #s # things => thing
    // If none of the above rules apply, then the word is assumed to be already
    // in its stem form. This function returns the stem that it guesses.
    // [Note that these really are guesses - it isn't hard to find words on which
    // these rules fail. E.g., "pies"]

    //New functions

    collectMisspelledWords (/* inputs */ targetFile, dictionaryFile,
    /* outputs */ misspellings)
    read dictionaryFile into dictionary;
    open targetFile;
    misspellings = empty;
    while more words in targetFile {
    read word w from targetFile;
    w = LOWERCASE(w);
    if ((w is not in dictionary) &&
    (STEM(w) is not in dictionary))
    add w to misspellings;
    close targetFile;

    The two functions capitalized are new. I am trying to write the bodies for the two string manipulation functions, as declared in the wordutils.h. The two functions should work entirely through the std::string interface - no character arrays.

  2. #2
    Registered User kitten's Avatar
    Join Date
    Aug 2001
    So? What's the problem?
    Making error is human, but for messing things thoroughly it takes a computer

  3. #3
    Registered User
    Join Date
    Aug 2001
    look in your compiler's help section. I believe the STL string class comes equipped with a member function to convert to upper or lower case as desired. If not, the cstring header file (or string.h) should contain the toupper() and tolower() functions so you can convert each char in the string to upper() or lower() cases one at a time.

  4. #4
    Registered User
    Join Date
    Sep 2001


    oops, I need help with writting the body of the 2 new functions without using character arrays.
    Thanks again

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    Do you have code trying to do what is required ?

    What were your specific problems with this assignments ?

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #6
    Registered User
    Join Date
    Sep 2001

    no character arrays

    I am trying to write the code to return the lower case character. Using an array would be great but I cannot. I am trying to work with the islower function. But do I need to write a line of code for every letter? Cout << "islower:\n" << ( islower ('a') ? " a is a " : "a is not a" )
    << " lowercase letter\n"
    cout << "nl converted to lowercase is "
    <<static _cast < char > ( tolower ( 'n' ))

    No clue where to start on the stem code

  7. #7
    Registered User
    Join Date
    Sep 2001
    I'm not sure but I think this will get you started.

    #include "stdafx.h"
    char toUpper( char ch );
    int main() { 
    	char c = toUpper( 'a' );
    	return 0; 
    } // end
    char toUpper( char ch )
    	if( ch > 96 && ch < 122 )//acii values for a to z
    		ch -= 32;// subtract 32 if from a to z becomes uppercase
    	return ch;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM