Thread: String issues

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    4

    String issues

    The following paragraph contains my main problem, though I have four others that I am unable to find help with in simple tutorials at the bottom of this post, I will greatly appreciate any help.

    Hello, I'm relatively new to c++ and may therefore may have a few foolish questions while I am attempting to work on a program that is a sort of basic AI interface. I would like to know how to have the program respond to user input that is set to a string variable as an entire sentence, or rather, how to equate an entire sentence with a string. As the user inputs data, I use cin >> my_string to attempt to set the sentence or words input as my_string. Then, when I tell the program to evaluate the string, it has no problem if it is a single word if I have already set this specific character arrangement to a string it should be looking for... If will almost certainly be easier for the problem to be seen in my block of code, which is only a very basic structure at present. it is as follows:
    Code:
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    #include <string>
    using namespace std;
    int main (int nNumberofArgs, char* pszArgs[])
    {
    //define some strings (present tense)
    //punctuation
    string period = ".";
    string comma = ",";
    string semicolon = ";";
    string sp = " ";
    //greetings (meant to be single line or sentence)
    string Hello = "Hello";
    string hello = "hello";
    string Good_morning = "Good morning";
    string good_morning = "good morning";
    //dismissals
    string Goodbye = "Goodbye";
    string goodbye = "goodbye";
    //articles
    string a = "a";
    //nouns
    string cat = "cat";
    //verbs
    string jump = "jump";
    //sentences (need to determine classes, and how to select from classes)
    //unser input sentences
    string s1;
    string s2;
    string s3;
    string s4;
    string s5;
    string s6;
    string s7;
    string s8;
    string s9;
    string s10;
    //output sentence strings
    string o1 = Hello;//tell to choose random greeting eventually (non-time based)
    string o2;
    string o3;
    string o4;
    string o5;
    string o6;
    string o7;
    string o8;
    string o9;
    string o10;
    // loop ints and such
    int l1 = 0;
    //begin program
    cin >> s1;
    //a newline must not be started until the first cin is reflected upon.
    if (s1==Hello+period||s1==Hello||s1==hello+period||s1==hello)  //if s1 is a greeting, then output nothing additional, otherwise reflect. (move to loop below)
    {
    cout << Hello+period << endl;
    }
    else
    {
    cout << Hello+semicolon;
    }
    //must insert something similar to loop here, to finish else statement evaluation of input
    while ( l1 < 10 ) {// loop stops if l1 is greater than 10
    cin >> s2;
    s3=s2;
    s4=s3;
    s5=s4;
    s6=s5;
    s7=s6;
    s8=s7;
    s9=s8;
    s10=s9;
    if (s3==Goodbye+period||s3==Goodbye||s3==goodbye||s3==goodbye+period) // begin with the most common input type.
    {
    l1 = 11;
    }
    
    else {
    cout << "I am quite sorry, but I am unable to understand your sentence, either\n";
    cout << "because of too great a number of grammatical errors, or because I simply\n";
    cout << "am unable to comprehend the structure or intent of the sentence input.\n";
    }// I now need to move to a whole bunch of if/then statements. inside a loop, these
    }// statements must be able to reflect upon every possible instance of input in
    // reasonably correct english. (FUN!)
    cout << Goodbye+period <<endl;
    
    
    
    system ("PAUSE");
    
    return 0;
    }
    when I input something other than Hello or goodbye if gives me a number of copies of the error sentence corresponding to the number of words.

    I would also like to ask:
    1. are classes able to be refrenced like strings, for example, if I tell the program to respond to the word "animal", and I have a class animal, subclasses dog and cat, would there be any way to take the highest order class, and tell the program to ask which of the sub branches that user wishes to speak about?
    (other than directly writing a response, which cannot automatically update itself as more subclasses are added)
    2.how can I tell the program to create new subclasses based on the input of the user, or is not classes, then strings atleast, for whords which are not already placed into a class (at this point i only want the program to be able to catagorically sort words based on classes I create, or tell it to create)
    3.as for the refrence mentioned in 1, how would I tell the program to respond to a single word input in a sentence, or several words when found togther, not necessarily in the exact same order and syntax as used every time.
    4. How would I tell the program to look for relative symmetry between strings (where a one letter mistake per five words perhaps might seem reasonable in human error, the program only knows exeact symmetry, or none at all, this is usefull in many aspects, but can become (though less than a major concern) a minor annoyance in my particular instance.
    5.where I have s3=s2,s4=s3 and such, should I reverse those? I just realized, that while I meant to keep some eight sentences in a sort of short-term memory, that line of equation may just be immediately putting the value of s2 in all of those variables, and resetting each time the loop makes a...loop. (by reverse I mean to put s10=s9 first, s9=s8, etc.)

    I appreciate the time of anyone who helps to answer any of the preceeding questions.
    Last edited by The_professor; 06-10-2007 at 09:17 PM. Reason: another question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  4. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM