例外13 [英] exception 13

查看:77
本文介绍了例外13的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译时出现异常13错误.你能帮我解决这个问题吗?
我在Win XP上使用了Turbo C ++.
我是一名加两个学生,还没有对语言进行深入研究.这段代码是我的4个板子项目.
在编译代码时,错误消息如下:
0AD7:0A31处出现常规保护故障,错误代码为3A00
ax = 3A00,bx = 029C,cx = 08CA,dx = 3A00,di = 0002,si = E2DE
ds = 069F限制= FFFF段号004D C:\ TC \ BIN \ TC.EXE
es = 13aF限制= 044F段#
cs = 0A07限制= 1D3B段号00A9 C:\ TC \ BIN \ TC.EXE
ss = 069F限制= FFFF段号004D C:\ TC \ BIB \ TC.EXE
错误代码= 3A00限制= INVL段号
我删除了d类Date中的d代码,未显示异常错误.
代码如下:
#include< iostream.h>
#include< conio.h>
#include< fstream.h>
#include< string.h>
#include< ctype.h>
#include< stdio.h>
ifstream flight("Flights.dat",ios :: binary);
ifstream hotel("Hotels.dat",ios :: binary);
ifstream rail("Rails.dat",ios :: binary);
ifstream总线("Bus.dat",ios :: binary);
ifstream holiday("Holidays.dat",ios :: binary);
ifstream place("Places.dat",ios :: binary);
ifstream booking("Booked.dat",ios :: binary);
ofstream book("Booked.dat",ios :: binary,ios :: app);
ifstream read_record("Record.dat",ios :: binary);
ofstream write_record("Record.dat",ios :: binary,ios :: app);
int离开= 0;
int destination = 0;

