| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 893 人关注过本帖
标题:大虾们帮忙找找问题不知道哪出错了,应该是出在主控程序里面,怎么改呢?
取消只看楼主 加入收藏
tottibuffon
Rank: 2
等 级:论坛游民
帖 子:105
专家分:20
注 册:2009-6-5
结帖率:83.87%
收藏
已结贴  问题点数:20 回复次数:6 
大虾们帮忙找找问题不知道哪出错了,应该是出在主控程序里面,怎么改呢?
程序代码:
#include "stdafx.h"
#include<string>
#include<iostream.h>
#include<assert.h>
#include "SeqStack.h"
#include "SeqQueue.h"
using namespace std;

struct car{
    std::string num;  //定义字符串
    int time;
};

int main(int argc, char* argv[])
{
    int iput,num,time;
    car car1,car2,car3;
    cout<<"************************欢迎进入停车场管理系统***************************"<<endl;
    cout<<"***本系统的收费规则是在停车场内的收费为每小时20元,在通道内停车收费0元***"<<endl;
    cout<<"停车场的停车泊位数为5个(通道泊位为5个):"<<endl;
    SeqStack<struct car> carpart1;
    SeqStack<struct car> carpart2;//备用栈,用来存放出栈的元素
    SeqQueue<struct car> tongdao;
    SeqQueue<struct car> tongdao2;//备用队列,用来存放出队元素
    iput=0;
    while(iput!=5)
    {
        do{
            cout<<"[1]       开 车 进 入                   "<<endl;
            cout<<"[2]       开 车 离 去                   "<<endl;
            cout<<"[3]       输出停车场中所有汽车的车牌号  "<<endl;
            cout<<"[4]       输出候车道上的所有汽车的车牌号"<<endl;
            cout<<"[5]       退出该停车系统                "<<endl;
            cin>>iput;
        }while(iput>5 || iput<1);
        switch(iput){
        case 1:           
            cout<<"请输入入库车牌号"<<endl;
            cin>>num;
            car1.num=num;
            cout<<"请输入入库时间"<<endl;
            cin>>time;
            car1.time=time;
            carpart1.Push(car1);
            if(carpart1.IsFull()==true){
                tongdao.EnQueue(car1);
            }
            if(tongdao.IsFull()==true){
                cout<<"停车场与通道都已经满了"<<endl;
            }
            continue;
        case 2:
            cout<<"请输入离开的车牌号"<<endl;
            cin>>num;
            car2.num=num;
            cout<<"请输入出库时间"<<endl;
            cin>>time;
            car2.time=time;
            carpart1.Pop(car3);
            carpart2.Push(car3);
            while(car3.num!=car2.num){
                carpart1.Pop(car3);
                carpart2.Push(car3);
            }
            if(carpart1.Pop(car3)==false){
                    cout<<"输入的车牌号不存在"<<endl;
            }
            else
            {cout<<"收费为"<<((car2.time-car3.time)*20)<<endl;}
            while(carpatr2.IsEmpty()!=true){
                carpart2.Pop(car3);
                carpart1.Push(car3);
            }
            continue;
        case 3:
            while(carpart1.IsEmpty()!=true){
                carpart1.Pop(car3);
                carpart2.Push(car3);
                cout<<"停车场内车牌为"<<car3.num<<endl;
            }
            while(carpatr2.IsEmpty()!=true){
                carpart2.Pop(car3);
                carpart1.Push(car3);
            }
            if(carpart1.IsEmpty()==true){
                cout<<"停车场内没有车"<<endl;
            }
            continue;
        case 4:
            while(tongdao.IsEmpty()!=true){
                tongdao.EnQueue(car3);
                tongdao2.DeQueue(car3);
                cout<<"通道内车牌为"<<car3.num<<endl;
            }
            while(tongdao2.IsEmpty()!=true){
                tongdao2.DeQueue(car3);
                tongdao1.EnQueue(car3);
            }
            if(tongdao1.IsEmpty()==true){
                cout<<"通道内没有车"<<endl;
            }            continue;
        case 5:
            cout<<"欢迎您再次光临!"<<endl;
            system("PAUSE");

}
}
}
#include <iostream.h>
#include <process.h>
#include<iostream.h>
#include "Queue.h"
#include"SeqStack.h"
template <class KT>
class SeqQueue:public Queue<KT>{
    public:
        SeqQueue(int sz=5);
        ~SeqQueue(){delete[] elements;}
        bool EnQueue(const KT &x);//队列不满,则将x进队,否则溢出
        bool DeQueue(KT &x);
        bool getFront(KT &x);
        void makeEmpty(){front==rear;}
        bool IsEmpty()const{return(front==rear)?true:false;}
        bool IsFull()const{return ((rear+1)%maxSize==front)?true:false;}
        int getSize()const{return (rear-front+maxSize)%maxSize;}
        friend ostream & operator<<(ostream &os,SeqQueue<KT>&Q);
    protected:
        int rear,front;
        KT *elements;
        int maxSize;
};

template<class KT>
SeqQueue<KT>::SeqQueue(int sz):front(0),rear(0),maxSize(sz){
    elements=new KT[maxSize];
    assert(elements!=NULL);
};

template<class KT>
bool SeqQueue<KT>::EnQueue(const T & x){
    if(IsFull() == true)return false;
    elements[rear]=x;
    rear=(rear+1)%maxSize;
    return true;
};

template<class KT>
bool SeqQueue<KT>::DeQueue(KT &x){
    if(IsEmpty()==true)return false;
    x=elements[front];
    front=(front+1)%maxSize;
    return true;
};

template<class KT>
bool SeqQueue<KT>::getFront(KT & x)const{
    if(IsEmpty()==true)return false;
    x=elements[front];
    return true;
};

template <class KT>
ostream& operator<<(ostream& os,SeqQueue<KT>& Q){
    os<<"front="<<Q.front<<",rear="<<Q.rear<<endl;
    for(int i=front;i!=rear;i=(i+1)%maxSize;)
        os<<i<<":"<<Q.elements[i]<<endl;
    return os;
};const int maxSize=5;
enum bl2{nfalse,ntrue};
template <class KT>
class Queue {
public:
    Queue(){};      //构造函数
    ~Queue(){};     //析构函数
    virtual void EnQueue(const KT&x)=0;//新元素x进入队列
    virtual bool DeQueue(KT &x)=0;//队头元素出队列
    virtual bool getFront(KT &x)=0;//读取对头元素的值
    virtual bool IsEmpty()const=0;//判空
    virtual bool IsFull()const=0;//判满
    virtual int getSize()const=0;//求队列元素的个数
};

程序代码:
#include <assert.h>
#include <iostream.h>
#include "stack.h"
#include <process.h>
//const int stackIncreament = 20;   
template <class T>
class SeqStack:stack<T>{       
    public:
        SeqStack(int sz=5);               
        ~SeqStack() {delete []elements;}   
        void Push(const T& x);           
        bool Pop(T& x);
        bool getTop(T& x);
        bool IsEmpty() {return (top == -1) ? true : false;}
        bool IsFull(){return (top == maxSize-1) ? true : false;}
        int getSize(){return top+1;}   
        void MakeEmpty() {top = -1;}
    private:
        T *elements;                       
        int top;                               
        int maxSize;                           
        /*void overflowProcess();*/                   
        };

template <class T>
SeqStack<T>::SeqStack(int sz):top(-1), maxSize (sz) {
            elements = new T[maxSize];           
            assert(elements != NULL);           
        };
/*template <class T>
void SeqStack<T>::overflowProcess() {
    T *newArray = new T[maxSize + stackIncreament];
    if (newArray = NULL) {cerr << "存储分配失败!" << endl; exit(1);}
    for (int i = 0; i <= top; i++) newArray[i] = elements[i];
    maxSize = maxSize + stackIncreament;
    delete []elements;
    elements = newArray;
};   
*/
template <class T>
void SeqStack<T>::Push(const T& x) {  
    if (IsFull()== true ) overflowProcess();   
    elements[++top] = x;                       
};

template <class T>
bool SeqStack<T>::Pop(T& x) {
    if (IsEmpty() == true) return false;       
    x = elements[top--];                   
    return true;                               
};

template <class T>
bool SeqStack<T>::getTop(T& x) {
    if (IsEmpty() == true)
        return false;   
    x=elements[top];                   
    return true;
};const int maxSize2 = 5;
enum bl{mfalse,mtrue};
template <class T>
class Stack {                                //栈的类定义
public:
    Stack(){};                                //构造函数
    virtual void Push(const T& x);        //新元素x进栈
    virtual bool Pop(T& x);                //栈顶元素出栈, 由x返回
    virtual bool getTop(T& x);    //读取栈顶元素, 由x返回
    virtual bool IsEmpty();        //判断栈空否
    virtual bool IsFull();        //判断栈满否
    virtual int getSize();        //计算栈中元素个数           
};

搜索更多相关主题的帖子: 主控 
2010-04-14 22:37
tottibuffon
Rank: 2
等 级:论坛游民
帖 子:105
专家分:20
注 册:2009-6-5
收藏
得分:0 
小弟初学C++,麻烦各位帮忙调试下,谢了
2010-04-14 22:57
tottibuffon
Rank: 2
等 级:论坛游民
帖 子:105
专家分:20
注 册:2009-6-5
收藏
得分:0 
回复 3楼 秀痘魔导士
这位大侠,有QQ吗?我想请教很多问题
2010-04-15 18:48
tottibuffon
Rank: 2
等 级:论坛游民
帖 子:105
专家分:20
注 册:2009-6-5
收藏
得分:0 
回复 3楼 秀痘魔导士
程序代码:
//这里是主控的代码
#include "stdafx.h"
#include<iostream.h>
#include<assert.h>
#include "SeqStack.h"
#include "SeqQueue.h"
int main(int argc, char* argv[])
{
    struct data{
    char *num;  //定义字符串
    int time;
    };
    typedef struct car{
    }CAR;  //定义CAR类型的结构,希望把其传递到template类里面
    int iput,num,time;
    CAR car1,car2,car3;
    cout<<"************************欢迎进入停车场管理系统***************************"<<endl;
    cout<<"***本系统的收费规则是在停车场内的收费为每小时20元,在通道内停车收费0元***"<<endl;
    cout<<"停车场的停车泊位数为5个(通道泊位为5个):"<<endl;
    SeqStack<CAR> carpart1;
    SeqStack<CAR> carpart2;//备用栈,用来存放出栈的元素
    SeqQueue<CAR> tongdao;
    SeqQueue<CAR> tongdao2;//备用队列,用来存放出队元素
    iput=0;
    while(iput!=5)
    {
        do{
            cout<<"[1]       开 车 进 入                   "<<endl;
            cout<<"[2]       开 车 离 去                   "<<endl;
            cout<<"[3]       输出停车场中所有汽车的车牌号  "<<endl;
            cout<<"[4]       输出候车道上的所有汽车的车牌号"<<endl;
            cout<<"[5]       退出该停车系统                "<<endl;
            cin>>iput;
        }while(iput>5 || iput<1);
        switch(iput){
        case 1:           
            cout<<"请输入入库车牌号"<<endl;
            cin>>num;
            car1.num=num;
            cout<<"请输入入库时间"<<endl;
            cin>>time;
            car1.time=time;
            carpart1.Push(car1);
            if(carpart1.IsFull()==true){
                tongdao.EnQueue(car1);
            }
            if(tongdao.IsFull()==true){
                cout<<"停车场与通道都已经满了"<<endl;
            }
            continue;
        case 2:
            cout<<"请输入离开的车牌号"<<endl;
            cin>>num;
            car2.num=num;
            cout<<"请输入出库时间"<<endl;
            cin>>time;
            car2.time=time;
            carpart1.Pop(car3);
            carpart2.Push(car3);
            while(car3.num!=car2.num){
                carpart1.Pop(car3);
                carpart2.Push(car3);
            }
            if(carpart1.Pop(car3)==false){
                    cout<<"输入的车牌号不存在"<<endl;
            }
            else
            {cout<<"收费为"<<((car2.time-car3.time)*20)<<endl;}
            while(carpatr2.IsEmpty()!=true){
                carpart2.Pop(car3);
                carpart1.Push(car3);
            }
            continue;
        case 3:
            while(carpart1.IsEmpty()!=true){
                carpart1.Pop(car3);
                carpart2.Push(car3);
                cout<<"停车场内车牌为"<<car3.num<<endl;
            }
            while(carpatr2.IsEmpty()!=true){
                carpart2.Pop(car3);
                carpart1.Push(car3);
            }
            if(carpart1.IsEmpty()==true){
                cout<<"停车场内没有车"<<endl;
            }
            continue;
        case 4:
            while(tongdao.IsEmpty()!=true){
                tongdao.EnQueue(car3);
                tongdao2.DeQueue(car3);
                cout<<"通道内车牌为"<<car3.num<<endl;
            }
            while(tongdao2.IsEmpty()!=true){
                tongdao2.DeQueue(car3);
                tongdao1.EnQueue(car3);
            }
            if(tongdao1.IsEmpty()==true){
                cout<<"通道内没有车"<<endl;
            }
            continue;
        case 5:
            cout<<"欢迎您再次光临!"<<endl;
            system("PAUSE");

}
}
}
D:\C++\4\停车场\停车场.cpp(22) : error C2926: 'struct main::car' : types with no linkage cannot be used as template arguments
D:\C++\4\停车场\停车场.cpp(22) : error C2079: 'carpart1' uses undefined class 'SeqStack<int>'
D:\C++\4\停车场\停车场.cpp(23) : error C2926: 'struct main::car' : types with no linkage cannot be used as template arguments
D:\C++\4\停车场\停车场.cpp(23) : error C2079: 'carpart2' uses undefined class 'SeqStack<int>'
D:\C++\4\停车场\停车场.cpp(24) : error C2926: 'struct main::car' : types with no linkage cannot be used as template arguments
D:\C++\4\停车场\停车场.cpp(24) : error C2079: 'tongdao' uses undefined class 'SeqQueue<int>'
D:\C++\4\停车场\停车场.cpp(25) : error C2926: 'struct main::car' : types with no linkage cannot be used as template arguments
D:\C++\4\停车场\停车场.cpp(25) : error C2079: 'tongdao2' uses undefined class 'SeqQueue<int>'
D:\C++\4\停车场\停车场.cpp(41) : error C2039: 'num' : is not a member of 'car'
        D:\C++\4\停车场\停车场.cpp(15) : see declaration of 'car'
D:\C++\4\停车场\停车场.cpp(44) : error C2039: 'time' : is not a member of 'car'
        D:\C++\4\停车场\停车场.cpp(15) : see declaration of 'car'
D:\C++\4\停车场\停车场.cpp(45) : error C2228: left of '.Push' must have class/struct/union type
D:\C++\4\停车场\停车场.cpp(46) : error C2228: left of '.IsFull' must have class/struct/union type
D:\C++\4\停车场\停车场.cpp(47) : error C2228: left of '.EnQueue' must have class/struct/union type
D:\C++\4\停车场\停车场.cpp(49) : error C2228: left of '.IsFull' must have class/struct/union type
D:\C++\4\停车场\停车场.cpp(56) : error C2039: 'num' : is not a member of 'car'
        D:\C++\4\停车场\停车场.cpp(15) : see declaration of 'car'
D:\C++\4\停车场\停车场.cpp(59) : error C2039: 'time' : is not a member of 'car'
        D:\C++\4\停车场\停车场.cpp(15) : see declaration of 'car'
D:\C++\4\停车场\停车场.cpp(60) : error C2228: left of '.Pop' must have class/struct/union type
D:\C++\4\停车场\停车场.cpp(61) : error C2228: left of '.Push' must have class/struct/union type
D:\C++\4\停车场\停车场.cpp(62) : error C2039: 'num' : is not a member of 'car'
        D:\C++\4\停车场\停车场.cpp(15) : see declaration of 'car'
D:\C++\4\停车场\停车场.cpp(62) : error C2039: 'num' : is not a member of 'car'
        D:\C++\4\停车场\停车场.cpp(15) : see declaration of 'car'
D:\C++\4\停车场\停车场.cpp(62) : fatal error C1903: unable to recover from previous error(s); stopping compilation
/*这么多的错误-_-!!!!*/
2010-04-15 18:53
tottibuffon
Rank: 2
等 级:论坛游民
帖 子:105
专家分:20
注 册:2009-6-5
收藏
得分:0 
回复 3楼 秀痘魔导士
我想把结构体的实例传到模板去,可是好像不行
2010-04-15 19:08
tottibuffon
Rank: 2
等 级:论坛游民
帖 子:105
专家分:20
注 册:2009-6-5
收藏
得分:0 
,救命啊
2010-04-16 09:29
tottibuffon
Rank: 2
等 级:论坛游民
帖 子:105
专家分:20
注 册:2009-6-5
收藏
得分:0 
回复 8楼 秀痘魔导士
如果想吧结构体放到一个getFront(const T &x)函数里面,该怎么写调用呢?
2010-04-16 12:16
快速回复:大虾们帮忙找找问题不知道哪出错了,应该是出在主控程序里面,怎么改呢 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036195 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved