My code does not compile!! Can anyone help me compile c++ code

This is a c++ program about palindromes. It does not compile, and I do not know how to fix it. Please Help!!!

MAIN FILE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include "Stack.h"
using namespace std;

int main() {
    Stack s;
    string str1 = "Kayak", str2;
    for (int i=0;i<str1.length();i++)
    {
        s.push(str1[i]);
    }
    str2 = s.ToString();
    if(str1!=str2)cout<<str1<<"is not a palindrome\n"<< endl;
    else cout<<str1<<"is a palindrome\n"<< endl;
    str2 = "Noon";
    for(int i=0;i<str1.length();i++)
    {
        s.push(str1[i]);
    }
    str2=s.ToString();
    if (str1!=str2)cout<<str1<<"is not a palindrome\n"<< endl;
    else cout<<str1<<"is a palindrome\n"<< endl;
    str2 = "Racecars";
    for (int i=0; i<str1.length();i++)
    {
        s.push(str1[i]);
    }
    str2=s.ToString();
    if(str1!=str2)cout<<str1<<"is not a palindrome\n"<< endl;
    else cout<<str1<<"is a palindrome\n"<< endl;
    str2 = "No word, no bond, row on";
    for (int i=0; i<str1.length();i++)
    {
        s.push(str1[i]);
    }
    str2=s.ToString();
    if (str1!=str2)cout<<str1<<"is not a palindrome\n"<< endl;
    else cout<<str1<<"is a palindrome\n"<< endl;
    {
        s.push(str1[]);
    }

    return 0;
}



Stack Class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <string>
#include "main.cpp"

class Node{
private:
    char data;
    Node* below;
public:
    Node(){
        below = NULL;
    }
    Node(char a, Node * c){
        data = a;
        below = c;
    }
    Node * getBelow()
    {
        return below;
    }
    char getData(){
        return data;
    }
};

class Stack{
private:
    Node * top;
    int size;
public:
    Stack(){
        top = NULL;
        size = 0;
    }
    Stack(char data){
        top = new Node(data, NULL);
        size++;
    }
    push(char data)
    {
        top = new Node (data, top);
        size++;
    }
    char pop()
    {
        Node * temp = top;
        top = top->getBelow();
        char val = temp->getData();
        size--;
        return val;
    }
    ToString(){
        string str=" ";
        while(top){
            str+=pop();
        }
        return str;
    }

};

Last edited on
Stack's push and ToString methods are missing their return values. Should be void push and string ToString
Topic archived. No new replies allowed.