求!帮我解决这个C++程序到底哪错了,急!!!

来源:百度知道 编辑:UC知道 时间:2024/06/17 08:34:09
//定义一个栈类,并创建和使用栈类对象。
#include <iostream.h>
const int MAX=5;
//ing namespace std;

class stack
{
float num[MAX];
int top;
public:
void init(void) {top=0;} //初始化函数
void push(float x)
{
if (top==MAX)
{
cout<<"Stack is full!"<<endl;
return;
};
num[top]=x;
top++;
}
float pop(void)
{
top--;
if (top<0)
{
cout<<"Stack is underflow!"<<endl;
return=0;
};
return num[top];
}
}

main(void)
{
int i;
float x;
stack a,b; //创建对象

a.init(); //对站对象初始化
b.init();

for (i=1;i<=MAX;i++)
a.push(2*i);

for (i=1;i<=MAX;i++)
cout<<a.pop()<<" ";
cout<<endl;

cout<<"please input five numbers."<<

#include <iostream.h>
const int MAX=5;
//ing namespace std;

class stack
{
float num[MAX];
int top;
public:
void init(void) {top=0;} //初始化函数
void push(float x)
{
if (top==MAX)
{
cout<<"Stack is full!"<<endl;
return;
};
num[top]=x;
top++;
}
float pop(void)
{
top--;
if (top<0)
{
cout<<"Stack is underflow!"<<endl;
return 0; //return 不能等于零 要返回零就好了 双击错误就能看到在哪里了~~~
};
return num[top];
}
}

main(void)
{
int i;
float x;
stack a,b; //创建对象

a.init(); //对站对象初始化
b.init();

for (i=1;i<=MAX;i++)
a.push(2*i);

for (i=1;i<=MAX;i++)
cout<<a.pop()<<" ";
cout<<endl;

cout<<"please input five numbers."<<endl;