标题:为何不能运行,老显示:fatal error C1083: Cannot open include file: 'cl ...
只看楼主
cjw911
Rank: 1
等 级:新手上路
帖 子:17
专家分:2
注 册:2013-4-9
结帖率:0
已结贴  问题点数:10 回复次数:2 
为何不能运行,老显示:fatal error C1083: Cannot open include file: 'class/Traffic_system.h'
#include <fstream>
#include <iostream>
using namespace std;

#include "class/Traffic_system.h"

int main()
{
    Traffic_system civil_aviation;
    //若文件不存在,则新建文件
    ofstream newfile( "flight information.txt", ios::app );
    if (!newfile)
    {
        cerr << "文件\"flight information.txt\"无法打开!\n";
        exit(2);
    }
    newfile.close();
    int tab;
    while(1)
    {
        cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>欢迎进入航空售票管理系统<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
             << "******    主菜单:                                                   ***********"
             << "******    1——更新航班信息(需管理员身份验证)   2——浏览航班信息  ***********"
             << "******    3——查询航班信息                       4——订票 和 退票  ***********"
             << "******    5——清        屏                       0——退 出  系 统  ***********"
             << "********************************************************************************"
             << "你需要做什么?(选择0~4)" << endl;
        cin >> tab;
        while(!(tab == 1 || tab == 2 || tab == 3 || tab == 4 || tab == 5 || tab == 0))
        {
            cout << "请输入正确选择(0~4):";
            cin >> tab;
        }
        switch(tab)
        {
            case 1:
            {
                civil_aviation.Manage();
                break;
            }           //航线管理
            case 2:
            {
                civil_aviation.Scan();
                break;
            }           //订票办理
            case 3:
            {
                civil_aviation.Search();
                break;
            }           //退票办理
            case 4:
            {
                civil_aviation.BookRefund();
                break;
            }
            case 5: system("cls"); break;
            case 0:return 0;   //退出系统
        }
    }
}

文件——class/Traffic_system.h
#include <vector>

using namespace std;

#include "flight.h"

//用于对文件的操作
class Traffic_system
{
public:
    Traffic_system()
    {
        m_sum = 0;
    }
    void Manage();//管理航班信息
    void Scan();//浏览
    int Search(int invoke = 0);//查询功能
    void BookRefund();//订票和退票
private:
    void Read_file();//读取文件
    void Save_file();//保存文件
private:
    int m_sum;//记录航班数
    vector <Flight> v_array;//航班类数组
};

文件——class/Traffic_system.cpp
#include <fstream>
#include <iostream>

using namespace std;

#include "Traffic_system.h"

//读取文件
void Traffic_system::Read_file()
{
    ifstream file( "flight information.txt");
    if (!file)
    {
        cerr << "文件\"flight information.txt\"无法打开!\n";
        exit(1);
    }
    m_sum = 0;
    while (!file.eof())
    {
        Flight fly;
        v_array.push_back(fly);//
        file >> v_array[m_sum++];
    }
    m_sum--;//
    file.close();
}

//保存文件
void Traffic_system::Save_file()
{
    ofstream file( "flight information.txt" , ios::trunc);
    if (!file)
    {
        cerr << "文件\"flight information.txt\"无法打开!\n";
        exit(2);
    }
    int i = -1;
    while (++i < m_sum)
    {
        if (!v_array[i].If_deleted())
        {
            file << v_array[i];
        }
    }
    file.close();
}

//管理航班信息
void Traffic_system::Manage()
{
    char password[20];//用于存贮密码
    int times = 3;
    cout << "登录系统需验证密码!" << endl;
//验证密码。三次错误后,就自动退出程序
    do
    {
        times--;
        cout << "请输入密码:(默认000)";
        cin >> password;
        if(strcmp(password, "000") == 0)//密码是“000”
        {
            times = -1;
            break;
        }
        else if (times > 0)
        cout << " 密码错误!\n 剩余" << times << "次机会!" << endl;
    }while(times > 0);
    if(times != -1)
    {
        cout << "对不起!\n 您不是管理员! 不能使用此系统!" << endl;
        return;
    }
    system("cls");
    while (1)
    {
        int tab;
        cout << "\n******************************欢迎使用航班信息管理系统**************************\n"
             << "————————————————————————————————————————"
             << "\t**\t >>1——重新创建信息库\t\t >>2——插入信息       **\n\t**\t >>3——修改信息\t\t >>4——删除信息       **\n\t**\t >>5——删除全部\t\t >>0——退出管理       **\n"
             << "————————————————————————————————————————"
             << "你需要做什么?(选择0~5)" << endl;
        cin >> tab;
        while(!(tab == 1 || tab == 2 || tab == 3 || tab == 4 || tab == 5 || tab == 0))
        {
            cout << "请输入正确选择(0~5):";
            cin >> tab;
        }
        switch(tab)
        {
            case 1:
            {
                m_sum = 0;
                Flight fly;
                cout << "请进行信息录入。按“+”结束!\n";
                do
                    v_array.push_back(fly);//
                while (v_array[m_sum++].SetInfo());
                break;
            }
            case 2:
            {
                Read_file();
                Flight fly;
                cout << "请进行信息录入。按“+”结束!\n";
                do
                    v_array.push_back(fly);//
                while (v_array[m_sum++].SetInfo());
                break;
            }
            case 3:
            {
                char fnum[1][18];
                Read_file();
                cout << "请输入您要修改信息的航班号:";
                cin >> fnum[0];
                int i = 0;
                for (; i < m_sum; i++)
                {
                    if (v_array[i].If_match(fnum, '1'))
                    {
                        cout << "该航班的原信息为:\n"
                             << " ———————————————————————————————————————\n"
                             << "丨 航 班 号  丨     起 始 站      丨     终 点 站      丨起飞时间丨票价丨余 票丨"
                             << " ———————————————————————————————————————\n";
                        v_array[i].Display();
                        cout << "请输入正确信息!\n";
                        v_array[i].SetInfo();
                        m_sum++;//保持及总航线数不变
                        break;
                    }
                }
                if (i == m_sum)
                {
                    cout << "抱歉!您要修改的信息不存在!" << endl;
                    return;
                }
                m_sum++;//
                break;
            }
            case 4:
            {
                char fnum[1][18];
                Flight empty;//声明"空"对象,用于删除
                Read_file();
                cout << "请输入您要删除航班的航班号:";
                cin >> fnum[0];
                int i = 0;
                for (; i < m_sum; i++)
                {
                    if (v_array[i].If_match(fnum, '1'))
                    {
                        cout << "您要删除的航班为:\n"
                             << " ———————————————————————————————————————\n"
                             << "丨 航 班 号  丨     起 始 站      丨     终 点 站      丨起飞时间丨票价丨余 票丨"
                             << " ———————————————————————————————————————\n";
                        v_array[i].Display();
                        v_array[i] = empty;
                        m_sum++;//保持及总航线数不变
                        break;
                    }
                }
                if (i == m_sum)
                {
                    cout << "您要删除的信息不存在!" << endl;
                    return;
                }
                break;
            }
            case 5:m_sum = 1; break;
            case 0:return;
        }
        cout << "《确认\\Y》  《取消\\N》\n请选择:";
        char yn;
        do
        {
            cin >> yn;
        }while(!(yn == 'Y' || yn == 'y' || yn == 'N' || yn == 'n' ));
        if(yn == 'Y' || yn == 'y')
        {
            m_sum--;//对应m_sum++
            Save_file();
            cout << "操作成功!" << endl;
        }
    }
}

//浏览
void Traffic_system::Scan()
{
    char c;
    Read_file();
    if (m_sum == 0)
    {
        cout << "暂无信息!请等待管理人员更新!";
        return;
    }
    cout << "\t航班信息表:\n"
         << " ———————————————————————————————————————\n"
         << "丨 航 班 号  丨     起 始 站      丨     终 点 站      丨起飞时间丨票价丨余 票丨"
         << " ———————————————————————————————————————\n";
    for (int i = 0; i < m_sum; i++)
        v_array[i].Display();
    cout << "按任意键返回主菜单!";
    cin >> c;
}

//查询功能
int Traffic_system::Search(int invoke)
{
    int tab;
    Read_file();
    cout << "*************************************************************************\n***    >>1——按航班号查询      >>2——按站点查询      >>0——返回    ***\n*************************************************************************\n请选择(0~2):"
         << endl;
    cin >> tab;
    while(!(tab == 1 || tab == 2 || tab == 0))
    {
        cout << "请输入正确选择(0~2):";
        cin >> tab;
    }
    char str[2][18], ta;
    if (tab == 0)
        return -1;
    else if (tab == 1)
    {
        cout << "请输入航班号:";
        cin >> str[0];
        ta = '1';
    }
    else
    {
        cout << "请输入出发站:";
        cin >> str[0];
        cout << "请输入终点站:";
        cin >> str[1];
        ta = '2';
    }
    for (int i = 0; i < m_sum; i++)
    {
        if (v_array[i].If_match(str, ta))
        {
            cout << "您要查询的结果如下:\n"
                 << " ———————————————————————————————————————\n"
                 << "丨 航 班 号  丨     起 始 站      丨     终 点 站      丨起飞时间丨票价丨余 票丨"
                 << " ———————————————————————————————————————"
                 << endl;
            v_array[i].Display();
            if (invoke == 0)
            {
                cout << "按任意键返回主菜单!";
                char c;
                cin >> c;
            }
            return i;
        }
    }
    cout << "抱歉!您查询的航班不存在!" << endl;
    return -1;
}

//订票和退票
void Traffic_system::BookRefund()
{
    while (1)
    {
        cout
        << "**************************欢迎进入机票服务系统**********************\n\n"
        << "——————————————————————————————————\n"
        << "请选择:\t\t\t\t\t\t\t\t ***\n***\t >>1——订票\t>>2——退票\t>>0——返回主菜单        ***\n"
        << "——————————————————————————————————" << endl;
        int tab;
        cin >> tab;
        while(!(tab == 1 || tab == 2 || tab == 0))
        {
            cout << "请输入正确选择(0~2):";
            cin >> tab;
        }
        char ta;
        switch(tab)
        {
            case 1:
            {
                cout << "请先查找该航班:" << endl;
                int i;
                i = Search(1);
                if (i != -1 && v_array[i].Book())
                {
                    cout << "《确认订票\\Y》  《取消订票\\N》\n请选择:";
                    do
                    {
                        cin >> ta;
                    }while(!(ta == 'Y' || ta == 'y' || ta == 'N' || ta == 'n' ));
                    if(ta == 'Y' || ta == 'y')
                    {
                        Save_file();
                        cout << "订票成功!" << endl;
                    }
                }
                break;
            }
            case 2:
            {
                char str[1][18];
                Read_file();
                cout << "请输入航班号:";
                cin >> str[0];
                int i = 0;
                for (; i < m_sum; i++)
                {
                    if (v_array[i].If_takeoff())
                        continue;
                    if (v_array[i].If_match(str, '1'))
                    {
                        v_array[i].Refund();
                        cout << "《确认退票\\Y》  《取消退票\\N》\n请选择:";
                        do
                        {
                            cin >> ta;
                        }while(!(ta == 'Y' || ta == 'y' || ta == 'N' || ta == 'n' ));
                        if(ta == 'Y' || ta == 'y')
                        {
                            Save_file();
                            cout << "退票成功!" << endl;
                        }
                        break;
                    }
                }
                if (i == m_sum)
                {
                    cout << "不存在该航班或该航班已起飞!不能退票。" << endl;
                    break;
                }
            }
            case 0:return;
        }
    }
}

文件——class/ flight.h
class Flight
{
public:
    Flight()
    {
        m_fnum[0] = '+';
    }
    bool SetInfo();//设置航班信息
    friend istream& operator>>(istream& in, Flight& cp);//提取运算符重载
    friend ostream& operator<<(ostream& out, Flight& cp);//插入运算符重载
    void Display();//输出航班信息
    bool Book();//订票
    void Refund();//退票
    bool If_takeoff();//判断是否起飞
    bool If_deleted();//判断是否删除
    bool If_match(char (*p)[18], char ta);//判断航班号或站点名是否相同
private:
    char m_fnum[10];//航班号
    int m_ftime[2];//起飞时间
    char m_fstar[18];//起始站
    char m_fdestination[18];//终点站
    int m_fprice;//票价
    int m_fseat;//票数
};

