#include
using namespace std;
template<class T,int MaxSize>
class SeqStack
{
T data[MaxSize];
int top;
public:
SeqStack();
void push(T x);
T Pop();
T Top();
bool Empty();
};
template<class T,int MaxSize>
SeqStack<T,MaxSize>::SeqStack()
{
top=-1;
}
template<class T,int MaxSize>
void SeqStack<T,MaxSize>::push(T x)
{
if(topMaxSize-1)
{cerr<<“上溢”;exit(1);}
top++;
data[top]=x;
}
template<class T,int MaxSize>
T SeqStack<T,MaxSize>::Pop()
{
int x;
if(top-1)
{
cerr<<“下溢”;exit(1);
}
x=data[top];
top–;
return x;
}
template<class T,int MaxSize>
T SeqStack<T,MaxSize>::Top()
{
if(top==-1)
{
cerr<<“下溢”;exit(1);
}
return data[top];
}
template<class T,int MaxSize>
bool SeqStack<T,MaxSize>::Empty()
{
return top==-1;
}
void main()
{
int a,x,b=0,c=0,d;
SeqStack<int,1000> s;
while(1)
{
cout<<"请选择你要进行的操作:1,2进制;2,8进制;3,退出."<<endl;
cin>>d;
switch(d)
{
case 1:cout<<"请输入一个十进制数";
cin>>a;{while(a!=0)
{
x=a%2;
s.push(x);
a=a/2;
b++;
}
cout<<"转换二进制为"<<endl;
for(c;c<b;c++)
cout<<s.Pop();}
cout<<endl;
break;
case 2:cout<<"请输入一个十进制数";
cin>>a;
{while(a!=0)
{
x=a%8;
s.push(x);
a=a/8;
b++;
}
cout<<"转换八进制为"<<endl;
for(c;c<b;c++)
cout<<s.Pop();}cout<<endl;break;
case 3:break;
default:cout<<"请输入正确操作的序号:"<<endl;break;
}
if(d==3)
break;
}
}