int depart_time = 0;
成人int = 0;
int children = 0;
int infants = 0;
int j = 0;
int c = 0;
int duration = 0;
浮动f = 0.0;
班级地方
{
私人:
字符名称[20];
整数代码;
公众:
无效assign()
{
cout<<名称:";
gets(name);
place.seekg(0,ios :: beg);
代码= 6000 +(place.tellg()/sizeof(地方))+ 1;
}
int get_code()
{
返回码;
}
无效的display()
{
puts(name);
cout<<(("<< code<<));
}
};
班级日期
{
私人:
诠释日;
整数月;
int年;
公众:
void enter_date();
无效副本(日期d);
无效的display()
{
cout< day<."<< month<."<< year;
}
void refresh()
{
day = 0;
month = 0;
年= 0;
}
int get_day()
{
返回日;
}
int get_month()
{
返回月份;
}
int get_year()
{
返回年份;
}
};
日期:: enter_date()
{
int correct = 0;
做{
cout<<"Day:";
cin>> day;
cout<<月份:";
cin>> month;
cout<<年份:";
cin>> year;
/* if((day> 0)||(day< 32)|||(month> 0)|||(month< 13)||(year> 2009)||(year< 2014))
{
if(((month == 4)||(month == 6)||(month == 11)||(month == 9))&(day == 31))
{
cout<<无效的日期.\ n请重新输入正确的日期:\ n";
继续;
}
否则if((month == 2)&&(day> 28))
{
if((year == 2012)&&(day == 29))
{
cout<<日期已验证:有效.\ n";
正确= 1;
继续;
}
其他
{
cout<<无效的日期.\ n请重新输入正确的日期:\ n";
继续;
}
}
其他
{
cout<<日期已验证:有效.\ n";
正确= 1;
继续;
}
}
其他
{
cout<<无效的日期.\ n请重新输入正确的日期:\ n";
继续;
}
} while(correct == 0);
} */
无效Date :: copy(D d)
{
day = d.get_day();
month = d.get_month();
year = d.get_year();
}
日期;
类密码
{
私人:
char pass [20];
公众:
密码()
{
strcpy(pass,"9830182259");
}
void change_pass(Record r);
int compare_pass(char p [20]);
};

无效密码:: change_pass()
{
char new_pass [20];
cout<<输入当前密码\ n";
gets(new_pass);
if(compare_pass(new_pass))
{
cout<<输入新密码\ n";
gets(new_pass);
strcpy(pass,new_pass);
cout<<密码更改成功\ n";
}
其他
cout<<无效的密码\ n访问被拒绝!\ n";
}


int密码:: compare_pass(char p [20])
{
for(int i = 0; i< 20; i ++)
{
if(pass [i] == p [i])
继续;
其他
返回0;
}
返回1;
}
密码* p = new密码();
ofstream write_pass("Password.dat",ios :: binary);
write_pass.write((char *)& p,sizeof(p));
类记录
{
私人:
日期d;
整数代码;
向左int;
公众:
int compare(记录r)
{
if((r.get_date().get_day()== d.get_day())&&(r.get_date().get_month()== d.get_month())&&(r.get_date ().get_year()== d.get_year())&&(r.get_code()== code))
返回1;
其他
返回0;
}
无效get(int a,int b)
{
code = a;
d.copy(date);
left = b;
}
无效副本(记录r)
{
d.copy(r.get_date());
code = r.get_code();
left = r.get_left();
}
日期get_date()
{
返回d;
}
int get_code()
{
返回码;
}
int get_left()
{
返回左;
}
};
航班
{
私人:
int f_code;
char op [20];
int operator_code;
来源;
地点;
整数时间;
int time_code;
票价;
经济型经济舱;
int business_seats;
公众:
void check_availability();

无效assign()
{
flight.seekg(0,ios :: end);
f_code = 1000 +(flight.tellg()/sizeof(Flight))+ 1;
cout<<"\ nOperator:";
gets(op);
cout<<"\ nDeparure:";
from.assign();
cout<<"\ n到达:";
to.assign();
cout<<"\ n出发时间:";
cin>> time;
if(time> 500& time< = 1200)
time_code = 1;
否则if(time> 1200& time< = 1800)
time_code = 2;
否则if(time> 1800& time< = 0)
time_code = 3;
其他
time_code = 4;
cout<<"\ n票价:卢比.";
cin>> fare;
cout<<"\ n经济席位:";
cin>> economy_seats;
cout<<"\ n商务席位:";
cin>> business_seats;
}
int check(int k,int l)
{
if((k == from.get_code())&&(l == to.get_code()))
返回f_code;
其他
返回0;
}
int get_code()
{
返回f_code;
}
int get_time_code()
{
返回time_code;
}
int get_fare()
{
返程票价;
}
void short_display()
{
cout<<航班代码:"<< f_code<<"\ t";
puts(op);
}
无效的display()
{
cout<<航班代码:"<< f_code<<"\ t";
puts(op);
cout<<"\ nFrom:";
from.display();
cout<<"\ nTo:";
to.display();
cout<<"\ nDate:";
date.display();
cout<<"\ nTime:"<< time<"\ nFare:Rs.";
f =票价*成人* 1.0 +票价*儿童* 0.5 +票价*婴儿* 0.1;
cout<< f<< endl;
}
};
无效Flight :: check_availability(Record r)
{
记录记录;
r.get(f_code,economy_seats + business_seats);
read_record.seekg(0,ios :: beg);
while(read_record)
{
read_record.read((char *)& rec,sizeof(rec));
if(rec.compare(r))
{
r.copy(rec);
休息;
}
}
}
等级酒店
{
私人:
int h_code;
字符名称[20];
诠释星;
放置p;
内部房间;
int avg_daily_rate;
int xtra_perday;
炭的便利设施[200];
公众:
void check_availability(Record r);
无效assign()
{
hotel.seekg(0,ios :: end);
h_code = 2000 +(hotel.tellg()/sizeof(Hotel))+ 1;
cout<<名称:";
gets(name);
cout<<星级评分:";
cin>> star;
cout<<位置:";
p.assign();
cout<<房间数:";
cin>>房间;
cout<<每日平均费用:卢比.";
cin>> avg_daily_rate;
cout<<每日额外费用:卢比:";
cin>> xtra_perday;
cout<<设施:";
gets(amenities);
}
void short_display()
{
puts(name);
cout<<(("<< h_code<<)\ t"<<< star<" star \ n;
}
无效的display()
{
puts(name);
cout<"(("< h_code<<)\ n"<< star<" star \ n<"平均每日汇率:Rs. ;
cout<<"\ nAmenities:";
puts(amenities);
cout<< endl;
}
int get_code()
{
返回h_code;
}
int get_location()
{
返回p.get_code();
}
};
无效的Hotel :: check_availability(Record r)
{
记录记录;
r.get(h_code,rooms);
read_record.seekg(0,ios :: beg);
while(read_record)
{
read_record.read((char *)& rec,sizeof(rec));
if(rec.compare(r))
{
r.copy(rec);
休息;
}
}
}
铁路
{
私人:
int r_code;
炭火火车[30];
内部座位;
来源;
地点;
int time [10];
放置站[10];
浮动票价[10];
公众:
void Assign();
void check_availability(Record r);
int check(int x,int y);

int get_code()
{
返回r_code;
}
void short_display()
{
cout<<火车代码:"<< r_code<<"\ tName:";
puts(train);
}

};
无效Rail :: assign()
{
rail.seekg(0,ios :: end);
r_code = 3000 +(rail.tellg()/sizeof(Rail))+ 1;
cout<<火车名称:\ n";
gets(train);
cout<<"\ n输入座位数:";
cin>> seats;
cout<<"\ n起始位置:";
from.assign();
cout<<"\ n目的地电台:";
to.assign();
cout<<"\ n输入停靠页:";
for(int i = 0; i< 10; i ++)
{
cout<<"\ nStation"<<(i + 1);
站[i] .assign();
cout<<"\ nTime:";
cin>> time [i];
cout<<"\ n来自前一站的票价:Rs.";
cin>> fare [i];
}
}
int Rail :: check(int x,int y)
{
int result = 0;
int d = 0;
if(x == from.get_code())
result = 1;
其他
{
for(d = 0; d< 10; d ++)
{
if(x == stations [d] .get_code())
result = 1;
}
}
if(结果)
{
结果= 0;
for(; d< 10; d ++)
{
if(y == stations [d] .get_code())
result = 1;
}
if(!result)
{
if(y == to.get_code())
result = 1;
}
}
if(结果)
返回r_code;
其他
返回0;
}
无效Rail :: check_availability(Record r)
{
记录记录;
r.get(r_code,seats);
read_record.seekg(0,ios :: beg);
while(read_record)
{
read_record.read((char *)& rec,sizeof(rec));
if(rec.compare(r))
{
r.copy(rec);
休息;
}
}
}
类Bus
{
私人:
int b_code;
char op [20];
int operator_code;
来源;
地点;
放置停工处[10];
int time [10];
浮动票价[10];
内部座位;
公众:
int check(int x,int y);
void check_availability(Record r);
void Assign();
int get_code()
{
返回b_code;
}
void short_display()
{
cout<<公交代码:"<< b_code<<"\ tOperator:";
puts(op);
}
};
无效的Bus :: assign()
{
bus.seekg(0,ios :: end);
b_code = 3000 +(bus.tellg()/sizeof(Bus))+ 1;
cout<<火车名称:\ n";
gets(op);
cout<<"\ n输入座位数:";
cin>> seats;
cout<<"\ n起始位置:";
from.assign();
cout<<"\ n目的地电台:";
to.assign();
cout<<"\ n输入停靠页:";
for(int i = 0; i< 10; i ++)
{
cout<<"\ nStation"<< i + 1;
stoppages [i] .assign();
cout<<"\ nTime:";
cin>> time [i];
cout<<"\ n上一站的票价:卢比.";
cin>> fare [i];
}
}
int Bus :: check(int x,int y)
{
int result = 0;
int d = 0;
if(x == from.get_code())
result = 1;
其他
{
for(d = 0; d< 10; d ++)
{
if(x == stoppages [d] .get_code())
result = 1;
}
}
if(结果)
{
结果= 0;
for(; d< 10; d ++)
{
if(y == stoppages [d] .get_code())
result = 1;
}
if(!result)
{
if(y == to.get_code())
result = 1;
}
}
if(结果)
返回b_code;
其他
返回0;
}
无效的Bus :: check_availability(Record r)
{
记录记录;
r.get(b_code,seats);
read_record.seekg(0,ios :: beg);
while(read_record)
{
read_record.read((char *)& rec,sizeof(rec));
if(rec.compare(r))
{
r.copy(rec);
休息;
}
}
}
已预订课程
{
私人:
int ref_no;
整数代码;
int l;
int dest;
字符名称[6] [20];
浮动票价;
char credit_card [16];
int conf;
日期d;
int偏好设置;
char e_mail [25];
公众:
void display();
int确认(int k,int l);
int get_reference()
{
返回ref_no;
}
};
预订的无效:: display()
{
cout<<参考编号:"<< ref_no<< endl;
cout<<旅行者:\ n";
for(int a = 0; a< 6; a ++)
{
cout<<((a + 1)<<." ;;
puts(names [a]);
}
cout<总票价-卢比."< fare;
cout<<日期:";
d.display();
}
预定的int :: confirm(int k,int l)
{
l =离开;
dest =目的地;
d.copy(date);
preference = l;
代码= k;
k = 0;
fare = f;
cout<<"\ n请输入旅客(不包括婴儿)的姓名:\ n";
cout<<"\ n完成后,输入0 \ n";

{
gets(名称[k]);
k ++;
} while(names [k] [0]!=''0'');
booking.seekg(0,ios :: end);
ref_no = 7000 +(booking.tellg()/sizeof(Booked))+ 1;
cout<<"\ n信用卡号:";
gets(credit_card);
cout<<电子邮件ID:\ n";
gets(e_mail);
if(k-1!= 0)conf = 1;
else conf = 0;
return conf;
}
假期类
{
私人:
放假;
放置目的地;
字符主题[20];
int theme_code;
int h_code;
int持续时间;
浮动票价;
字符描述[300];
公众:
无效assign()
{
holiday.seekg(0,ios :: end);
h_code = 5000 +(holiday.tellg()/sizeof(假日))+ 1;
cout<<"\ n出发地:";
Leave.assign();
cout<<"\ n目的地:";
destination.assign();
cout<<"\ nTheme:";
gets(theme);
cout<<"\ nDuration:";
cin>>持续时间";
cout<<"\ n票价:卢比.";
cin>> fare;''
cout<<"\ nDescription:";
gets(description);
}
void short_display()
{
cout<<目的地:";
p.display();
cout<<"\ tCode:"<< h_code;
cout<"\ tDuration:"<< duration<<"days";
}
无效的display()
{
cout<<目的地:";
destination.display();
cout<<"\ n航班将从";
提供 Leave.display();
cout<<"\ n假日主题:";
puts(theme);
cout<"\ nDuration:"<< duration<天\ n票价:卢比."<票价<<每人\ nDuration;
}
};


无效menu()
{
cout<<"1.航班"<< endl;
cout<<"2.酒店"<< endl;
cout<<"3.铁路"<< endl;
cout<<"4.Bus"<< endl;
cout<<"5.节假日"<< endl;
cout<<"6.检查状态"<< endl;
cout<<"7.登录名(仅限授权人员)";
cout<<"8.出口";
}
void login_menu()
{
cout<<"\ n登录菜单";
cout<<"1.添加新的航班\ n";
cout<<"2.添加新酒店\ n";
cout<<"3.添加新火车\ n";
cout<<"4.添加新的公共汽车\ n";
cout<<"5.添加新的假期\ n";
cout<<"6.添加新地点\ n";
cout<<"7.更改密码\ n";
cout<<"8.返回上一级菜单\ n";
cout<<输入您的选项(1-7):";
}
void display_cities()
{
放置p;
j = 1;
place.seekg(0);
while(!place)
{
place.read((char *)& p,sizeof(Place));
cout<< j<.";
p.display();
cout<< endl;
j ++;
}
cout<<输入城市代码:";
}
无效read_info(int ch)
{
if(ch!= 2 || ch!= 5)
{
cout<<离开:\ n";
display_cities();
cin>> leave;
}
cout<<"\ n转到:\ n";
display_cities();
cin>>目的地;
if(ch!= 2)
cout<<出发日期:";
其他
cout<<到达日期:";
date.enter_date();
if(ch == 1)
{
cout<<"\ n选择出发时间\ n1.0500-1200 \ n2.1200-1800 \ n3.1800-0000 \ n4.0000-0500 \ n";
cin>> depart_time;
}
cout<<旅行者(每次预订最多6人):\ n";
cout<<成人(12岁以上):";
cin>>成人;
cout<<"\ nChildren(2-11):";
cin>> children;
cout<<"\ nInfants(0-2):";
cin>>婴儿;
}
void holiday_info()
{
cout<<目的地:";
display_cities();
cin>>目的地;
cout<<"\ n持续时间:\ n1.1-4天\ n2.4-7天\ n3.7 +天";
cin> duration;
}
int search_flight()
{
航班f;
int a1;
发现int = 0;
flight.seekg(0);
cout<<搜索结果:\ n";
同时(飞行)
{
flight.read((char *)& f,sizeof(Flight));
if((f.check(leave,destination))&&(f.get_time_code()== depart_time))
{
f.short_display();
找到= 1;
}
}
如果(找到)
{
cout<<输入航班代码以获取更多信息:\ n";
cin>> a1;
返回a1;
}
其他
返回0;
}
int search_hotels()
{
H酒店;
int a2;
发现int = 0;
while(酒店)
{
hotel.read((char *)& h,sizeof(Hotel));
if(目的地== h.get_location())
{
找到= 1;
h.short_display();
}
}
如果(找到)
{
cout<<输入酒店代码以获取更多信息:\ n";
cin>> a2;
返回a2;
}
其他
返回0;
}
int search_rails()
{
铁路r;
int a3;
发现int = 0;
rail.seekg(0);
while(rail)
{
rail.read((char *)& r,sizeof(Rail));
if(r.check(leave,destination))
{
找到= 1;
r.short_display();
}
}
如果(找到)
{
cout<<输入火车代码以获取更多信息:\ n";
cin>> a3;
返回a3;
}
其他
返回0;
}

int search_buses()
{
巴士b;
int a4;
发现int = 0;
bus.seekg(0);
while(公共汽车)
{
bus.read((char *)& b,sizeof(Bus));
if(b.check(leave,destination))
{
找到= 1;
b.short_display();
}
}
如果(找到)
{
cout<<输入总线代码以获取更多信息:\ n";
cin>> a4;
返回a4;
}
其他
返回0;
}
int search_holiday()
{
假日h;
int a5;
发现int = 0;
holiday.seekg(0);
假期(假日)
{
holiday.read((char *)& h,sizeof(Holiday));
if(h.get_destination()== destination)
{
找到= 1;
h.short_display();
}
}
如果(找到)
{
cout<<输入假期代码以获取更多信息:\ n"
cin>> a5;
返回a5;
}
其他
返回0;
}
void refresh()
{
离开= 0;
destination = 0;
date.refresh();
depart_time = 0;
成人= 0;
children = 0;
婴儿= 0;
j = 0;
c = 0;
持续时间= 0;
}
无效的书(int代码,int选择)
{
int check = 0;
char ch;
记录r;
已预订b;
cout<<"\ n您已选择以下";
开关(选择)
{
案例1:f航班;
flight.seekg(0,ios :: beg);
同时(飞行)
{
flight.read((char *)& f,sizeof(f));
if(code == f.get_code())
休息;
}
cout<<航班:";
f.display();
cout<<"\ n正在检查可用性\ n";
f.check_availability(r);
if(r.get_left()!= 0)
{
cout<<可用的席位\ n";
check = 1;
}
其他
cout<<抱歉!席位不可用\ n";
休息;
案例2:酒店h;
hotel.seekg(0,ios :: beg);
while(酒店)
{
hotel.read((char *)& h,sizeof(h));
if(code == h.get_code())
休息;
}
cout<<"hotel:";
h.display();
cout<<"\ n正在检查可用性\ n";
h.check_availability(r);
if(r.get_left()!= 0)
{
cout<<可用的席位\ n";
check = 1;
}
其他
cout<<抱歉!席位不可用\ n";
休息;
情况3:Rail rl;
rail.seekg(0,ios :: beg);
while(rail)
{
rail.read((char *)& f,sizeof(rl));
if(code == rl.get_code())
休息;
}
cout<<航班:";
rl.display();
cout<<"\ n正在检查可用性\ n";
rl.check_availability(r);
if(r.get_left()!= 0)
{
cout<<可用的席位\ n";
check = 1;
}
其他
cout<<抱歉!席位不可用\ n";
休息;
情况4:巴士b;
bus.seekg(0,ios :: beg);
while(公共汽车)
{
bus.read((char *)& b,sizeof(b));
if(code == b.get_code())
休息;
}
cout<<"bus:";
b.display();
cout<<"\ n正在检查可用性\ n";
b.check_availability(r);
if(r.get_left()!= 0)
{
cout<<可用的席位\ n";
check = 1;
}
其他
cout<<抱歉!席位不可用\ n";
休息;
情况5:假日h;
holiday.seekg(0,ios :: beg);
假期(假日)
{
holiday.read((char *)& h,sizeof(h));
if(code == h.get_code())
休息;
}
cout<<假日:";
h.display();
cout<<"\ n正在检查可用性\ n";
h.check_availability(r);
if(r.get_left()!= 0)
{
cout<<可用的席位\ n";
check = 1;
}
其他
cout<<抱歉!席位不可用\ n";
休息;
}
如果(检查)
{
cout<<确认此预订?(y/n):";
cin>> ch;
if((ch ==''y'')||((ch ==''Y))
check = b.confirm(code,choice);
如果(检查)
{
r.update();
cout<<"\ n您的预订已确认.\ nYpur参考编号是:"<< b.get_reference();
book.write((char *)& b,sizf(b));
write_record.seekp(read_record.tellg()-sizeof(r),ios :: beg);
write_record.write((char *)& r,sizeof(r));
}
其他
cout<<无法确认预订,";
}
}
void check_status()
{
cout<<参考编号:";
int n;
cin>> n;
已预订b;
booking.seekg(0,ios :: beg);
while(预订)
{
booking.read((char *)& b,sizeof(b));
if(n == b.get_reference())
{
b.display();
休息;
}
其他
n = 0;
}
if(!n)
cout<<无效的参考号.\ n请确保输入的数字正确无误.";
}
void login()
{
ofstream get_flight("Flights.dat",ios :: binary,ios :: app);
ofstream get_hotel("Hotel.dat",ios :: binary,ios :: app);
ofstream get_rail("Rails.dat",ios :: binary,ios :: app);
ofstream get_bus("Bus.dat",ios :: binary,ios :: app);
ofstream get_holiday("Holiday.dat",ios :: binary,ios :: app);
ofstream get_place("Places.dat",ios :: binary,ios :: app);
ifstream read_pass("Password.dat",ios :: binary);
int选择;
char pass [20];
密码p;
read_pass.read((char *)& p,sizeof(p));
cout<<密码:";
gets(pass);
if(p.compare_pass(pass))
{

{
login_menu();
cin>> choice;
开关(选择)
{
案例1:f航班;
f.assign();
get_flight.write((char *)& f,sizeof(f));
休息;
案例2:酒店h;
h.assign();
get_hotel.write((char *)& h,sizeof(h));
休息;
情况3:Rail r;
r.assign();
get_rail.write((char *)& r,sizeof(r));
休息;
情况4:巴士b;
b.assign();
get_bus.write((char *)& b,sizeof(b));
休息;
情况5:假日h;
h.assign();
get_holiday.write((char *)& h,sizeof(h));
休息;
情况6:放置p;
p.assign();
get_place.write(((chr *)& p,sizeof(p));
休息;
情况7:cout<<密码:\ n";
p.change_pass();
write_pass.write((char *)& p,sizeof(p));
休息;
情况8:cout<<"\ n退出... \ n";
休息;
默认值:cout<<"\ n无效的选项.\ n访问被拒绝.";
}
} while(choice!= 7);
}
其他
cout<<密码无效!\ n访问被拒绝...";
}

void main()
{
cout<<欢迎来到KHK旅行社"<<< endl;
int选择;
做{
menu();
cout<<输入您的选项:"<< endl;
cin>> choice;
开关(选择)
{
情况1:cout<<预订航班\ n";
read_info(choice);
if(c = search_flight())
{
book(c,choice);
}
其他
{
cout<<"抱歉.您输入的目的地之间没有航班.\ n;
}
refresh();
休息;
情况2:cout<<预订酒店\ n";
read_info(choice);
if(c = search_hotels())
{
book(c,choice);
}
其他
{
cout<<抱歉.在您指定的位置,我们的网络下没有任何酒店.\ n";
}
refresh();
休息;
情况3:cout<<在线铁路预订\ n";
read_info(choice);
if(c = search_rails())
{
book(c,choice);
}
其他
{
cout<<抱歉.您输入的车站之间没有火车路线.\ n";
}
refresh();
休息;
情况4:cout<<在线巴士座位预订\ n";
read_info(choice);
if(c = search_buses())
{
book(c,choice);
}
其他
{
cout<<对不起.您输入的地点之间没有公交路线.\ n";
}
refresh();
休息;
情况5:cout<<计划假期\ n";
holiday_info();
if(c = search_holidays())
{
book(c,choice);
}
其他
{
cout<<抱歉.我们的旅行社未在您输入的城市安排假期.\ n";
}
refresh();
休息;
情况6:check_status();
休息;
情况7:login();
休息;
案例8:cout<<感谢您使用KHK旅行社.\ n请再次访问.\ n";
休息;
默认值:cout<<输入无效!\ n请再次输入您的选项.\ n";
}
} while(choice!= 7);
}

while compiling i got an exception 13 error. can u help me fix it.
i used turbo c++ on win xp.
i''m a plus two student and haven''t gone into an in-depth study of the language.this code is my project 4 boards.
on compiling the code,the error message was as follows:
general protection fault at 0AD7:0A31 ERROR CODE-3A00
ax=3A00,bx=029C,cx=08CA,dx=3A00,di=0002,si=E2DE
ds=069F limit=FFFF segment# 004D C:\TC\BIN\TC.EXE
es=13aF limit=044F segment#
cs=0A07 limit=1D3B segment# 00A9 C:\TC\BIN\TC.EXE
ss=069F limit=FFFF segment# 004D C:\TC\BIB\TC.EXE
error code=3A00 limit=INVL segment#
wen i removd d class Date part of d code,the exception error didn''t show up.
the code is as follows:
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<ctype.h>
#include<stdio.h>
ifstream flight("Flights.dat",ios::binary);
ifstream hotel("Hotels.dat",ios::binary);
ifstream rail("Rails.dat",ios::binary);
ifstream bus("Bus.dat",ios::binary);
ifstream holiday("Holidays.dat",ios::binary);
ifstream place("Places.dat",ios::binary);
ifstream booking("Booked.dat",ios::binary);
ofstream book("Booked.dat",ios::binary,ios::app);
ifstream read_record("Record.dat",ios::binary);
ofstream write_record("Record.dat",ios::binary,ios::app);
int leave=0;
int destination=0;

int depart_time=0;
int adults=0;
int children=0;
int infants=0;
int j=0;
int c=0;
int duration=0;
float f=0.0;
class Place
{
private:
char name[20];
int code;
public:
void assign()
{
cout<<"Name:";
gets(name);
place.seekg(0,ios::beg);
code=6000+(place.tellg()/sizeof(Place))+1;
}
int get_code()
{
return code;
}
void display()
{
puts(name);
cout<<"("<<code<<")";
}
};
class Date
{
private:
int day;
int month;
int year;
public:
void enter_date();
void copy(Date d);
void display()
{
cout<<day<<"."<<month<<"."<<year;
}
void refresh()
{
day=0;
month=0;
year=0;
}
int get_day()
{
return day;
}
int get_month()
{
return month;
}
int get_year()
{
return year;
}
};
void Date::enter_date()
{
int correct=0;
do{
cout<<"Day:";
cin>>day;
cout<<"Month:";
cin>>month;
cout<<"Year:";
cin>>year;
/* if((day>0)||(day<32)||(month>0)||(month<13)||(year>2009)||(year<2014))
{
if(((month==4)||(month==6)||(month==11)||(month==9))&&(day==31))
{
cout<<"Invalid date.\nPlease re-enter correct date:\n";
continue;
}
else if((month==2)&&(day>28))
{
if((year==2012)&&(day==29))
{
cout<<"Date verified:Valid.\n";
correct=1;
continue;
}
else
{
cout<<"Invalid date.\nPlease re-enter corrcet date:\n";
continue;
}
}
else
{
cout<<"Date verified:Valid.\n";
correct=1;
continue;
}
}
else
{
cout<<"Invalid date.\nPlease re-enter correct date:\n";
continue;
}
}while(correct==0);
} */
void Date::copy(Date d)
{
day=d.get_day();
month=d.get_month();
year=d.get_year();
}
Date date;
class Password
{
private:
char pass[20];
public:
Password()
{
strcpy(pass,"9830182259");
}
void change_pass(Record r);
int compare_pass(char p[20]);
};

void Password::change_pass()
{
char new_pass[20];
cout<<"Enter current password\n";
gets(new_pass);
if(compare_pass(new_pass))
{
cout<<"Enter new password\n";
gets(new_pass);
strcpy(pass,new_pass);
cout<<"Password changed successfully\n";
}
else
cout<<"Invalid password\nAccess Denied!!\n";
}


int Password::compare_pass(char p[20])
{
for(int i=0;i<20;i++)
{
if(pass[i]==p[i])
continue;
else
return 0;
}
return 1;
}
Password *p=new Password();
ofstream write_pass("Password.dat",ios::binary);
write_pass.write((char*)&p,sizeof(p));
class Record
{
private:
Date d;
int code;
int left;
public:
int compare(Record r)
{
if((r.get_date().get_day()==d.get_day())&&(r.get_date().get_month()==d.get_month())&&(r.get_date().get_year()==d.get_year())&&(r.get_code()==code))
return 1;
else
return 0;
}
void get(int a,int b)
{
code=a;
d.copy(date);
left=b;
}
void copy(Record r)
{
d.copy(r.get_date());
code=r.get_code();
left=r.get_left();
}
Date get_date()
{
return d;
}
int get_code()
{
return code;
}
int get_left()
{
return left;
}
};
class Flight
{
private:
int f_code;
char op[20];
int operator_code;
Place from;
Place to;
int time;
int time_code;
int fare;
int economy_seats;
int business_seats;
public:
void check_availability();

void assign()
{
flight.seekg(0,ios::end);
f_code=1000+(flight.tellg()/sizeof(Flight))+1;
cout<<"\nOperator:";
gets(op);
cout<<"\nDeparure:";
from.assign();
cout<<"\nArrival:";
to.assign();
cout<<"\nDeparture time:";
cin>>time;
if(time>500 && time<=1200)
time_code=1;
else if(time>1200 && time<=1800)
time_code=2;
else if(time>1800 && time<=0)
time_code=3;
else
time_code=4;
cout<<"\nFare: Rs.";
cin>>fare;
cout<<"\nEconomy seats:";
cin>>economy_seats;
cout<<"\nBusiness seats:";
cin>>business_seats;
}
int check(int k,int l)
{
if((k==from.get_code())&&(l==to.get_code()))
return f_code;
else
return 0;
}
int get_code()
{
return f_code;
}
int get_time_code()
{
return time_code;
}
int get_fare()
{
return fare;
}
void short_display()
{
cout<<"Flight code:"<<f_code<<"\t";
puts(op);
}
void display()
{
cout<<"Flight code:"<<f_code<<"\t";
puts(op);
cout<<"\nFrom:";
from.display();
cout<<"\nTo:";
to.display();
cout<<"\nDate:";
date.display();
cout<<"\nTime:"<<time<<"\nFare:Rs.";
f=fare*adults*1.0+fare*children*0.5+fare*infants*0.1;
cout<<f<<endl;
}
};
void Flight::check_availability(Record r)
{
Record rec;
r.get(f_code,economy_seats+business_seats);
read_record.seekg(0,ios::beg);
while(read_record)
{
read_record.read((char*)& rec, sizeof(rec));
if(rec.compare(r))
{
r.copy(rec);
break;
}
}
}
class Hotel
{
private:
int h_code;
char name[20];
int star;
Place p;
int rooms;
int avg_daily_rate;
int xtra_perday;
char amenities[200];
public:
void check_availability(Record r);
void assign()
{
hotel.seekg(0,ios::end);
h_code=2000+(hotel.tellg()/sizeof(Hotel))+1;
cout<<"Name:";
gets(name);
cout<<"Star rating:";
cin>>star;
cout<<"Location:";
p.assign();
cout<<"Number of Rooms:";
cin>>rooms;
cout<<"Average daily rate: Rs.";
cin>>avg_daily_rate;
cout<<"Extra per day:Rs:";
cin>>xtra_perday;
cout<<"Amenities:";
gets(amenities);
}
void short_display()
{
puts(name);
cout<<"("<<h_code<<")\t"<<star<<" star\n";
}
void display()
{
puts(name);
cout<<"("<<h_code<<")\n"<<star<<" star\n"<<"Avg daily rate:Rs."<<avg_daily_rate;
cout<<"\nAmenities:";
puts(amenities);
cout<<endl;
}
int get_code()
{
return h_code;
}
int get_location()
{
return p.get_code();
}
};
void Hotel::check_availability(Record r)
{
Record rec;
r.get(h_code,rooms);
read_record.seekg(0,ios::beg);
while(read_record)
{
read_record.read((char*)& rec, sizeof(rec));
if(rec.compare(r))
{
r.copy(rec);
break;
}
}
}
class Rail
{
private:
int r_code;
char train[30];
int seats;
Place from;
Place to;
int time[10];
Place stations[10];
float fare[10];
public:
void assign();
void check_availability(Record r);
int check(int x,int y);

int get_code()
{
return r_code;
}
void short_display()
{
cout<<"Train code:"<<r_code<<"\tName:";
puts(train);
}

};
void Rail::assign()
{
rail.seekg(0,ios::end);
r_code=3000+(rail.tellg()/sizeof(Rail))+1;
cout<<"Train name:\n";
gets(train);
cout<<"\nEnter number of seats:";
cin>>seats;
cout<<"\nStarting location:";
from.assign();
cout<<"\nDestination station:";
to.assign();
cout<<"\nEnter stoppages:";
for(int i=0;i<10;i++)
{
cout<<"\nStation "<<(i+1);
stations[i].assign();
cout<<"\nTime:";
cin>>time[i];
cout<<"\nFare from previous station: Rs.";
cin>>fare[i];
}
}
int Rail::check(int x,int y)
{
int result=0;
int d=0;
if(x==from.get_code())
result=1;
else
{
for(d=0;d<10;d++)
{
if(x==stations[d].get_code())
result=1;
}
}
if(result)
{
result=0;
for(;d<10;d++)
{
if(y==stations[d].get_code())
result=1;
}
if(!result)
{
if(y==to.get_code())
result=1;
}
}
if(result)
return r_code;
else
return 0;
}
void Rail::check_availability(Record r)
{
Record rec;
r.get(r_code,seats);
read_record.seekg(0,ios::beg);
while(read_record)
{
read_record.read((char*)& rec, sizeof(rec));
if(rec.compare(r))
{
r.copy(rec);
break;
}
}
}
class Bus
{
private:
int b_code;
char op[20];
int operator_code;
Place from;
Place to;
Place stoppages[10];
int time[10];
float fare[10];
int seats;
public:
int check(int x,int y);
void check_availability(Record r);
void assign();
int get_code()
{
return b_code;
}
void short_display()
{
cout<<"Bus code:"<<b_code<<"\tOperator:";
puts(op);
}
};
void Bus::assign()
{
bus.seekg(0,ios::end);
b_code=3000+(bus.tellg()/sizeof(Bus))+1;
cout<<"Train name:\n";
gets(op);
cout<<"\nEnter number of seats:";
cin>>seats;
cout<<"\nStarting location:";
from.assign();
cout<<"\nDestination station:";
to.assign();
cout<<"\nEnter stoppages:";
for(int i=0;i<10;i++)
{
cout<<"\nStation "<<i+1;
stoppages[i].assign();
cout<<"\nTime:";
cin>>time[i];
cout<<"\nFare from previous station: Rs.";
cin>>fare[i];
}
}
int Bus::check(int x,int y)
{
int result=0;
int d=0;
if(x==from.get_code())
result=1;
else
{
for(d=0;d<10;d++)
{
if(x==stoppages[d].get_code())
result=1;
}
}
if(result)
{
result=0;
for(;d<10;d++)
{
if(y==stoppages[d].get_code())
result=1;
}
if(!result)
{
if(y==to.get_code())
result=1;
}
}
if(result)
return b_code;
else
return 0;
}
void Bus::check_availability(Record r)
{
Record rec;
r.get(b_code,seats);
read_record.seekg(0,ios::beg);
while(read_record)
{
read_record.read((char*)& rec, sizeof(rec));
if(rec.compare(r))
{
r.copy(rec);
break;
}
}
}
class Booked
{
private:
int ref_no;
int code;
int l;
int dest;
char names[6][20];
float fare;
char credit_card[16];
int conf;
Date d;
int preference;
char e_mail[25];
public:
void display();
int confirm(int k, int l);
int get_reference()
{
return ref_no;
}
};
void Booked::display()
{
cout<<"Reference No.:"<<ref_no<<endl;
cout<<"Travellers:\n";
for(int a=0;a<6;a++)
{
cout<<(a+1)<<". ";
puts(names[a]);
}
cout<<"Total fare- Rs."<<fare;
cout<<"Date:";
d.display();
}
int Booked::confirm(int k, int l)
{
l=leave;
dest=destination;
d.copy(date);
preference=l;
code=k;
k=0;
fare=f;
cout<<"\nPlease enter the names of the travellers(excluding infants):\n";
cout<<"\nWhen done enter 0\n";
do
{
gets(names[k]);
k++;
}while(names[k][0]!=''0'');
booking.seekg(0,ios::end);
ref_no=7000+(booking.tellg()/sizeof(Booked))+1;
cout<<"\nCredit card number:";
gets(credit_card);
cout<<"e-mail id:\n";
gets(e_mail);
if(k-1!=0) conf=1;
else conf=0;
return conf;
}
class Holiday
{
private:
Place leave;
Place destination;
char theme[20];
int theme_code;
int h_code;
int duration;
float fare;
char description[300];
public:
void assign()
{
holiday.seekg(0,ios::end);
h_code=5000+(holiday.tellg()/sizeof(Holiday))+1;
cout<<"\nDeparture:";
leave.assign();
cout<<"\nDestination:";
destination.assign();
cout<<"\nTheme:";
gets(theme);
cout<<"\nDuration:";
cin>>"duration";
cout<<"\nFare: Rs.";
cin>>fare;''
cout<<"\nDescription:";
gets(description);
}
void short_display()
{
cout<<"Destination:";
p.display();
cout<<"\tCode:"<<h_code;
cout<<"\tDuration:"<<duration<<" days";
}
void display()
{
cout<<"Destination:";
destination.display();
cout<<"\nFlight will be provided from ";
leave.display();
cout<<"\nHoliday theme:";
puts(theme);
cout<<"\nDuration:"<<duration<<" days\nFare: Rs."<<fare<<" per person\nDuration";
}
};


void menu()
{
cout<<"1. Flights"<<endl;
cout<<"2. Hotels"<<endl;
cout<<"3. Railways"<<endl;
cout<<"4. Bus"<<endl;
cout<<"5. Holidays"<<endl;
cout<<"6. Check status"<<endl;
cout<<"7. Login(for authorised personnel only)";
cout<<"8. Exit";
}
void login_menu()
{
cout<<"\n Login menu";
cout<<"1. Add new flight\n";
cout<<"2. Add new hotel\n";
cout<<"3. Add new train\n";
cout<<"4. Add new bus\n";
cout<<"5. Add new holiday\n";
cout<<"6. Add new place\n";
cout<<"7. Change password\n";
cout<<"8. Return to previous menu\n";
cout<<"Enter your option(1-7):";
}
void display_cities()
{
Place p;
j=1;
place.seekg(0);
while(!place)
{
place.read((char*)& p, sizeof(Place));
cout<<j<<".";
p.display();
cout<<endl;
j++;
}
cout<<"Enter the city code:";
}
void read_info(int ch)
{
if(ch!=2||ch!=5)
{
cout<<"Leaving from:\n";
display_cities();
cin>>leave;
}
cout<<"\nGoing to:\n";
display_cities();
cin>>destination;
if(ch!=2)
cout<<"Departure date:";
else
cout<<"Arrival date:";
date.enter_date();
if(ch==1)
{
cout<<"\nChoose departure time\n1. 0500-1200\n2. 1200-1800\n3. 1800-0000\n4. 0000-0500\n";
cin>>depart_time;
}
cout<<"Travellers(upto 6 per booking):\n";
cout<<"Adults(12+):";
cin>>adults;
cout<<"\nChildren(2-11):";
cin>>children;
cout<<"\nInfants(0-2):";
cin>>infants;
}
void holiday_info()
{
cout<<"Destination:";
display_cities();
cin>>destination;
cout<<"\nDuration:\n1.1-4 days\n2.4-7 days\n3.7+ days";
cin>>duration;
}
int search_flight()
{
Flight f;
int a1;
int found=0;
flight.seekg(0);
cout<<"Search results:\n";
while(flight)
{
flight.read((char*)& f, sizeof(Flight));
if((f.check(leave,destination))&&(f.get_time_code()==depart_time))
{
f.short_display();
found=1;
}
}
if(found)
{
cout<<"Enter flight code to get more information:\n";
cin>>a1;
return a1;
}
else
return 0;
}
int search_hotels()
{
Hotel h;
int a2;
int found=0;
while(hotel)
{
hotel.read((char*)& h, sizeof(Hotel));
if(destination==h.get_location())
{
found=1;
h.short_display();
}
}
if(found)
{
cout<<"Enter hotel code to get more information:\n";
cin>>a2;
return a2;
}
else
return 0;
}
int search_rails()
{
Rail r;
int a3;
int found=0;
rail.seekg(0);
while(rail)
{
rail.read((char*)& r,sizeof(Rail));
if(r.check(leave,destination))
{
found=1;
r.short_display();
}
}
if(found)
{
cout<<"Enter train code to get more information:\n";
cin>>a3;
return a3;
}
else
return 0;
}

int search_buses()
{
Bus b;
int a4;
int found=0;
bus.seekg(0);
while(bus)
{
bus.read((char*)& b,sizeof(Bus));
if(b.check(leave,destination))
{
found=1;
b.short_display();
}
}
if(found)
{
cout<<"Enter bus code to get more information:\n";
cin>>a4;
return a4;
}
else
return 0;
}
int search_holiday()
{
Holiday h;
int a5;
int found=0;
holiday.seekg(0);
while(holiday)
{
holiday.read((char*)& h,sizeof(Holiday));
if(h.get_destination()==destination)
{
found=1;
h.short_display();
}
}
if(found)
{
cout<<"Enter holiday code to get more information:\n"
cin>>a5;
return a5;
}
else
return 0;
}
void refresh()
{
leave=0;
destination=0;
date.refresh();
depart_time=0;
adults=0;
children=0;
infants=0;
j=0;
c=0;
duration=0;
}
void book(int code, int choice)
{
int check=0;
char ch;
Record r;
Booked b;
cout<<"\nYou have selected the following ";
switch(choice)
{
case 1: Flight f;
flight.seekg(0,ios::beg);
while(flight)
{
flight.read((char*)& f,sizeof(f));
if(code==f.get_code())
break;
}
cout<<"flight:";
f.display();
cout<<"\nChecking availability\n";
f.check_availability(r);
if(r.get_left()!=0)
{
cout<<"Seats available\n";
check=1;
}
else
cout<<"Sorry! Seats unavailable\n";
break;
case 2: Hotel h;
hotel.seekg(0,ios::beg);
while(hotel)
{
hotel.read((char*)& h,sizeof(h));
if(code==h.get_code())
break;
}
cout<<"hotel:";
h.display();
cout<<"\nChecking availability\n";
h.check_availability(r);
if(r.get_left()!=0)
{
cout<<"Seats available\n";
check=1;
}
else
cout<<"Sorry! Seats unavailable\n";
break;
case 3: Rail rl;
rail.seekg(0,ios::beg);
while(rail)
{
rail.read((char*)& f,sizeof(rl));
if(code==rl.get_code())
break;
}
cout<<"flight:";
rl.display();
cout<<"\nChecking availability\n";
rl.check_availability(r);
if(r.get_left()!=0)
{
cout<<"Seats available\n";
check=1;
}
else
cout<<"Sorry! Seats unavailable\n";
break;
case 4: Bus b;
bus.seekg(0,ios::beg);
while(bus)
{
bus.read((char*)& b,sizeof(b));
if(code==b.get_code())
break;
}
cout<<"bus:";
b.display();
cout<<"\nChecking availability\n";
b.check_availability(r);
if(r.get_left()!=0)
{
cout<<"Seats available\n";
check=1;
}
else
cout<<"Sorry! Seats unavailable\n";
break;
case 5: Holiday h;
holiday.seekg(0,ios::beg);
while(holiday)
{
holiday.read((char*)& h,sizeof(h));
if(code==h.get_code())
break;
}
cout<<"holiday:";
h.display();
cout<<"\nChecking availability\n";
h.check_availability(r);
if(r.get_left()!=0)
{
cout<<"Seats available\n";
check=1;
}
else
cout<<"Sorry! Seats unavailable\n";
break;
}
if(check)
{
cout<<"Confirm this booking?(y/n):";
cin>>ch;
if((ch==''y'')||(ch==''Y))
check=b.confirm(code,choice);
if(check)
{
r.update();
cout<<"\nYour booking has been confirmed.\nYpur reference number is:"<<b.get_reference();
book.write((char*)& b,sizf(b));
write_record.seekp(read_record.tellg()-sizeof(r),ios::beg);
write_record.write((char*)& r,sizeof(r));
}
else
cout<<"Unable to confirm booking,";
}
}
void check_status()
{
cout<<"Reference number:";
int n;
cin>>n;
Booked b;
booking.seekg(0,ios::beg);
while(booking)
{
booking.read((char*)& b,sizeof(b));
if(n==b.get_reference())
{
b.display();
break;
}
else
n=0;
}
if(!n)
cout<<"Invalid reference number.\nPlease make sure that the number you have entered is correct.";
}
void login()
{
ofstream get_flight("Flights.dat",ios::binary,ios::app);
ofstream get_hotel("Hotel.dat",ios::binary,ios::app);
ofstream get_rail("Rails.dat",ios::binary,ios::app);
ofstream get_bus("Bus.dat",ios::binary,ios::app);
ofstream get_holiday("Holiday.dat",ios::binary,ios::app);
ofstream get_place("Places.dat",ios::binary,ios::app);
ifstream read_pass("Password.dat",ios::binary);
int choice;
char pass[20];
Password p;
read_pass.read((char*)& p,sizeof(p));
cout<<"Password:";
gets(pass);
if(p.compare_pass(pass))
{
do
{
login_menu();
cin>>choice;
switch(choice)
{
case 1: Flight f;
f.assign();
get_flight.write((char*)& f,sizeof(f));
break;
case 2: Hotel h;
h.assign();
get_hotel.write((char*)& h,sizeof(h));
break;
case 3: Rail r;
r.assign();
get_rail.write((char*)& r,sizeof(r));
break;
case 4: Bus b;
b.assign();
get_bus.write((char*)& b,sizeof(b));
break;
case 5: Holiday h;
h.assign();
get_holiday.write((char*)& h,sizeof(h));
break;
case 6: Place p;
p.assign();
get_place.write((chr*)& p,sizeof(p));
break;
case 7: cout<<"Password:\n";
p.change_pass();
write_pass.write((char*)& p,sizeof(p));
break;
case 8: cout<<"\nExiting...\n";
break;
default:cout<<"\nInvalid option.\nAccess denied.";
}
}while(choice!=7);
}
else
cout<<"Invalid password!!\nAccess denied...";
}

void main()
{
cout<<"Welcome to KHK Travel Agency"<<endl;
int choice;
do{
menu();
cout<<"Enter your option:"<<endl;
cin>>choice;
switch(choice)
{
case 1: cout<<"Booking Flights\n";
read_info(choice);
if(c=search_flight())
{
book(c,choice);
}
else
{
cout<<"Sorry.There does not exist any flight between the destinations you entered.\n";
}
refresh();
break;
case 2: cout<<"Booking Hotels\n";
read_info(choice);
if(c=search_hotels())
{
book(c,choice);
}
else
{
cout<<"Sorry.There does not exist any hotel under our network in the place specified by you.\n";
}
refresh();
break;
case 3: cout<<"Online Railway Reservation\n";
read_info(choice);
if(c=search_rails())
{
book(c,choice);
}
else
{
cout<<"Sorry.No train routes exist between the stations you entered.\n";
}
refresh();
break;
case 4: cout<<"Online Bus Seats Booking\n";
read_info(choice);
if(c=search_buses())
{
book(c,choice);
}
else
{
cout<<"Sorry.No bus routes exist between the places you entered.\n";
}
refresh();
break;
case 5: cout<<"Planning Holidays\n";
holiday_info();
if(c=search_holidays())
{
book(c,choice);
}
else
{
cout<<"Sorry.Our travel agency does not arrange holidays in the city you entered.\n";
}
refresh();
break;
case 6: check_status();
break;
case 7: login();
break;
case 8: cout<<"Thank You for using KHK Travel Agency.\nPlease visit again.\n";
break;
default: cout<<"Invalid input!!\nPlease enter your option again.\n";
}
}while(choice!=7);
}

推荐答案

我要说几件事.

您发布的代码格式不正确.在您的帖子中选择代码,然后单击代码块".向其添加缩进以显示结构并使其更具可读性.我也认为发布一个职位太长了.更短的东西更好的格式将使人们更容易/更有可能阅读和阅读;帮助您.是的,您说的是,但这就是我的代码要花多长时间."好吧,您可以尝试暂时删除部分代码,以缩小显示该问题的范围.这甚至可以帮助您自己找到问题.

接下来,
您写的
I have several things to mention.

The code you posted is not well formatted. Select the code in your post and click on "code block". Add indentation to it to show the structure and make it more readable. I also think it is overly long for a post. Something shorter & better formatted would be easier/more likely for people to read & help you with. Yes, you are saying, "but that''s how long my code is." Well, you could try to temporarily remove parts of your code to get something smaller that exhibits the problem. This could even help you find the problem yourself.

Next,
:

在编译时出现异常13错误

while compiling i got an exception 13 error


我确信这是不正确的.由于您发布了错误消息,所以我不太有把握.构建程序时,有:预处理,编译和链接时间.在这之后有运行时间.我相信您的一般保护错误(例外13)在运行时.在头脑中清楚流程对于沟通和自己弄清事情很重要. (在编译时使用GPF是有可能的-我已经看到了等效的方法.)

您使用的编译器的时间大约在1990年到1995年之间.那时真不错.但是,在1990年代对C ++语言进行了更改,这对该语言产生了深远的影响.该语言的标准于1998年正式发布.您的编译器将无法处理标准C ++.它接受的方言不适用于大多数希望使用的标准兼容编译器(希望如此).它也可能与Windows XP不完全兼容.

我最近遇到了一个客户,该客户试图将Turbo C 3.0版放在Windows XP上以支持非常旧的C(不是C ++)DOS项目.事实证明,某些源代码文件的(DOS合法)名称在XP下的Turbo C中触发了一些错误,尽管在Windows的早期版本中运行时没有问题.您可能正在经历类似的事情.如果确实需要使用此编译器,则可以尝试挖掘Windows 95或98机器来使用它.如果将来要学习C ++,则应继续使用现代编译器. Microsoft具有其编译器的快速版本,可以免费下载.

现在,如果您在Windows上使用的是相当现代的编译器,并且这种编译器在运行时发生,那么您将可以选择启动调试器.这至少可以告诉您代码在哪里死亡.这可能是找出问题的起点.

最后,浏览一下您的代码,我可以看到许多问题.您将需要努力找到它们.我在这里只指出三个.

1)您的代码中有:


I was confident that this is inaccurate. Since you posted the error message I am not so confident. When building a program there is: pre-processing, compile, and link time. After this there is run time. I believe that your General Protection Fault (exception 13) is at run-time. It is important to have the process clear in your head both for communication and for figuring things out yourself. ( A GPF at compile time is a potential - I have seen the equivalent. )

The compiler you are using is from somewhere around 1990 to 1995. It was good then. However, changes were made to the C++ language in the 1990s that had a profound affect on the language. The standard for the language was officially released in 1998. Your compiler will not handle standard C++. The dialect it does accept is not appropriate for a standards compliaint compiler like (hopefully) most of use are using. It may also not be fully compatible with Windows XP.

I have recently dealt with a client who was trying to put Turbo C version 3.0 on Windows XP to support a very legacy C (not C++) DOS project. It turned out that the (DOS legal) names of some of the source code files were triggering some error in Turbo C under XP, though there had been no problem when running under earlier versions of Windows. You may be experiencing something similar. If you really, really have to use this compiler, you might try digging out a Windows 95 or 98 machine to go with it. If you are learning C++ for the future, you should move on to a modern compiler. Microsoft has an express edition of their compiler that can be downloaded for free.

Now, if you were using a reasonably modern compiler on Windows and this occurred at runtime, you would be getting an option to start the debugger. This would at least tell you where your code died. This could be a starting point to figuring out your problem.

Finally, in glancing over your code I can see a number of issues. You are going to need to work on it to find them all. I will only point out three here.

1) You have in your code:

if((day>0)||(day<32)||(month>0)||(month<13)||(year>2009)||(year<2014))


该测试将永远不会失败.您写的不是您想要的,您将需要考虑并修复它.但是,这不是导致异常的原因13.

2)您同时使用gets()和std :: cin作为输入.它们可能会相互干扰.选择一个并坚持下去.

3)您正在不同位置向char数组中输入数据.如果输入的时间超出您的允许范围,则可能会发生错误的事情-包括GPF.这或类似的东西很可能是您的问题.考虑改用std :: string(与std :: cin一起使用).注意:您当前的编译器没有此代码.


This test will never fail. What you wrote was not what you intended and you will need to think about it and fix it. It is not, however, the cause of your exception 13.

2) You are using both gets() and std::cin for input. They are likely to interfere with each other. Choose one and stick to it.

3) You are doing input into char arrays at various places. If the input is longer than you have allowed for, Bad Things can happen - including a GPF. This or something like it could very well be your problem. Consider using std::string (with std::cin) instead. Note: Your current compiler does not have this.


编译器错误包含有用的信息,例如,它们指示发生错误的源代码行. 请仅发布相关代码和完整的编译器错误消息.
:)
Compiler errors are full of useful information, for instance, they indicate the line of the source code wherein the error occurs.
Please post just the relevant code and the full compiler error message.
:)


写道:​​

#include< iostream.h>

#include<iostream.h>



这不是有效的C ++.如果您的老师认为是这样,请找一位新老师.



This is not valid C++. If your teacher thinks it is, find a new teacher.


这篇关于例外13的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