Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // Thi Cuối Kỳ
- //
- // Created by Vũ Nguyễn Khánh on 5/22/18.
- // Copyright © 2018 Vũ Nguyễn Khánh. All rights reserved.
- //
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- typedef struct
- {
- int ClassID;
- char CourseName[30];
- char Room[10];
- int Day;
- char Slots[10];
- } university;
- university a[200];
- int n=0,k=0;
- void Input()
- {
- int m;
- do
- {
- printf("Nhap so luong lop : \n");
- scanf("%d",&m);
- } while(m<1 || m>200);
- n+=m;
- for(int i=0;i<n;i++)
- {
- printf("Nhap thong tin lop can them [%d] \n",i+1);
- printf("ClassID : "); rewind(stdin);
- scanf("%d",&a[i].ClassID);
- printf("CourseName: "); rewind(stdin);
- gets(a[i].CourseName);
- printf("Room : "); rewind(stdin);
- gets(a[i].Room);
- do
- {
- printf("Day :"); rewind(stdin);
- scanf("%d",&a[i].Day);
- } while(a[i].Day<2 && a[i].Day>7);
- do
- {
- printf("Slots (?-?) : "); rewind(stdin);
- gets(a[i].Slots);
- } while (a[i].Slots != '-');
- }
- k+=m;
- }
- void Output()
- {
- for(int i=0;i<n;i++)
- {
- printf("\n\n");
- printf("Ma lop \t Ten mon hoc \t Ten phong \t Thu \t Tiet hoc");
- printf("%d \t %s \t %s \t %d \t %s",a[i].ClassID,a[i].CourseName,a[i].Room,a[i].Day,a[i].Slots);
- printf("\n\n");
- }
- }
- void Search_Room()
- {
- char s[10];
- printf("Nhap ten phong muon tim : "); rewind(stdin);
- gets(s);
- for(int i=0;i<n;i++)
- {
- if(strcmp(a[i].Room,s) == 0)
- {
- printf("Ma lop \t Ten mon hoc \t Ten phong \t Thu \t Tiet hoc");
- printf("%d \t %s \t %s \t %d \t %s",a[i].ClassID,a[i].CourseName,a[i].Room,a[i].Day,a[i].Slots);
- printf("\n\n");
- k=0;
- }
- else
- {
- printf("Khong ton tai phong %s trong danh sach.\n",a[i].Room);
- }
- }
- }
- void Arrange()
- {
- university tmp;
- for(int i=0;i<n-1;i++)
- for(int j=i+1;j<n;j++)
- {
- if(a[i].ClassID<a[j].ClassID)
- {
- tmp=a[i];
- a[i]=a[j];
- a[j]=tmp;
- }
- }
- for(int i=0;i<n;i++)
- {
- printf("Ma lop \t Ten mon hoc \t Ten phong \t Thu \t Tiet hoc");
- printf("%d \t %s \t %s \t %d \t %s",a[i].ClassID,a[i].CourseName,a[i].Room,a[i].Day,a[i].Slots);
- printf("\n\n");
- }
- }
- void Check()
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if ((strcmp(a[i].Room, a[j].Room) == 0) && (atoi(a[i].Slots) == atoi(a[j].Slots)) && (a[i].Day = a[j].Day))
- printf("%d", a[i].ClassID);
- break;
- }
- }
- }
- void Menu()
- {
- printf("-----------------MENU-----------------");
- printf("1. Bo sung lop hoc.\n");
- printf("2. In thong tin cac lop.\n");
- printf("3. Tim kiem theo phong.\n");
- printf("4. Sap xep.\n");
- printf("5. Kiem tra trung phong.\n");
- printf("6. Thoat chuong trinh.\n");
- }
- int Select()
- {
- int q;
- printf("Lua chon cua ban: ");
- scanf("%d",&q);
- if(q>0 && q<7)
- return q;
- else return Select();
- }
- void Option()
- {
- while(1)
- {
- int Choose=Select();
- switch(Choose)
- {
- case 1: Input(); break;
- case 2: Output(); break;
- case 3: Search_Room(); break;
- case 4: Arrange(); break;
- case 5: Check(); break;
- case 6: printf("Ket thuc.\n");e xit(1); break;
- default: break;
- }
- }
- }
- int main()
- {
- Menu();
- Select();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement