By GokiSoft.com| 20:33 27/09/2023|
Lập Trình C

Quản lý rạp chiếu phim quốc gia - Assignment - Lập trình C



Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Đỗ Minh Tâm [community,C2010G]
Đỗ Minh Tâm

2020-12-25 01:11:32



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

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
typedef struct Cinema{
	char name[25],address[35];
	int Seats;
}cinema;
int main(int argc, char *argv[]) {
	int choose,a,min,maxs,tmp;
	cinema cinemalist[4];
	do{
		printf("\n1.Nhap du lieu quan ly danh sach rap chieu phim.");
		printf("\n2.Hien thi danh sach rap ra man hinh.");
		printf("\n3.Tim rap theo so ghe toi thieu.");
		printf("\n4.luu du lieu ra tep cinema.dat");
		printf("\n5.Doc du lieu tu tep cinema.dat");
		printf("\n6.Thoat.");
		printf("\nchoose=");
		scanf("%d",&choose);
		switch(choose){
			case 1:
				for(a=0;a<4;a++){
					printf("Nhap ten rap chieu phim thu %d: ",a+1);
					fflush(stdin);fflush(stdout);
						gets(cinemalist[a].name);
					printf("Nhap dia chi rap thi %d: ",a+1);
					fflush(stdin);fflush(stdout);
						gets(cinemalist[a].address);
					printf("Nhap so luong ghe cua rap thu %d: ",a+1);
					scanf("%d", &cinemalist[a].Seats);
				}
				break;
			case 2:
				printf("\n%-10s| %-30s| %-10s|\n", "ten rap", "dia chi", "so ghe");
				for(a=0;a<4;a++){
					printf("\n%s | %s| %d |\n",cinemalist[a].name, cinemalist[a].address, cinemalist[a].Seats);}
				break;
			case 3:
				printf("Nhap so ghe toi thieu min= ");
				scanf("%d",&min);
				maxs=cinemalist[0].Seats;
				for(a=0;a<4;a++){
					if(cinemalist[a].Seats>maxs){
						maxs=cinemalist[a].Seats;
					}
				}
				for(a=0;a<4;a++){
					if(cinemalist[a].Seats>=min){
						printf("\n%-10s| %-30s| %-10s|\n", "ten rap", "dia chi", "so ghe");
						printf("\n%s | %s| %d |\n",cinemalist[a].name, cinemalist[a].address, cinemalist[a].Seats);
					}else if(min>maxs){
						printf("Khong co rap nao phu hop.");
					}
					}
					
				
				break;
			case 4:
				break;
			case 5:
				break;
			case 6:
				printf("\nGoodbye!!!");
			default:
				printf("\nNhap sai!!!");
				break;
			
		}
	}while(choose!=6);
	return 0;



Triệu Văn Lăng [T2008A]
Triệu Văn Lăng

2020-10-12 08:30:02



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
  
  
void showMenu() {
	printf("\nchon 1 de nhap du lieu quan den rap chieu phim");
	printf("\nchon 2 de hien thi danh sach rap ");
	printf("\nchon 3 de tim rap theo so ghe");
	printf("\nchon 4 de luu tep");
	printf("\nchon 5 de doc tep");
	printf("\nchon 6 de thoat");
	printf("\nmoi chon: ");
}
typedef struct cinema_ST{
	char name[25], address[35];
	int seats;
} cinema;

void inputcinemaList(cinema *p){
	int i;
	for(i=0;i<4;i++) {
	printf("\nhap ten rap thu %d ",i+1);
	fflush(stdin);fflush(stdout);
	gets(p[i].name);
	printf("\nnhap dia chi: ");
	fflush(stdin);fflush(stdout);
    gets(p[i].address);
    printf("\nnhap so ghe: ");
    scanf("%d",&p[i].seats);
    }
}

void sx(cinema *p){
	int i, j;
	for(i=0;i<3;i++){
		for(j=i+1;j<4;j++){
			int cmp=strcmp(p[i].name, p[j].name);
			if(cmp>0){
				cinema tmp=p[i];
				p[i]=p[j];
				p[j]=tmp;
			}
		}
	}
}

void displaycinemaList(cinema *p){
	int i, j;
	printf("\n");
	for(i=0;i<70;i++) {
		printf("-");
	}
	printf("\n|%25s|%35s|%6s|", "Name", "Address", "Seats");
	printf("\n");
	for(i=0;i<70;i++) {
		printf("-");
	}
	for(i=0;i<4;i++) {
		printf("\n|%25s|%35s|%6d|", p[i].name, p[i].address, p[i].seats);
		printf("\n");
		for(j=0;j<70;j++) {
			printf("-");
		}
}
}
void searchByMinSeats(cinema *p) {
	int i, j, minSeats;
	printf("\nNhap so ghe toi thieu can tim: ");
	scanf("%d", &minSeats);
	
	printf("\n");
	for(i=0;i<70;i++) {
		printf("-");
	}
	printf("\n|%25s|%35s|%6s|", "Name", "Address", "Seats");
	printf("\n");
	for(i=0;i<70;i++) {
		printf("-");
	}
	int count = 0;
	
	for(i=0;i<4;i++) {
		if(p[i].seats >= minSeats) {
			count++;
			printf("\n|%25s|%35s|%6d|", p[i].name, p[i].address, p[i].seats);
			printf("\n");
			for(j=0;j<70;j++) {
				printf("-");
			}
		}
	}
	
	if(count == 0) {
		printf("\nKhong co rap nao phu hop");
	}
}

void saveFile(cinema *p) {
	FILE *fp;
	fp = fopen("cinema.dat", "wb");
	fwrite(p, sizeof(cinema), 4, fp);
	fclose(fp);
}

void readFile(cinema *p) {
	FILE *fp;
	fp = fopen("cinema.dat", "rb");
	fread(p, sizeof(cinema), 4, fp);
	fclose(fp);
}

int main(int argc, char *argv[]) {
	cinema cinemaList[4];
	int n;
	do{
		showMenu();
		scanf("%d",&n);
		switch(n){
			case 1:
				inputcinemaList(cinemaList);
				break;
			case 2:
				sx(cinemaList);
				displaycinemaList(cinemaList);
			    break;
			case 3:
				searchByMinSeats(cinemaList);
			    break;
			case 4:
				saveFile(cinemaList);
			    break;
			case 5:
				readFile(cinemaList);
			    break;
			case 6:
				printf("\nket thuc");
			    break;
			default:
			    printf("\nnhap sai");
				break; 					
		}
}
		
	  while(n!=6);
	return 0;
}



Nguyễn Tiến Đạt [T2008A]
Nguyễn Tiến Đạt

2020-10-03 02:00:41



//Assignment Quan li rap chieu phim(checked)
#include <stdio.h>
#include <stdlib.h>
#include<string.h>

typedef struct Cinema_ST{
	char name[25],address[35];
	int seats;
}Cinema;

void Menu(){
	printf("\n1.Nhap du lieu quan li danh sach rap chieu phim");
	printf("\n2.Hien thi danh sach rap ra man hinh");
	printf("\n3.Tim rap theo so ghe toi thieu");
	printf("\n4.Luu du lieu ra tep cinema.dat");
	printf("\n5.Doc du lieu tu tep cinema.dat");
	printf("\n6.Thoat");
}

void inputcinemaList(Cinema *p){
	int i;
	for(i=0;i<4;i++){
		fflush(stdin);fflush(stdout);
		printf("\nNhap ten rap chieu phim thu %d: ",i+1);
		gets(p[i].name);
		fflush(stdin);fflush(stdout);
		printf("\nNhap dia chi rap: ");
		gets(p[i].address);
		fflush(stdin);fflush(stdout);
		printf("\nNhap so luong ghe: ");
		scanf("%d",&p[i].seats);
		fflush(stdin);fflush(stdout);
	}
}

void sort(Cinema *p){
	int i,j;
	for(i=0;i<3;i++){
		for(j=i+1;j<4;j++){
			int cmp= strcmp(p[i].name,p[j].name);
			if(cmp>0){
				Cinema temp=p[i];
				p[i]=p[j];
				p[j]=temp;
			}
		}
	}
}

void displaycinemaList(Cinema *p){
	int i,j;
	printf("\n");
	for(i=0;i<70;i++){
		printf("-");
	}
	printf("\n|%-25s|%-35s|%-6s|","Name","Address","Seats");
	printf("\n");
	for(i=0;i<70;i++){
		printf("-");
	}
	for(i=0;i<4;i++){
		printf("\n|%-25s|%-35s|%-6d|",p[i].name,p[i].address,p[i].seats);
	    printf("\n");
	    for(j=0;j<70;j++){
		printf("-");
	    }
	}
	printf("\n");
}

void minseats(Cinema *p){
	int i,j,minseats;
	printf("\nNhap so ghe toi thieu: ");
	scanf("%d",&minseats);
	printf("\n");
	for(i=0;i<70;i++){
		printf("-");
	}
	printf("\n|%-25s|%-35s|%-6s|","Name","Address","Seats");
	printf("\n");
	for(i=0;i<70;i++){
		printf("-");
	}
	int count=0;
	for(i=0;i<4;i++){
		if(p[i].seats>=minseats){
			count++;
		    printf("\n|%-25s|%-35s|%-6d|",p[i].name,p[i].address,p[i].seats);
	        printf("\n");
	        for(j=0;j<70;j++){
		    printf("-");	
		    }
	    }
    }
    if(count==0){
    	printf("\nKhong co rap nao phu hop");
	}
	printf("\n");
}

void savefile(Cinema *p){
	FILE *fp;
	fp = fopen("cinema.dat","wb");
	fwrite(p, sizeof(Cinema), 4, fp);
	fclose(fp);
}

void readfile(Cinema *p){
	FILE *fp;
	fp = fopen("cinema.dat","rb");
	fread(p, sizeof(Cinema), 4, fp);
	fclose(fp);
}

int main(){
	Cinema cinemaList[4];
	int choose;
	while(1){
		Menu();
		printf("\nChon chuong trinh: ");
		scanf("%d",&choose);
		switch(choose){
			case 1:
				inputcinemaList(cinemaList);
			break;
			case 2:
				sort(cinemaList);
				displaycinemaList(cinemaList);
			break;
			case 3:
				minseats(cinemaList);
			break;
			case 4:
				savefile(cinemaList);
				printf("\nDa luu thanh cong!!!\n");
			break;
			case 5:
				readfile(cinemaList);
			break;
			case 6:
				printf("\nGoodbyeeeeee\n");
				exit(0);
			break;	
			default:
				printf("\nKhong co chuong trinh nay, vui long chon lai!!!\n");
			break;	
		}
	}
}



Đặng Trần Nhật Minh [T2008A]
Đặng Trần Nhật Minh

2020-10-02 09:57:38



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

int n = 4;

typedef struct Cinema {
	
	char Name[25], Address[35];
	int Seats;
	
} cn;

void swap(cn &a, cn &b) {
	
	cn temp = a;
	a = b;
	b = temp;
	
}

void inputCinema(cn *a, int n) {
	
	for (int i = 0; i < n; i++) {
		
		printf("\nNhap Rap Thu %d:", i + 1);
					
		printf("\nNhap ten rap: ");
		fflush(stdin); fflush(stdout);
		gets(a[i].Name);
					
		printf("\nNhap dia chi rap: ");
		fflush(stdin); fflush(stdout);
		gets(a[i].Address);
					
		printf("\nNhap so luong ghe: ");
		fflush(stdin); fflush(stdout);
		scanf("%d", &a[i].Seats);
								
	}
	
}

void displayCinema(cn *a, int n) {
	
	printf("\n|Name                     |Address                            |Seats          |");
//	printf("\n|_____________________________________________________________________________|");
	
	int index_MIN;
	
	for (int i = 0; i < n - 1; i++) {
					
		index_MIN = i;
				
		for (int j = i + 1; j < n; j++)
		if (strcmp(a[index_MIN].Name, a[j].Name) > 0) index_MIN = j;
				
		swap(a[index_MIN], a[i]);
					
	}
	
	for (int i = 0; i < n; i++) {
		
//		printf("\n|Name                     |Address                            |Seats          |");
		printf("\n|%-25s|%-35s|%-15d|", a[i].Name, a[i].Address, a[i].Seats);
		
	}
	
}

void searchCinema(cn *a, int n) {
	
	printf("\nNhap so ghe toi thieu: "); 
	int s; scanf("%d", &s);
	bool check = false;
	
	printf("\n|Name                     |Address                            |Seats          |");
	
	for (int i = 0; i < n; i++)
		if (a[i].Seats >= s) printf("\n|%-25s|%-35s|%-15d|", a[i].Name, a[i].Address, a[i].Seats), check = true;
		
	if (!check) printf("\n|Khong co rap nao phu hop!                                                    |");
	
}

void outputCinema(cn *a, int n) {
	
	FILE *fp;
	
	fp = fopen("cinema.dat", "wb");
	
	fwrite(a, sizeof(cn), n, fp);
	
	fclose(fp);
	
}

void readCinema(cn *a, int n) {
	
	FILE *fp;
	
	fp = fopen("cinema.dat", "rb");
	
	fread(a, sizeof(cn), n, fp);
	
	fclose(fp);
	
}

int main() {

	cn cinemaList[n];
	
	int sel;
	
	while (true) {
		
		printf("\n==========Menu=========");
		printf("\n1. Nhap du lieu quan ly.");
		printf("\n2. Hien thi danh sach rap ra man hinh.");
		printf("\n3. Tim rap theo so ghe toi thieu.");
		printf("\n4. Luu du lieu ra tep cinema.dat.");
		printf("\n5. Doc du lieu tu tap cinema.dat.");
		printf("\n6. Thoat.");		
		printf("\n========================");
		printf("\nNhap lua chon cua ban: "); 
		fflush(stdin); fflush(stdout);
		scanf("%d", &sel);
		
		switch (sel) {
			
			case 1:
				
				inputCinema(cinemaList, n);
				
				break;
				
			case 2:
				
				displayCinema(cinemaList, n);
				
				break;
				
			case 3:
				
				searchCinema(cinemaList, n);
				
				break;
				
			case 4:
				
				outputCinema(cinemaList, n);
				
				break;
				
			case 5:
				
				readCinema(cinemaList, n);
				
				break;
				
			case 6:
				
				printf("THOAT!");
				
				exit(0);
				
			default:
				
				printf("\nNHAP SAI!");
				
				break;
			
		}
		
	}
	
	return 0;

}



Do Trung Duc [T2008A]
Do Trung Duc

2020-10-01 13:46:35



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

typedef struct Cinema_ST{
	char name[25], address[35];
	int seats;
}Cinema;

void ShowMenu();

void inputCinemalList(Cinema *p);

void sort(Cinema *p);

void displayCinemaList(Cinema *p);

void searchByMinSeats(Cinema *p);

void saveFile(Cinema *p);

void readFile(Cinema *p);

void ShowMenu();

int main(int argc, char *argv[]) {
	
	Cinema cinemaList[4];
	int choose;
	
	do{
		ShowMenu();
		scanf("%d", &choose);
		
	switch(choose){
		case 1:
			inputCinemalList(cinemaList);
		break;
		
		case 2:
			sort(cinemaList);
			displayCinemaList(cinemaList);
			
		break;

		case 3:
			searchByMinSeats(cinemaList);
		break;

		case 4:
			saveFile(cinemaList);
		break;
			
		case 5:
			readFile(cinemaList);
		break;

		case 6:
			printf("Ket thuc chuong trinh");
		break;

		default:
			printf("Nhap sai !!!");
		break;
		
	}
	}while(choose!=6);
	
	return 0;
}


void ShowMenu(){
	printf("\n1.Nhap du lieu ");
	printf( "\n2.Hien thi du lieu ");
	printf( "\n3.Tim kiem ");
	printf ( "\n4.Luu Data");
	printf("\n5.Doc Data ");
	printf("\n6.Thoat chuowng trinh");
	printf("\nChon choose: ");
}

void inputCinemalList(Cinema *p){
	
	int i;
	for(i=0;i<4;i++){
		printf("\nNhap ten rap chieu phim thu %d: ", i+1);
		fflush(stdin), fflush(stdout);
		gets(p[i].name);
		
		printf("\nNhap dia chi rap: ");
		fflush(stdin), fflush(stdout);
		gets(p[i].address);
		
		printf("\nNhap so ghe: ");
		fflush(stdin), fflush(stdout);
		scanf("%d", &p[i].seats);
	}
	
}

void sort(Cinema *p){
	int i,j;
	for(i=0;i<3;i++){
		for(j=i+1;j<4;j++){
			int cmp = strcmp (p[i].name, p[j].name);
			if(cmp>0){
				Cinema tmp = p[i];
				p[i] = p[j];
				p[j] = tmp;
				
			}
			
		}
	}
	
}

void displayCinemaList(Cinema *p){
	int j,i;
	for(i=0;i<70;i++){
		printf("-");	
	}
	printf("\n%25s|%35s|%6s", "Name", "Address", "Seats");
	printf("\n");
	
	for(i=0;i<70;i++){
		printf("-");	
	}
	
	for(i=0;i<4;i++){
		printf("\n%25s|%35s|%6d", p[i].name, p[i].address, p[i].seats);
		printf("\n");
		for(j=0;j<70;j++){
		printf("-");	
	}
	}
	}
	
	void searchByMinSeats(Cinema *p){
		int i,j, minseats;
		printf("Nhap so ghe toi thieu: ");
		scanf("%d", &minseats);
		
		for(i=0;i<70;i++){
		printf("-");	
	}
		printf("\n%25s|%35s|%6s", "Name", "Address", "Seats");
		printf("\n");
	
		for(i=0;i<70;i++){
		printf("-");	
	}
		int count = 0;
		
		for(i=0;i<4;i++){
			if(p[i].seats >= minseats){
				count++;
				printf("\n%25s|%35s|%6d", p[i].name, p[i].address, p[i].seats);
				printf("\n");
				for(j=0;j<70;j++){
				printf("-");	
	}

			}
		}
			if(count==0){
				printf("\nKhong co rap nao phu hop");
			}	
	}

	
	void saveFile(Cinema *p){
		FILE *fp;
		fp = fopen("cinema.dat", "wb");
		fwrite(p, sizeof (Cinema), 4, fp);
		fclose(fp);
	}

	void readFile(Cinema *p){
		FILE *fp;
		fp = fopen("cinema.dat", "rb");
		fread(p, sizeof (Cinema), 4, fp);
		fclose(fp);
		
	}		
	



Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó