Thread: Problem finding error..

  1. #1
    Registered User
    Join Date
    Jul 2013
    Location
    Malaysia
    Posts
    4

    Problem finding error..

    Hi,
    I'm new here.. sorry if this question is funny.i Got this question and answer online..i just want to study it..but when i'm try to compile it, the code got some errors...can anyone help?

    Consider the problem of recognizing whether a particular string is in the language:
    L = { w$w’: w is a possibly empty string of characters other than $, w’ = reverse(w) }.
    Write a C program to determining whether a given string is in L. You must apply stacks to solve this question.


    Output Sample 1:
    Input a string: ABC$CBA
    Result: The above string is in the language


    Output Sample 2:
    Input a string: ABCD$CB
    Result: The above string is not in the language

    Code:
    #include <iostream>
    #include <string>
    #include <stack>
    using namespace std;
    
    
    typedef char StackItemType;
    
    
    class Stack {
    
    
    private:
      stack<StackItemType> s;
    public:
      bool isEmpty() const {
          return s.empty();
      }
    
    
      void push(const StackItemType & v) {
        s.push(v);
      }
    
    
      void pop() {
        s.pop();
      }
    
    
      void pop(StackItemType & stackTop) {
        stackTop = s.top();
        s.pop();
      }
    
    
      void getTop(StackItemType & stackTop) {
        stackTop = s.top();
      }
    
    
      int size() {
        return s.size();
      }
    };
    
    
    // TODO(student9#9#): Write your code here
    // Begin Question
    bool isInTheLanguage(const string & input)
    {
    
    
    
    
    
    
    }
    // End Question
    
    
    int main(int argc, char* argv[])
    {
        string input;
        bool inLanguage = false;
    
    
        cout << "Input a string: ";
        cin >> input;
    
    
        inLanguage = isInTheLanguage(input);
    
    
        if (inLanguage)
        {
            cout << "Result: The above string is in the language" << endl;
        }
        else {
            cout << "Result: The above string is not in the language" << endl;
        }
    
    
        system("PAUSE");
        return 0;
    }
    Last edited by azrey86; 07-08-2013 at 03:33 AM. Reason: forgot the question..

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    161
    Needs to be posted in C++ section, this is 'C'.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Indeed; moved to C++ programming forum.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Jul 2013
    Location
    Malaysia
    Posts
    4
    Quote Originally Posted by laserlight View Post
    Indeed; moved to C++ programming forum.
    Thanks Laserlight..i thougt this is about C.. base on the question..thanks..

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    i thougt this is about C.. base on the question..thanks..
    O_o

    So, this is obviously homework, but I still have a question despite having no intention to provide a solution.

    The question: are you supposed to be writing C or C++?

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  6. #6
    Registered User
    Join Date
    Jul 2013
    Location
    Malaysia
    Posts
    4
    Quote Originally Posted by phantomotap View Post
    O_o

    So, this is obviously homework, but I still have a question despite having no intention to provide a solution.

    The question: are you supposed to be writing C or C++?

    Soma
    i'm sorry this not homework.i got it from internet..just try to compile but it got some errors..
    here the links that i got this -->>
    https://www.google.com.my/url?sa=t&r...rGIs1KAmF4Z2OA
    Last edited by azrey86; 07-08-2013 at 05:32 AM. Reason: typing error

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    If you don't know if it is C or C++, then perhaps you are jumping the gun. I suggest that you forget about this exercise for the time being and learn C or C++, whichever one you choose.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Jul 2013
    Location
    Malaysia
    Posts
    4
    thanks for all...all of u are very nice ..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please help me finding the error... :(
    By fredsilvester93 in forum C Programming
    Replies: 4
    Last Post: 01-04-2012, 01:15 AM
  2. new to C & need help finding parse error
    By dsemel in forum C Programming
    Replies: 3
    Last Post: 02-10-2011, 01:42 AM
  3. Help finding the error
    By C++Noob316 in forum C++ Programming
    Replies: 6
    Last Post: 03-13-2009, 01:16 PM
  4. Need help finding error
    By chorney in forum C++ Programming
    Replies: 13
    Last Post: 01-15-2007, 12:16 AM
  5. Finding out a Parse error
    By Ziionyx in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2003, 01:05 PM