0% found this document useful (0 votes)
4 views6 pages

Include

The document contains a C program that manages flight information, allowing users to input flight details such as flight code, airline, departure and arrival locations, departure time, and ticket price. It includes functions for entering flight data, displaying the list of flights, sorting them by flight code, and searching for flights based on price range or airline. The program utilizes structures to store flight information and provides a user-friendly interface for interaction.

Uploaded by

24107963
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Include

The document contains a C program that manages flight information, allowing users to input flight details such as flight code, airline, departure and arrival locations, departure time, and ticket price. It includes functions for entering flight data, displaying the list of flights, sorting them by flight code, and searching for flights based on price range or airline. The program utilizes structures to store flight information and provides a user-friendly interface for interaction.

Uploaded by

24107963
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include <stdio.

h>
#include <string.h>
#include <stdlib.h>

struct thongtin {
char machuyenbay[20];
char hanghangkhong[20];
char diemdi[20];
char diemden[20];
char tgkhoihanh[20];
float giave;
};
typedef struct thongtin tt;

// Hàm nhập số lượng và danh sách chuyến bay


void nhapDanhSach(tt ds[], int *n) {
do {
printf("Nhap so luong chuyen bay (n > 0): ");
scanf("%d", n);
} while (*n <= 0);

for (int i = 0; i < *n; i++) {


printf("\n--- Nhap thong tin chuyen bay thu %d ---\n", i + 1);
printf("Nhap ma chuyen bay: ");
scanf("%s", ds[i].machuyenbay);
printf("Nhap hang hang khong: ");
scanf("%s", ds[i].hanghangkhong);
printf("Nhap diem di: ");
scanf("%s", ds[i].diemdi);
printf("Nhap diem den: ");
scanf("%s", ds[i].diemden);
printf("Nhap thoi gian khoi hanh (hh:mm dd/mm/yyyy): ");
scanf(" %[^\n]", ds[i].tgkhoihanh); // Đọc chuỗi có chứa khoảng trắng
printf("Nhap gia ve (trieu VND): ");
scanf("%f", &ds[i].giave);
}
}

int main() {
tt ds[100];
int n;
nhapDanhSach(ds, &n);
return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
char maCB[11];
char hang[16];
char diemDi[16];
char diemDen[16];
char tgKhoiHanh[20];
float giaVe;
} ChuyenBay;

void nhapDanhSach(ChuyenBay ds[], int *n) {


do {
printf("Nhap so luong chuyen bay (n > 0): ");
scanf("%d", n);
} while (*n <= 0);

for (int i = 0; i < *n; i++) {


printf("\nNhap thong tin chuyen bay thu %d:\n", i + 1);
printf("Ma chuyen bay: ");
scanf("%s", ds[i].maCB);
printf("Hang hang khong: ");
scanf("%s", ds[i].hang);
printf("Diem di: ");
scanf("%s", ds[i].diemDi);
printf("Diem den: ");
scanf("%s", ds[i].diemDen);
printf("Thoi gian khoi hanh (hh:mm dd/mm/yyyy): ");
scanf(" %[^\n]", ds[i].tgKhoiHanh); // dùng %[^\n] để đọc chuỗi có chứa dấu
cách
printf("Gia ve (trieu VND): ");
scanf("%f", &ds[i].giaVe);
}
}
void inDanhSach(ChuyenBay ds[], int n) {
printf("------------------------------------------------------------------------------------------\n");
printf("| STT | Ma chuyen bay | Hang bay | Diem di | Diem den | TG khoi
hanh | Gia ve |\n");
printf("------------------------------------------------------------------------------------------\n");
for (int i = 0; i < n; i++) {
printf("| %-3d | %-13s | %-12s | %-11s | %-11s | %-19s | %-13.0f |\n",
i + 1, ds[i].maCB, ds[i].hang, ds[i].diemDi, ds[i].diemDen,
ds[i].tgKhoiHanh, ds[i].giaVe * 1000000);
}
printf("------------------------------------------------------------------------------------------\n");
}

void sapXepTheoMaCB(ChuyenBay ds[], int n) {


for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (strcmp(ds[i].maCB, ds[j].maCB) > 0) {
ChuyenBay temp = ds[i];
ds[i] = ds[j];
ds[j] = temp;
}
}
}
}

void timTheoGia(ChuyenBay ds[], int n, float b, float c) {


printf("Cac chuyen bay co gia ve trong khoang %.2f den %.2f trieu VND:\n", b, c);
for (int i = 0; i < n; i++) {
if (ds[i].giaVe >= b && ds[i].giaVe <= c) {
printf("Ma CB: %s | Hang: %s | Gia: %.2f trieu\n", ds[i].maCB, ds[i].hang,
ds[i].giaVe);
}
}
}

void timTheoHang(ChuyenBay ds[], int n, char hangTK[]) {


printf("Cac chuyen bay thuoc hang '%s':\n", hangTK);
for (int i = 0; i < n; i++) {
if (strcmp(ds[i].hang, hangTK) == 0) {
printf("Ma CB: %s | Diem di: %s | Diem den: %s\n", ds[i].maCB, ds[i].diemDi,
ds[i].diemDen);
}
}
}

int main() {
ChuyenBay ds[100];
int n;
nhapDanhSach(ds, &n);

printf("\n--- DANH SACH CHUYEN BAY ---\n");


inDanhSach(ds, n);

printf("\n--- DANH SACH SAU KHI SAP XEP ---\n");


sapXepTheoMaCB(ds, n);
inDanhSach(ds, n);

float b, c;
printf("\nNhap khoang gia b den c de tim chuyen bay:\n");
printf("b = "); scanf("%f", &b);
printf("c = "); scanf("%f", &c);
timTheoGia(ds, n, b, c);

char hangTK[16];
printf("\nNhap ten hang de tim chuyen bay: ");
scanf("%s", hangTK);
timTheoHang(ds, n, hangTK);

return 0;
}

You might also like