当前位置: 首页 > 知识库问答 >
问题:

这个堆栈有什么问题?

石博艺
2023-03-14

我有一个关于书库的问题...我想写一个有3个堆栈的程序,我想在每个堆栈上添加这些操作(我应该使用数组):

1.创建堆栈2。按3号。流行音乐4号。显示每个堆栈的顶部

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

错误4错误LNK2019:未解析的外部符号“public:int\u thiscall stack::IsFull2(void)”(?IsFull2@stack@@QAEHXZ)在函数“public:void _thiscall stack::Push2(void)”中引用(?Push2@stack@@QAEXZ)C:\Users\Princess\Documents\Visual Studio 2012\Projects\Project9\Project9\Source。obj

错误5错误LNK1120:1未解决的外部问题C:\用户\公主\文档\Visual Studio 2012\项目\Project9\调试\Project9.exe1

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

#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;
}

共有1个答案

戎永福
2023-03-14

错误的确切含义是:您没有在代码中定义stack::IsFull2方法,而是在stack::Push2方法中使用它。您需要编写stack::IsFull2的主体,或者更改代码,使其不调用它(然后删除声明)。

 类似资料:
  • 问题内容: 我已经为Employee类的父类是抽象的并且父类中的clone()方法是抽象的编写了此克隆方法。我想用此代码复制Employee对象的原始数据类型,而不是复制每个原始数据单独键入,但是此代码在我调用clone()方法的行中有问题。(此代码在Employee类中) 错误是:来自对象类型的方法clone()不可见。 但是我的Employee类在类层次结构中,可以访问Object类中受保护的

  • 我是GraphQL的新手,我正试图做一个突变来从我的数据库中删除一篇文章,但我不知道如何删除。我使用Node.js,猫鼬和GraphQL。 这是我的模式的变异。 这是我在调用API删除文章时使用的查询。 我做错了什么? 我收到一个错误的400请求。消息:“无法查询类型为“变异”的字段“删除”

  • 尝试在每周一8:15运行时间表,我尝试了以下表达式: 我想这意味着: 分钟数:15 小时:8 月日:每隔 月份:每 星期几:仅周一 年份:每 文件:http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html

  • 提示:Extra content at the end of the document这样的错误

  • 下面的代码在执行时会产生堆栈溢出错误。然而,如果移除其中任何一个