| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 420 人关注过本帖
标题:有一个错误,请大家帮我看看啊
只看楼主 加入收藏
b465513006
Rank: 2
等 级:论坛游民
威 望:1
帖 子:70
专家分:48
注 册:2011-3-18
结帖率:73.33%
收藏
已结贴  问题点数:35 回复次数:2 
有一个错误,请大家帮我看看啊
虽然有点长,但是不难,把代码复制到vs上,然后编译就会出错,找不出那个错误是什么原因引起的,这是个商品管理系统
#include<iostream>
#include<string>
#include<vector>
using namespace std;

#ifdef __cplusplus
extern "C"
#endif
FILE _iob[3] = {__iob_func()[0], __iob_func()[1], __iob_func()[2]};


/*
供应商类
*/
class Saleman {
    int no;
    string name;
    long tel;
public:
    Saleman(int no, string name, long tel) {
        this->name = name;
        this->no = no;
        this->tel = tel;
    }
    Saleman() {}
    string getName() {return name;}
    void setName(string name) {this->name = name;}
    int getNo() {return no;}
    void setNo(int no) {this->no = no;}
    long getTel() {return tel;}
    void setTel(long tel) {this->tel = tel;}
};

vector<Saleman> saleman;//商人容器

/*
商品类型类
*/
class Category {
    string name;
public:
    Category(string name) {
        this->name = name;
    }
    Category(){}
    string getName() {return name;}
    void setName(string name) {this->name = name;}
};

vector<Category> category;//商品类型容器

/*
商品类
*/
class Goods {
    int no;
    string name;
    double price;
    Category cate;
    Saleman sale;
public:
    Goods();
    Goods(int no, string name, Category cate, double price, Saleman sale) {
        this->cate = cate;
        this->name = name;
        this->no = no;
        this->price = price;
        this->sale = sale;
    }
    bool add(int, string, Category, double, Saleman);
    int getNo() {return no;}
    void setNo(int no) {this->no = no;}
    string getName() {return name;}
    void setName() {this->name = name;}
    double getPrice() {return price;}
    void setPrice(double price) {this->price = price;}
    Category getCategory() {return cate;}
    void setCategory(Category cate) {this->cate = cate;}
    Saleman getSaleman() {return sale;}
    void setSaleman(Saleman sale) {this->sale = sale;}

};

vector<Goods> goods;//商人容器

Goods findGoods(int no) {
    Goods g;
    g.setNo(-1);
    vector<Goods>::iterator iter = goods.begin();
    int i = 0;
    for(; iter != goods.end(); iter++) {
        if(goods.at(i).getNo() == no) {
            g = goods.at(i);
            return g;
        }
        i++;
    }
    return g;
}

Saleman findSaleman(int no) {
    Saleman s;
    s.setNo(-1);
    vector<Saleman>::iterator iter = saleman.begin();
    int i = 0;
    for(; iter != saleman.end(); iter++) {
        if(saleman.at(i).getNo() == no) {
            s = saleman.at(i);
            return s;
        }
        i++;
    }
    return s;
}

Category findCategory(string name) {
    Category c;
    c.setName("-1");
    vector<Category>::iterator iter = category.begin();
    int i = 0;
    for(; iter != category.end(); iter++) {
        if(category.at(i).getName() == name) {
            c = category.at(i);
            return c;
        }
        i++;
    }
    return c;
}

bool addGoods(int no, string name, Category cate, double price, Saleman sale) {
    Goods g(no, name, cate, price, sale);
    goods.push_back(g);
    cout << "商品添加成功" << endl;
    return true;
}

bool addSaleman(int no, string name, long tel) {
    Saleman s(no, name, tel);
    saleman.push_back(s);
    cout << "供应商添加成功" << endl;
    return true;
}

bool addCategory(string name) {
    Category c(name);
    category.push_back(c);
    cout << "商品类型添加成功" << endl;
    return true;
}

bool eraseGoods(int no) {
    vector<Goods>::iterator iter = goods.begin();
    int i = 0;
    for(; iter != goods.end(); iter++) {
        if(goods.at(i).getNo() == no) {
            goods.erase(iter);
            return true;
        }
        i++;
    }
    cout << "没找到要删除的元素" << endl;
    return false;
}

bool eraseSaleman(int no) {
    vector<Saleman>::iterator iter = saleman.begin();
    int i = 0;
    for(; iter != saleman.end(); iter++){
        if(saleman.at(i).getNo() == no) {
            saleman.erase(iter);
            return true;
        }
        i++;
    }
    cout << "没找到要删除的供应商" << endl;
    return false;
}