文件——class/ flight.cpp
#include <iostream>
#include <string>
#include <iomanip>
#include <ctime>//time.h in C

using namespace std;

#include <stdio.h>
#include "flight.h"

//<<运算符重载
istream& operator>>(istream& in, Flight& cp)
{
    in >> cp.m_fnum >> cp.m_fstar >> cp.m_fdestination >> cp.m_ftime[0] >> cp.m_ftime[1] >> cp.m_fprice >> cp.m_fseat;
    return in;
}

ostream& operator<<(ostream& out, Flight& cp)
{
    out << cp.m_fnum << " " << cp.m_fstar << " " << cp.m_fdestination << " " << cp.m_ftime[0] << " " << cp.m_ftime[1] << " " << cp.m_fprice << " " << cp.m_fseat << "\n";
    return out;
}

//获取系统时间
int get_systemtime()
{
    time_t now;
    struct tm *fmt;
    time(&now);
    fmt = localtime(&now);
    return (fmt->tm_hour * 60 + fmt->tm_min);
}

//判断是否起飞
bool Flight::If_takeoff()
{
    return (m_ftime[0] * 60 + m_ftime[1] <= get_systemtime());
}

//判断是否作废
bool Flight::If_deleted()
{
    return m_fnum[0] == '-';
}

//判断航班号或站点名是否相同
bool Flight::If_match(char (*p)[18], char ta)
{
    if (ta == '1')
        return (!strcmp(m_fnum, p[0]));
    else
        return (!strcmp(m_fstar, p[0]) && !strcmp(m_fdestination, p[1]));
}

//设置航班信息
bool Flight::SetInfo()
{
    cout << "输入航班号:";
    cin >> m_fnum;
    if (m_fnum[0] == '+')
        return false;
    cout << "起始站:";
    cin >> m_fstar;
    cout << "终点站:";
    cin >> m_fdestination;
    cout << "请输入起飞时间:(格式:03:05)";
    scanf("%d:%d",m_ftime, m_ftime + 1);
    cout << "票价:";
    cin >> m_fprice;
    cout << "余票:";
    cin >> m_fseat;
    return true;
}

//输出航班信息
void Flight::Display()
{
    if (If_takeoff())
    {
        cout << "丨 " << setiosflags(ios::left) << setw(10) << m_fnum << "丨 " << setw(18) <<  m_fstar << "丨 " << setw(18) << m_fdestination
             << "丨 " << " 本次航班已经起飞!" << " 丨"
             << " ———————————————————————————————————————"
             << endl;
    }
    else
    {
        cout << "丨 " << setiosflags(ios::left) << setw(10) << m_fnum << "丨 " << setw(18) <<  m_fstar << "丨 " << setw(18) << m_fdestination
             << "丨 " << setiosflags(ios::right) << setw(2) << setfill('0') << m_ftime[0] << ":" << setw(2) << m_ftime[1] << setfill(' ')
             << "  丨" << setw(4) << m_fprice << "丨" << setw(5) << m_fseat << "丨" << resetiosflags(ios::right)
             << " ———————————————————————————————————————"
             << endl;
    }
}

//订票
bool Flight::Book()
{
    if (If_takeoff())
    {
        cout << "该航班已经起飞,停止售票!" << endl;
        return false;
    }
    int count;
    cout << "请输入订购的票数:";
    cin >> count;
    if (m_fseat < count)
    {
        cout << "余票不足!" << endl;
        return false;
    }
    m_fseat -= count;
    return true;
}

//退票
void Flight::Refund()
{
    if (If_takeoff())
    {
        cout << "该航班已经起飞,停止退票!" << endl;
        return;
    }
    int count;
    cout << "请输入退订票数";
    cin >> count;
    m_fseat += count;
}
搜索更多相关主题的帖子: include 管理系统 flight file 
2013-06-24 11:11
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:5 
'class/Traffic_system.h'
你确认这个文件存在吗

我行我乐
我的博客:
http://blog.yuccn. net
2013-06-24 12:14
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
得分:5 
Cannot open include file: 'class/Traffic_system.h'
不能打开这个引用文件
你确定文件路径是对的?
你看不懂英文?

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-06-24 12:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-415917-1-1.html




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

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