做了个C语言的,怎么转换成C++输出输入呢?
#include<stdio.h>#include<stdlib.h>
#include<dos.h>
#include<time.h>
#include<conio.h>
#include<string.h>
const int MAX=20;
const int N=50;
const int MAXFILENAME=100;
enum {FALSE,TRUE};
struct time
{
int hour;
int minutes;
};
struct ticket
{
int SerialNumber;
struct time SetOut;
char DeparturePoint[MAX];
char TerminalPoint[MAX];
float LastTime;
int FixNumber;
int FixedNumber;
}car[N];
int RecordNumber;
int FLAG=FALSE;
/**********************************************/
int ShowMessage(void); //载入原始数据
void mainmenu(void); //主菜单
void InsertMessage(void); //录入班次信息
void SearchMenu(void); //查询路线子菜单
void SearchByNumber(void); //按班次号查询
void SearchByAddress(void); //按终点站查询
void TicketManagement(void); //车票售出与退回
void TicketOrder(void); //售票
void TicketDelete(void); //退票
void exit(void); //退出该系统
/********************************************/
int main(void)
{
RecordNumber=ShowMessage();
if(1)
do
{
mainmenu();
}while(FLAG==FALSE);
return 0;
}
void mainmenu(void)
{
system("color 1f");
system("mode con: cols=140 lines=130");
char functionNumber;
printf(" 欢迎使用车票管理系统\n\n");
printf(" 1.录入班次信息\t\n");
printf(" 2.浏览班次信息\t\n");
printf(" 3.查询行车路线\t\n");
printf(" 4.售票与退票系统\t\n");
printf(" 5.退出该系统\t\n");
printf("============================================================================\n");
printf("请选择你所需要的功能:");
scanf("%c",&functionNumber);
switch(functionNumber)
{
case '1':
{
InsertMessage();
printf("\n按任意键回主菜单......\n");
getchar();
getchar();
}
break;
case '2':
{
ShowMessage();
printf("\n按任意键回主菜单......\n");
getchar();
getchar();
}
break;
case '3':
{
SearchMenu();
printf("\n按任意键回主菜单......\n");
getchar();
getchar();
}
break;
case '4':
{
TicketManagement();
getchar();
getchar();
}
break;
case '5':FLAG=TRUE;exit();break;
default:
{
printf("输入错误,请确保你的输入为1--5.\n");
printf("按任意键回主菜单......\n");
getchar();
getchar();
}
}//switch ends
FLAG=FALSE;
}
void InsertMessage(void)
{
FILE *fp;
char filename[MAXFILENAME];
int i;
printf("请输入文件名或者文件路径名:");
scanf("%s",filename);
if((fp=fopen(filename,"r"))==NULL)
{
printf("文件%s不可读,请确认文件%s存在或者文件路径正确.\n\n",filename,filename);
mainmenu();
}
for(i=RecordNumber;!feof(fp)&&!ferror(fp);i++)
{
fscanf(fp,"%d %d %d",&car[i].SerialNumber,&car[i].SetOut.hour,&car[i].SetOut.minutes);
fscanf(fp,"%s %s %f %d %d",&car[i].DeparturePoint,&car[i].TerminalPoint,&car[i].LastTime,&car[i].FixNumber,&car[i].FixedNumber);
}
int count=i;
printf("班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n");
for(i=0;i<count;i++)
{
printf("%d\t%d:%d\t\t",car[i].SerialNumber,car[i].SetOut.hour,car[i].SetOut.minutes);
printf("%s\t%s\t\t%.1f\t %d\t\t%d\n",car[i].DeparturePoint,car[i].TerminalPoint,car[i].LastTime,car[i].FixNumber,car[i].FixedNumber);
}
fclose(fp);
}
int ShowMessage(void)
{
int i;
FILE *fp;
if((fp=fopen("add.txt","r"))==NULL)
{
printf("读取数据失败,请检查文件add.txt是否存在.\n");
exit(-1);
}
for(i=0;!feof(fp)&&!ferror(fp);i++)
{
fscanf(fp,"%d%d%d",&car[i].SerialNumber,&car[i].SetOut.hour,&car[i].SetOut.minutes);
fscanf(fp,"%s%s%f%d%d",&car[i].DeparturePoint,&car[i].TerminalPoint,&car[i].LastTime,&car[i].FixNumber,&car[i].FixedNumber);
}
int count=i;
printf("班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n");
for(i=0;i<count;i++)
{
printf("%d\t%d:%d\t\t",car[i].SerialNumber,car[i].SetOut.hour,car[i].SetOut.minutes);
printf("%s\t%s\t\t%.1f\t %d\t\t%d\n",car[i].DeparturePoint,car[i].TerminalPoint,car[i].LastTime,car[i].FixNumber,car[i].FixedNumber);
}
return count;
}
void SearchMenu(void)
{
system("color 1f");
system("mode con: cols=140 lines=130");
char functionNumber;
printf(" 查询子菜单\n");
printf("============================================================================\n");
printf(" 1.按班次号查询\t\n");
printf(" 2.按终点站查询\t\n");
printf(" 3.返回主菜单\t\n");
printf("============================================================================\n");
printf("请选择你所需要的功能:");
scanf("%*c%c",&functionNumber);
switch(functionNumber)
{
case '1':SearchByNumber();break;
case '2':SearchByAddress();break;
case '3':
getchar();
mainmenu();
break;
default:
printf("输入错误,请确保你的输入为1--3.\n");
printf("按任意键回查询子菜单......\n");
getchar();
getchar();
SearchMenu();
}
}
void SearchByNumber(void)
{
int SearchNumber;
printf("请输入要查询的班次号:");
scanf("%d",&SearchNumber);
printf("班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n");
printf("%d\t%d:%d\t\t",car[SearchNumber-1].SerialNumber,car[SearchNumber-1].SetOut.hour,car[SearchNumber-1].SetOut.minutes);
printf("%s\t%s\t\t%.1f\t %d\t\t%d\n",car[SearchNumber-1].DeparturePoint,car[SearchNumber-1].TerminalPoint,car[SearchNumber-1].LastTime,car[SearchNumber-1].FixNumber,car[SearchNumber-1].FixedNumber);
}
void SearchByAddress(void)
{
int i;
char Address[MAX];
printf("请输入终点站的名称:");
scanf("%s",&Address);
printf("班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n");
for(i=0;i<RecordNumber;i++)
{
//对比终点站记录,找到并输出
if((strcmp(Address,car[i].TerminalPoint))==0)
{
printf("%d\t%d:%d\t\t",car[i].SerialNumber,car[i].SetOut.hour,car[i].SetOut.minutes);
printf("%s\t%s\t\t%.1f\t %d\t\t%d\n",car[i].DeparturePoint,car[i].TerminalPoint,car[i].LastTime,car[i].FixNumber,car[i].FixedNumber);
}
}
}
void TicketManagement(void)
{
char functionNumber;
system("color 1f");
system("mode con: cols=140 lines=130");
printf(" 订票与退票菜单\n");
printf("============================================================================\n");
printf(" 1.订票\t\n");
printf(" 2.退票\t\n");
printf(" 3.返回主菜单.\n");
printf("============================================================================\n");
printf("选择你需要的功能:");
scanf("%*c%c",&functionNumber);
switch(functionNumber)
{
case '1':
{
TicketOrder();
//getchar();
//getchar();
}
break;
case '2':TicketDelete();break;
case '3':
{
getchar();
mainmenu();
}
break;
default:
{
printf("输入错误,请确保你的输入为1--3.\n");
printf("按任意键回主菜单......\n");
getchar();
getchar();
mainmenu();
}
}
}
void TicketOrder(void)
{
int i;
printf("请输入要订购的车票的班次:");
scanf("%d",&i);
if(i<0||i>RecordNumber)
{
printf("对不起,今天没有这趟车,谢谢使用!\n");
printf("按任意键回主菜单......\n");
getchar();//getchar();
TicketManagement();
}
time_t tval;
struct tm *now;
tval = time(NULL);
now = localtime(&tval);
if((now->tm_hour==car[i].SetOut.hour&&now->tm_min<car[i].SetOut.minutes)||(now->tm_hour<car[i].SetOut.hour))
{
if(car[i].FixedNumber<car[i].FixNumber)
{
car[i].FixedNumber++;
printf("你的订票成功,谢谢使用!\n");
}
else printf("对不起,今天的这趟车的票已卖完!\n");
}
else printf("对不起,今天的这趟车已发出!\n");
printf("班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n");
printf("%d\t%d:%d\t\t",car[i-1].SerialNumber,car[i-1].SetOut.hour,car[i-1].SetOut.minutes);
printf("%s\t%s\t\t%.1f\t %d\t\t%d\n",car[i-1].DeparturePoint,car[i-1].TerminalPoint,car[i-1].LastTime,car[i-1].FixNumber,car[i-1].FixedNumber);
//printf("按任意键回主菜单......\n");
//getchar();getchar();
}
void TicketDelete(void)
{
int i;
printf("请输入要退购的车票的班次:");
scanf("%d",&i);
if(i<0||i>RecordNumber)
{
printf("对不起,今天没有这趟车,无法完成退票.谢谢使用!\n");
getchar();
//getchar();
TicketManagement();
getchar();
}
time_t tval;
struct tm *now;
tval = time(NULL);
now = localtime(&tval);
if((now->tm_hour==car[i].SetOut.hour&&now->tm_min<car[i].SetOut.minutes)||(now->tm_hour<car[i].SetOut.hour))
{
if(car[i].FixedNumber>=1)
{
car[i].FixedNumber--;
printf("退订车票成功,谢谢使用!\n");
}
else printf("对不起,今天的这趟车的票尚未卖出,无法完成退票!\n");
}
else printf("对不起,今天的这趟车已发出,无法完成退票!\n");
printf("班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n");
printf("%d\t%d:%d\t\t",car[i-1].SerialNumber,car[i-1].SetOut.hour,car[i-1].SetOut.minutes);
printf("%s\t%s\t\t%.1f\t %d\t\t%d\n",car[i-1].DeparturePoint,car[i-1].TerminalPoint,car[i-1].LastTime,car[i-1].FixNumber,car[i-1].FixedNumber);
getchar();//getchar();
}
void exit(void)
{
printf("\n\n*********************谢谢使用本系统,欢迎下次继续使用***********************\n");
exit(0);
}
#include<stdio.h>
#include<time.h>
#include<string.h>
typedef struct information
{
int numb;
char starttime[10];
char begin[21];
char end[21];
float lasttime;
int canload;
int alreadyload;
}INFORMATION;
void AddInformation(void)
{
FILE *fp;
INFORMATION info;
printf("please input the information you want to insert,input 0 to return back:\n");
scanf("%d", &info.numb);
if(info.numb == 0) return;
scanf("%s%s%s%f%d%d", info.starttime, info.begin, info.end, &info.lasttime, &info.canload, &info.alreadyload);
if((fp = fopen("c:\\information.txt", "a+")) == 0)
{
printf("open file error!");
exit(0);
}
fprintf(fp, "%d %s %s %s %f %d %d\n", info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
fclose(fp);
}
int GetHour(char *s)
{
char *p, *q;
p = (char *)malloc(10);
strcpy(p, s);
q = p;
while(*q != ':')
{
q++;
}
*q = '\0';
return atoi(p);
}
int GetMinute(char *s)
{
char *p;
p = (char *)malloc(10);
strcpy(p, s);
while(*p != ':')
{
p++;
}
p++;
return atoi(p);
}
void ShowInformation(void)
{
FILE *fp;
INFORMATION info;
time_t t;
struct tm *timeinfo;
if((fp = fopen("c:\\information.txt", "r+")) == 0)
{
printf("open file error!");
exit(0);
}
time(&t);
timeinfo = localtime(&t);
while(!feof(fp))
{
fscanf(fp, "%d%s%s%s%f%d%d\n", &info.numb, info.starttime, info.begin, info.end, &info.lasttime, &info.canload, &info.alreadyload);
printf("%d %s %s %s %f %d %d ", info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
if(GetHour(info.starttime) < timeinfo->tm_hour) printf("此班已发出!\n");
else if(GetHour(info.starttime) == timeinfo->tm_hour)
{
if(GetMinute(info.starttime)<=timeinfo->tm_min) printf("此班已发出!\n");
else printf("\n");
}
else printf("\n");
}
fclose(fp);
}
void SearchbyNum(void)
{
FILE *fp;
INFORMATION info;
int bc;
printf("please input the number,input 0 to return back:\n");
scanf("%d", &bc);
if(0 == bc) return;
if((fp = fopen("c:\\information.txt", "r+")) == 0)
{
printf("open file error!");
exit(0);
}
while(!feof(fp))
{
fscanf(fp, "%d%s%s%s%f%d%d\n", &info.numb, info.starttime, info.begin, info.end, &info.lasttime, &info.canload, &info.alreadyload);
if(info.numb == bc)
{
printf("%d %s %s %s %f %d %d\n", info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
}
}
fclose(fp);
}
void SearchbyEnd(void)
{
FILE *fp;
INFORMATION info;
char zhongdian[100];
printf("please input the place,input 0 to return back:\n");
scanf("%s", zhongdian);
if(strcmp(zhongdian, "0") == 0) return;
if((fp = fopen("c:\\information.txt", "r+")) == 0)
{
printf("open file error!");
exit(0);
}
while(!feof(fp))
{
fscanf(fp, "%d%s%s%s%f%d%d\n", &info.numb, info.starttime, info.begin, info.end, &info.lasttime, &info.canload, &info.alreadyload);
if(strcmp(zhongdian, info.end) == 0)
{
printf("%d %s %s %s %f %d %d\n", info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
}
}
fclose(fp);
}
void SearchWay(void)
{
int i;
printf("1. search by number\n");
printf("2. search by end\n");
printf("0. return back\n");
printf("which way do you want?\n");
scanf("%d", &i);
switch(i)
{
case 1: SearchbyNum(); break;
case 2: SearchbyEnd(); break;
case 0: return;
default : break;
}
}
void Buy(void)
{
FILE *fp;
INFORMATION info;
time_t t;
struct tm *timeinfo;
int bc;
long pos, pos1;
printf("please input the banci you want to buy,input 0 to return back:\n");
scanf("%d", &bc);
if(0 == bc) return;
if((fp = fopen("c:\\information.txt", "r+")) == 0)
{
printf("open file error!");
exit(0);
}
time(&t);
timeinfo = localtime(&t);
while(1)
{
pos1 = ftell(fp);
fscanf(fp, "%d%s%s%s%f%d%d\n", &info.numb, info.starttime, info.begin, info.end, &info.lasttime, &info.canload, &info.alreadyload);
pos = ftell(fp) - pos1;
if(info.numb == bc)
{
if(info.alreadyload < info.canload)
{
if(GetHour(info.starttime) < timeinfo->tm_hour)
{
printf("sorry, the plane has taken off!");
}
else if(GetHour(info.starttime) == timeinfo->tm_hour)
{
if(GetMinute(info.starttime) <= timeinfo->tm_min) printf("sorry, the plane has taken off!");
else
{
printf("take your ticket, bye!");
info.alreadyload ++;
fseek(fp, -pos, SEEK_CUR);
fprintf(fp, "%d %s %s %s %f %d %d\n", info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
}
}
else
{
printf("take your ticket, bye!");
info.alreadyload ++;
fseek(fp, -pos, SEEK_CUR);
fprintf(fp, "%d %s %s %s %f %d %d\n", info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
}
}
else printf("sorry, the tickets are all sold out!");
break;
}
}
fclose(fp);
}
void Cancel(void)
{
FILE *fp;
INFORMATION info;
time_t t;
struct tm *timeinfo;
int bc;
long pos, pos1;
printf("please input the banci you want to cancel,input 0 to return back:\n");
scanf("%d", &bc);
if(0 == bc) return;
if((fp = fopen("c:\\information.txt", "r+")) == 0)
{
printf("open file error!");
exit(0);
}
time(&t);
timeinfo = localtime(&t);
while(1)
{
pos1 = ftell(fp);
fscanf(fp, "%d%s%s%s%f%d%d\n", &info.numb, info.starttime, info.begin, info.end, &info.lasttime, &info.canload, &info.alreadyload);
pos = ftell(fp) - pos1;
if(info.numb == bc)
{
if(GetHour(info.starttime) < timeinfo->tm_hour)
{
printf("sorry, the plane has taken off!");
}
else if(GetHour(info.starttime) == timeinfo->tm_hour)
{
if(GetMinute(info.starttime) <= timeinfo->tm_min) printf("sorry, the plane has taken off!");
else
{
printf("your ticket is canceled, bye!");
info.alreadyload --;
fseek(fp, -pos, SEEK_CUR);
fprintf(fp, "%d %s %s %s %f %d %d\n", info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
}
}
else
{
printf("your ticket is canceled, bye!");
info.alreadyload --;
fseek(fp, -pos, SEEK_CUR);
fprintf(fp, "%d %s %s %s %f %d %d\n", info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
}
break;
}
}
fclose(fp);
}
void ForTicket(void)
{
int i;
printf("1. I want to buy a ticket\n");
printf("2. I want to return a ticket\n");
printf("0. return back\n");
printf("which do you want?");
scanf("%d", &i);
switch(i)
{
case 1: Buy(); break;
case 2: Cancel(); break;
case 0: return;
default : break;
}
}