bool eraseCategory(string name) {
    vector<Category>::iterator iter = category.begin();
    int i = 0;
    for(; iter != category.end(); iter++) {
        if(category.at(i).getName() == name) {
            category.erase(iter);
            return true;
        }
        i++;
    }
    cout << "没找到要删除的商品类别" << endl;
    return false;
}

bool changeGoods(int n) {
    vector<Goods>::iterator iter = goods.begin();
    int goodsNo, salemanNo;
    string goodsName, salemanName, categoryName;
    Category cate;
    Saleman sale;
    double price;
    cout << "请输入要修改的商品的新信息(编号,名称,商品类别的名称,供应商的编号,价格)" << endl;
    cin >> goodsNo >> goodsName >> categoryName >> salemanNo >> price;
    sale = findSaleman(salemanNo);
    cate = findCategory(categoryName);
    Goods g = findGoods(goodsNo);
    if(sale.getNo() == -1) {
        cout << "未找到您要寻找的供应商的信息,请重新输入或添加此供应商信息" << endl;
        return false;
    }
    if(cate.getName() == "-1") {
        cout << "未找到您要修改的商品的类别,请重新输入或者添加此商品类别信息" << endl;
        return false;
    }
    if(g.getNo() != -1) {
        cout << "该编号已经存在商品,请重新输入" << endl;
        return false;
    }
    int i = 0;
    Goods g1(goodsNo, goodsName, cate, price, sale);
    for(; iter != goods.end(); iter++) {
        if(goods.at(i).getNo() == n) {
            goods.at(i) = g1;
            return true;
        }
        i++;
    }
    return false;
}

bool changeSaleman(int n) {
    vector<Saleman>::iterator iter = saleman.begin();
    int salemanNo;
    string salemanName;
    long tel;
    cout << "请输入要修改的供应商的新信息(编号,姓名,电话号码)" << endl;
    cin >> salemanNo >> salemanName >> tel;
    Saleman sale = findSaleman(salemanNo);
    if(sale.getNo() != -1) {
        cout << "此编号已经存在供应商,请重新输入" << endl;
        return false;
    }
    int i = 0;
    Saleman s(salemanNo, salemanName, tel);
    for(; iter != saleman.end(); iter++) {
        if(saleman.at(i).getNo() == n) {
            saleman.at(i) = s;
            return true;
        }
        i++;
    }
    return false;
}

bool changeCategory(string name) {
    vector<Category>::iterator iter = category.begin();
    string categoryName;
    cout << "请输入要修改的商品类型的新信息(名称)" << endl;
    cin >> categoryName;
    Category cate = findCategory(categoryName);
    if(cate.getName() != "-1") {
        cout << "此商品类型已经存在" << endl;
        return false;
    }
    int i= 0;
    Category c(categoryName);
    for(; iter != category.end(); iter++) {
        if(category.at(i).getName() == name) {
            category.at(i) = c;
            return false;
        }
        i++;
    }
    return false;
}

int main() {
    int GoodsNo, saleNo;
    string GoodsName, saleName, cate;
    double price;
    long tel;
    Saleman sale;
    int choose, choose1;
    while(1) {
        cout << "\t\t\t\t商品管理系统\n" << endl;
        cout << "\t\t" << "1.添加商品类" << "\t\t\t" << "2.添加供应商" <<  "3.添加商品" << "\n" << endl;
        cout << "\t\t" << "3.添加供应商" << "\t\t\t" << "4.删除供应商" << "\n" << endl;
        cout << "\t\t" << "5.添加商品" << "\t\t\t" << "6.删除商品" << "\n" << endl;
        cout << "\t\t" << "7.退出系统" <<"\n" << endl;
        cout << "您选择: ";
        cin >> choose;
        cout << "\n";
        if(choose == 1) {
        
        } else if(choose == 2) {
        
        } else if(choose == 3) {
            cout << "请输入要添加的供应商的信息(编号,名称,电话号码)" << endl;
            cin >> saleNo >> saleName >> tel;
            addSaleman(saleNo, saleName, tel);
            while(1) {
                cout << "是否继续添加 1.是 2.否" << endl;
                cin >> choose1;
                if(choose1 == 1) {
                    cout << "请输入要添加的供应商的信息(编号,名称,电话号码)" << endl;
                    cin >> saleNo >> saleName >> tel;
                    addSaleman(saleNo, saleName, tel);
                }
                else break;
            }
        } else if(choose == 4) {
            cout << "请输入要删除的供应商名称: " << endl;
            cin >> saleName;
            while(1) {
                while(1){
                    if(eraseSaleman(saleNo) == true) {
                        break;
                    }
                    cout << "请输入要删除的供应商的名称:" << endl;
                    cin >> saleName;
                }
                cout << "是否继续删除 1.是 2.否" << endl;
                cin >> choose1;
                if(choose1 == 1) {
                    cout << "请输入要删除的供应商名称: " << endl;
                    cin >> saleName;
                    while(1){
                    if(eraseSaleman(saleNo) == true) {
                        break;
                    }
                    cout << "请输入要删除的供应商的名称:" << endl;
                    cin >> saleName;
                    }
                }else break;
            }
        } else if(choose == 5) {
            cout << "请输入要添加的商品的信息(编号,名称,类别,价格,供销商)" << endl;
            cin >> GoodsNo >> GoodsName >> cate >> price >> saleName;
            while(1) {
                while(1) {
                    if(findSaleman(sale.getNo()).getNo() == -1)
                        break;
                    cout << "没有你输入的供应商,请重新添加商品信息或者添加新的供应商" << "\n\n"
                         << "请输入要添加的商品的信息(编号,名称,类别,价格,供销商)" << "\n" << endl;
                    cin >> GoodsNo >> GoodsName >> cate >> price >> saleName;
                }
                addGoods(GoodsNo, GoodsName, cate, price, sale);
                cout << "是否继续添加 1.是 2.否" << endl;
                cin >> choose1;
                if(choose1 == 1){
                    cout << "请输入要添加的商品的信息(编号,名称,类别,价格,供销商)" << endl;
                    cin >> GoodsNo >> GoodsName >> cate >> price >> saleName;
                    while(1) {
                        if(findSaleman(saleNo).getNo() == -1)
                            break;
                        cout << "没有你输入的供应商,请重新添加商品信息或者添加新的供应商" << "\n\n"
                             << "请输入要添加的商品的信息(编号,名称,类别,价格,供销商)" << "\n" << endl;
                        cin >> GoodsNo >> GoodsName >> cate >> price >> saleName;
                    }
                    addGoods(GoodsNo, GoodsName, cate, price, sale);
                } else break;
            }
        } else if(choose == 6) {
            cout << "请输入要删除的商品的编号: " << endl;
            cin >> GoodsNo;
            while(1) {
                while(1){
                    if(eraseGoods(GoodsNo) == true)
                        break;
                    cout << "请输入要删除的商品的编号:" << endl;
                    cin >> GoodsNo;
                }
                cout << "是否继续添加 1.是 2.否" << endl;
                cin >> choose1;
                if(choose1 == 1){
                    cout << "请输入要删除的商品的编号: " << endl;
                    cin >> GoodsNo;
                    while(1){
                    if(eraseGoods(GoodsNo) == true)
                        break;
                    cout << "请输入要删除的商品的编号:" << endl;
                    cin >> GoodsNo;
                    }
                } else break;
            }
        } else if(choose == 7) {
            cout << "欢迎使用本管理系统" << "\n" << endl;   
            break;
        }
    }
}
搜索更多相关主题的帖子: long include public 供应商 
2012-05-26 22:40
天使梦魔
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:37
帖 子:564
专家分:2754
注 册:2007-8-29
收藏
得分:18 
还是贴错误提示吧
2012-05-27 09:46
lknight
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:37
专家分:187
注 册:2008-9-17
收藏
得分:18 
#ifdef __cplusplus
extern "C"
#endif
FILE _iob[3] = {__iob_func()[0], __iob_func()[1], __iob_func()[2]};//你上面代码中这句括号里面的东西是没定义的东西肯定报错


/*
商品类
*/
class Goods {
    int no;
    string name;
    double price;
    Category cate;
    Saleman sale;
public:
   Goods();//这里定义倒是没错,但是如果你在这里不把它作为inline函数的话,后面应该给出Goods函数的实现,要不也肯定报错
    Goods(int no, string name, Category cate, double price, Saleman sale) {
        this->cate = cate;
        this->name = name;
        this->no = no;
        this->price = price;
        this->sale = sale;
    }
    bool add(int, string, Category, double, Saleman);
    int getNo() {return no;}
    void setNo(int no) {this->no = no;}
    string getName() {return name;}
    void setName() {this->name = name;}
    double getPrice() {return price;}
    void setPrice(double price) {this->price = price;}
    Category getCategory() {return cate;}
    void setCategory(Category cate) {this->cate = cate;}
    Saleman getSaleman() {return sale;}
    void setSaleman(Saleman sale) {this->sale = sale;}

};


[ 本帖最后由 lknight 于 2012-5-27 10:56 编辑 ]
2012-05-27 10:54
快速回复:有一个错误,请大家帮我看看啊
数据加载中...
 
   



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

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