2013-11-03 79 views
0

我有一个关于堆栈问题... 我想写与3stacks一个程序,我想加上每个堆栈作业本(我应该使用数组):这个堆栈有什么问题?

1.创建堆栈 2 。推数 3.pop数 4.显示每个堆栈的顶部

我写的程序,但我遇到这些错误:

错误4错误LNK2019:无法解析的外部符号“公用:整数 __thiscall (函数“public:void __thiscall stack :: Push2(void)”中引用的栈:: IsFull2(void)“(?Is​​Full2 @ stack @@ QAEHXZ)文档\的Visual Studio 2012 \项目\ Project9 \ Project9 \ Source.obj

错误5错误LNK1120:1周未解析的外部 C:\用户\王妃\文件\的Visual Studio 2012 \项目\ Project9 \调试\ Project9 .exe 1

我应该怎么做才能解决这些错误?

#include <iostream> 
using namespace std; 
#define Max 100 
class stack 
{ 
private: 
    int a[Max],b[Max],c[Max]; 
    int sp1,sp2,sp3; 
public: 
    void create1(); 
    void create2(); 
    void create3(); 
    int IsEmpty1(); 
    int IsEmpty2(); 
    int IsEmpty3(); 
    int IsFull1(); 
    int IsFull2(); 
    int IsFull3(); 
    void Push1(); 
    void Push2(); 
    void Push3(); 
    int Pop1(); 
    int Pop2(); 
    int Pop3(); 
    void Top(); 
    void Show();  
    int menu(); 
}; 
//*************************************** 
void stack::create1() 
{ 
    sp1=-1; 
}; 
//*************************************** 

void stack::create2() 
{ 
    sp2=-1; 
} 
//*************************************** 

void stack::create3() 
{ 
    sp3=-1; 
} 
//*************************************** 
int stack::IsEmpty1(){ 
    return sp1==-1; 
} 
//*************************************** 
int stack::IsEmpty2(){ 
    return sp2==-1; 
} 
//*************************************** 
int stack::IsEmpty3(){ 
    return sp3==-1; 
} 
//*************************************** 

int stack::IsFull1() 
{ 
    return sp1==Max-1; 
} 
//*************************************** 
void stack::Push1() 
{ 
    if(IsFull1()) 
     printf("stack is full"); 
    else 
    { 
     int x; 
     cout<<"Enter your number"<<endl; 
     cin>>x; 
     sp1++; 
     a[sp1]=x; 
    } 
} 
//*************************************** 
int stack::Pop1() 
{ 
    if(IsEmpty1()) 
     cout<<"stack is empty"<<endl; 
    else 
    { 
     int x=a[sp1]; 
     sp1--; 
     return x; 
    } 
} 
//*************************************** 
int stack::IsFull3() 
{ 
    return sp3==Max-1; 
} 
//*************************************** 
void stack::Push2() 
{ 
    if(IsFull2()) 
     printf("stack is full"); 
    else 
    { 
     int x; 
     cout<<"Enter your number"<<endl; 
     cin>>x; 
     sp2++; 
     b[sp2]=x; 
    } 
} 
//*************************************** 
int stack::Pop2() 
{ 
    if(IsEmpty2()) 
     cout<<"stack is empty"<<endl; 
    else 
    { 
     int x=b[sp2]; 
     sp2--; 
     return x; 
    } 
} 
//*************************************** 
void stack::Push3() 
{ 
    if(IsFull3()) 
     printf("stack is full"); 
    else 
    { 
     int x; 
     cout<<"Enter your number"<<endl; 
     cin>>x; 
     sp3++; 
     c[sp3]=x; 
    } 
} 
//*************************************** 
int stack::Pop3() 
{ 
    if(IsEmpty3()) 
     cout<<"stack is empty"<<endl; 
    else 
    { 
     int x=c[sp3]; 
     sp3--; 
     return x; 
    } 
} 
//*************************************** 
void stack::Top() 
{ 
    cout<<"the top of first stack"<<a[sp1]<<endl; 
    cout<<"the top of second stack"<<b[sp2]<<endl; 
    cout<<"the top of third stack"<<c[sp3]<<endl; 
} 
//*************************************** 
void stack::Show() 
{ 
    for(int i=0;i<=sp1;i++) 
     cout<<"the members of the first stack:"<<a[i]<<endl; 
    for(int j=0;j<=sp2;j++) 
     cout<<"the members of the second stack:"<<b[j]<<endl; 
    for(int k=0;k<=sp3;k++) 
     cout<<"the members of the third stack:"<<c[k]<<endl; 
} 
//*************************************** 

int stack::menu(){ 
    int x; 
    cout<<"1.Add Item"<<endl; 
    cout<<"2.Delete Item"<<endl; 
    cout<<"3.Get Count"<<endl; 
    cout<<"4.Show stack"<<endl; 
    cout<<"5.Exit"<<endl; 
    cout<<"Enter your choose:"<<endl; 
    cin>>x; 
    return x; 
} 
////*************************************** 
int main() 
{ 
    stack st; 
    st.create1(); 
    st.create2(); 
    st.create3(); 
    while(1) 
    { 
     switch(st.menu()) 
     { 
      case 1: 
       cout<<"first stack:"<<endl; 
       st.Push1(); 
       cout<<"second stack:"<<endl; 
       st.Push2(); 
       cout<<"third stack:"<<endl; 
       st.Push3(); 
       break; 
      case 2: 
       cout<<"first stack:"<<endl; 
       st.Pop1(); 
       cout<<"second stack:"<<endl; 
       st.Pop2(); 
       cout<<"third stack:"<<endl; 
       st.Pop3(); 
       break; 
      case 3: 
       st.Top(); 
       break; 
      case 4: 
       st.Show(); 
       break; 
      case 5: 
       return 0; 
      default: 
       cout<<"incorrect"<<endl; 
     } 
    } 
    return 0; 
} 
+0

定义'IsFull2'。另外,请用相关的平台标签来标记这个问题,显然这是Windows上的C++? – tripleee

+0

是的,它在窗口 – nazila

+1

问:'“我应该怎么做才能解决这些错误?”A:读它们? ('unresolved ... symbol'... int ... stack :: IsFull2') – kfsone

回答

1

完全错误说什么:你没有在你的代码中定义的方法IsFull2,但你使用它的方法stack::Push2里面。您需要编写stack::IsFull2的主体或更改您的代码,以便它不会调用它(然后再删除声明)。