下面展示一些 内联代码片
。
参考源码
#include <stdio.h>
#include <string.h>
//企鹅联系-----------------3765140556
#define MAX_FLIGHTS 100
#define MAX_ORDERS 100
#define MAX_USERS 100
// 用户结构体
typedef struct {
char username[50];
char password[50];
} User;
// 航班结构体
typedef struct {
int id;
char name[50];
char destination[50];
int seats;
} Flight;
// 订单结构体
typedef struct {
int id;
char name[50];
int flight_id;
} Order;
User users[MAX_USERS];
Flight flights[MAX_FLIGHTS];
Order orders[MAX_ORDERS];
int num_flights = 0;
int num_orders = 0;
int num_users = 0;
void registerUser() {
// 实现用户注册功能
if (num_users < MAX_USERS) {
printf("请输入用户名:");
scanf("%s", users[num_users].username);
printf("请输入密码:");
scanf("%s", users[num_users].password);
num_users++;
printf("注册成功!\n");
} else {
printf("用户数量已达上限,无法注册新用户。\n");
}
}
int loginUser() {
// 实现用户登录功能
char username[50];
char password[50];
printf("请输入用户名:");
scanf("%s", username);
printf("请输入密码:");
scanf("%s", password);
for (int i = 0; i < num_users; i++) {
if (strcmp(users[i].username, username) == 0 && strcmp(users[i].password, password) == 0) {
return 1; // 登录成功
}
}
return 0; // 登录失败
}
void addFlight() {
// 实现航班添加功能
// 可以使用结构体来存储航班信息
struct Flight {
char flightNo[10];
char departure[20];
char destination[20];
char date[10];
char time[6];
int price;
int seats;
} flight;
printf("请输入航班号:");
scanf("%s", flight.flightNo);
printf("请输入起点城市:");
scanf("%s", flight.departure);
printf("请输入终点城市:");
scanf("%s", flight.destination);
printf("请输入日期(格式为yyyy-mm-dd):");
scanf("%s", flight.date);
printf("请输入时间(格式为hh:mm):");
scanf("%s", flight.time);
printf("请输入票价:");
scanf("%d", &flight.price);
printf("请输入座位数:");
scanf("%d", &flight.seats);
// 将航班信息保存到文件中
FILE *fp = fopen("flights.dat", "ab");
if (fp == NULL) {
printf("无法打开文件。\n");
return;
}
fwrite(&flight, sizeof(flight), 1, fp);
fclose(fp);
printf("航班添加成功。\n");
}
void viewFlights() {
// 实现查看航班功能
// 从文件中读取航班信息并输出
struct Flight {
char flightNo[10];
char departure[20];
char destination[20];
char date[10];
char time[6];
int price;
int seats;
} flight;
FILE *fp = fopen("flights.dat", "rb");
if (fp == NULL) {
printf("无法打开文件。\n");
return;
}
printf("航班号\t起点城市\t终点城市\t日期\t时间\t票价\t座位数\n");
while (fread(&flight, sizeof(flight), 1, fp) == 1) {
printf("%s\t%s\t%s\t%s\t%s\t%d\t%d\n", flight.flightNo, flight.departure, flight.destination, flight.date, flight.time, flight.price, flight.seats);
}
fclose(fp);
}