ITZY_Official 2016-10-09 11:26 采纳率: 0%
浏览 1130
已结题

C++程序为什么一直报错 如何解决这个问题

#include
#include
using namespace std;
const int defaultsize=30;
template
class Stack {
private:
void operator =(const Stack&) {}
Stack(const Stack&) {}

public:
Stack() {}

virtual ~Stack() {}
virtual void clear() = 0;
virtual void push(const E& it) = 0;
virtual E pop() = 0;
virtual const E& topValue() = 0;
virtual int length() = 0;
};
template
class AStack: public Stack {
private:
int maxSize;

int top;

E listArray;

public:
AStack(int size=defaultsize){
maxSize = size;
top = 0;
listArray = new E [size];
}
~AStack(){
delete [] listArray;
}
void clear(){
top = 0;
}

void push(const E& it) {
assert(top!= maxSize);
listArray[top] = it;
top++;
}
E pop(){

assert(top!= 0);
return listArray[--top];
}
int length(){
return top;
}
};
int main(){
int ten=0,x,y,p,fir;
cout<<" 请输入初始进制:";
cin>>x;
cout<<" 请输入初始数值:";
cin>>fir;
cout<<" 请输入目标进制:";
cin>>y;
AStack sta1();
AStack sta2();
while(fir>0){
p=fir%10;
fir/=10;
sta1.push(p);
}
while(sta1.top!=0){
ten+=sta1.pop();
ten
=x;
}
ten/=x;
while(ten>0){
p=ten%y;
ten/=y;
sta2.push(p);
}
while(sta2.top!=0){
cout<<sta2.pop();
}
cout<<endl;
return 0;
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-10-09 14:24
    关注
     #include<iostream>
    #include<cassert>
    using namespace std;
    const int defaultsize=30;
    template <typename E> 
    class Stack {
        private:
            void operator =(const Stack&) {}
            Stack(const Stack&) {}         
        public:
            Stack() {}                      
            virtual ~Stack() {}
            virtual void clear() = 0;
            virtual void push(const E& it) = 0;
            virtual E pop() = 0;
            virtual const E& topValue() = 0;
            virtual int length() = 0;
    };
    template <typename E> 
    class AStack: public Stack<E> {
        private:
            int maxSize;                    
            E *listArray;          
        public:
            int top; 
            AStack(int size=defaultsize){ 
            maxSize = size; 
            top = 0; 
            listArray = new E [size];
            }
            ~AStack(){ 
            delete [] listArray;
            }
            void clear(){
                top = 0;
            }          
            void push(const E& it) {
                assert(top!= maxSize);
                listArray[top] = it;
                top++;
            }
            E pop(){                
                assert(top!= 0);
                return listArray[--top];
            }
            int length(){ 
                return top; 
            }
            const E& topValue()
            {
                assert(top!= 0);
                return listArray[top];
            }
    };
    int main(){
        int ten=0,x,y,p,fir;
        cout<<" 请输入初始进制:";
        cin>>x; 
        cout<<" 请输入初始数值:";
        cin>>fir; 
        cout<<" 请输入目标进制:";
        cin>>y;
        AStack<int> sta1;
        AStack<int> sta2; 
        while(fir>0){
            p=fir%10;
            fir/=10;
            sta1.push(p);
        }
        while(sta1.top!=0){
            ten+=sta1.pop();
            ten*=x;
        }
        ten/=x;
        while(ten>0){
            p=ten%y;
            ten/=y;
            sta2.push(p);
        }
        while(sta2.top!=0){
            cout<<sta2.pop();
        }
        cout<<endl;
        return 0;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波