程序如下:
#include<iostream.h>
class continual
{
public:
continual(){}
continual(int size):topa(0),bottoma(0),topb(1),bottomb(1),ta(0),tb(0),w(0)
{
a=new double[size];
b=new char[size];
b[0]='\0';
}
~continual()
{
delete []a;
delete []b;
}
void pusha(double q)
{
if(topa-bottoma>100)
{
cout<<"full!"<<endl;
}
else
{
if(topa==bottoma)
{
a[topa]=q;
topa=topa+2;
}
else
{
a[topa]=q;
topa=topa+2;
}
}
}
double popa()
{
if(topa<=bottoma)
{
cout<<"empty!"<<endl;
return 0;
}
else
{
return a[topa-2];
topa=topa-2;
}
}
void pushb(char p)
{
if(topb-bottomb>99)
{
cout<<"full!"<<endl;
}
else
{
if(topb=bottomb)
{
b[topb]=p;
topb=topb+2;
}
else
{
b[topb]=p;
topb=topb+2;
}
}
}
char popb()
{
if(topb<=bottomb)
{
cout<<"empty!"<<endl;
return 0;
}
else
{
return b[topb-2];
topb=topb-2;
}
}
void lianxv()
{
if(topa==0&&topb==1)
{
for(int i=0;i<100;i++)
{
if(i%2==0)
{
double q;
cout<<"请输入要操作的数:"<<endl;
cin>>q;
pusha(q);
ta=ta+1;
w=w+1;
}
if(i%2==1)
{
char p;
cout<<"请输入要进行的符号:"<<endl;
cin>>p;
const char e='e';
if(p==e)
{
break;
}
else
{
pushb(p);
tb=tb+1;
w=w+1;
}
}
}
}
cout<<"要进行操作的式子是:";
for(int j=0;j<w;j=j+2)
{
cout<<a[j];
cout<<b[j+1];
}
cout<<endl;
for(int k=1;k<=2*tb-1;k=k+2)
{
if(b[k]=='*'||b[k]=='/')
{
if(b[k]=='*')
{
a[k-1]=a[k-1]*a[k+1];
for(int d=k+3;d<=2*ta-1;d=d+2)
{
a[d-2]=a[d];
topa=topa-2;
}
for(int e=k+2;e<=2*tb-1;e=e+2)
{
b[e-2]=b[e];
topb=topb-2;
}
}
else
{
a[k-1]=a[k-1]/a[k+1];
for(int d=k+3;d<=2*ta-1;d=d+2)
{
a[d-2]=a[d];
topa=topa-2;
}
for(int e=k+2;e<=2*tb-1;e=e+2)
{
b[e-2]=b[e];
topb=topb-2;
}
}
}
}
for(int h=1;h<=2*tb-1;h=h+2)
{
if(b[h]=='+'||b[h]=='-')
{
if(b[h]=='+')
{
a[h-1]=a[h-1]+a[h+1];
for(int d=h+3;d<=2*ta-1;d=d+2)
{
a[d-2]=a[d];
topa=topa-2;
}
for(int e=h+2;e<=2*tb-1;e=e+2)
{
b[e-2]=b[e];
topb=topb-2;
}
}
else
{
a[h-1]=a[h-1]-a[h+1];
for(int d=h+3;d<=2*ta-1;d=d+2)
{
a[d-2]=a[d];
topa=topa-2;
}
for(int e=h+2;e<=2*tb-1;e=e+2)
{
b[e-2]=b[e];
topb=topb-2;
}
}
}
}
}
private:
int topa;
int topb;
int bottoma;
int bottomb;
int ta;
int tb;
int w;
double *a;
char *b;
};
int main()
{
continual x(100);
x.lianxv();
cout<<x.popa();
return 0;
}
其结果不是我要的结果 肯定哪个地方出错了 我找了好久也没找出来 希望大家帮帮忙 谢谢大家了