1081603 Thành viên mới
Tổng số bài gửi : 1 Join date : 06/04/2011
| Tiêu đề: nluan1: xếp lịch thi cho học sinh phổ thông Wed Apr 06, 2011 1:58 am | |
| Cách sử dụng đồ họa trong devC đã có bạn hướng dẫn rồi mình chỉ xin phép đưa code lên thôi Code còn nhiều thiết sót mong mọi người chỉ giáo - Sử dụng phương pháp đồ thị thể hiện việc bố trí lịch thi cho học sinh phổ thông trung học với bảy môn thi trong bảy ngày. - Yêu cầu phải bố trí lịch thi sao cho hai môn thi của cùng một giáo viên không được rơi vào hai ngày liên tiếp nhau. - Biêt rằng không có giáo viên nào có nhiều hơn bốn môn thi. - Code:
-
#include<iostream.h> #include<string.h> #include<conio.h> #include<stdio.h> #include<graphics.h> #include<math.h> #include<stdlib.h> struct lichthi { char hoten[50]; char mon[20]; int mau; int thutu; }; lichthi d[10]; void nhap() {lichthi lt[10]; int t=0; for(int i=0; i<7; i++) { printf("nhap mon hoc thu %d: ", i+1); gets(d[i].mon); printf("nhap ten giao vien: ");gets(d[i].hoten); d[i].thutu=t; t++; } for(int i=0; i<7; i++) {lt[i]=d[i]; //printf("\t %s",d[i].mon); } }
void sapxep() {lichthi lt[10]; lichthi tam; for(int i=0;i<7;i++) { for(int j=i+1;j<7;j++) { if (strcmp(lt[i].hoten,lt[j].hoten)==0) { tam=lt[i+1]; lt[i+1]=lt[j]; lt[j]=tam; i++; } } } lt[0].mau=1; for(int i=0; i<6; i++) { if(strcmp(lt[i].hoten,lt[i+1].hoten)==0) lt[i+1].mau=lt[i].mau; else lt[i+1].mau=lt[i].mau+1; } }
void lich() { lichthi lt[10];lichthi b[10]; int max,min,lon,nho,t,c=7; for(int i=0;i<7;i+=2) { max=-1;min=4;lon=-1;nho=-1; //-----------tim so mon nhieu nhat----------- for(int j=0;j<c;j++) { t=0; for(int d=0;d<c;d++) if(strcmp(lt[j].hoten,lt[d].hoten)==0) t++; if(max<t&&(i==0||strcmp(lt[j].hoten,b[i-1].hoten)!=0))
{ max=t; lon=j; } } //-----------chen phan tu lon nhat vao mang b---------- b[i]=lt[lon];
for(int j=lon;j<c;j++) lt[j]=lt[j+1]; c--; //-----------tim giao vien day it mon nhat---------- for(int j=c-1;j>=0;j--) { t=0; for(int d=c-1;d>=0;d--) if(strcmp(lt[j].hoten,lt[d].hoten)==0) t++; if((min>t)&&strcmp(lt[j].hoten,b[i].hoten)!=0) { min=t; nho=j; } } //-----------chen phan tu nho nhat vao mang b------------ b[i+1]=lt[nho]; for(int j=nho;j<c;j++) lt[j]=lt[j+1]; c--; } } void hien() {lichthi lt[10]; lichthi b[10]; /*printf("ket qua sau khi sap xep cac mon cung giao vien gan nhau"); for(int i=0; i<7; i++) { printf("\n mon %s giao vien %s, mau %d", lt[i].mon, lt[i].hoten, lt[i].mau);
}*/ printf("lich thi da duoc xep: \n"); for(int i=0; i<7; i++) { printf("\n Ngay thu %d: Mon %s, Giao vien %s, mau %d", i+1, b[i].mon, b[i].hoten, b[i].mau); } }
void DDA(int x1,int y1,int x2,int y2,int color) //giai thuat ve duong thang { int dx,dy,step; float x_inc,y_inc,x,y; dx=x2-x1; dy=y2-y1; if (abs(dx)>abs(dy)) step=abs(dx); else step=abs(dy); x_inc=(float)dx/step; y_inc=(float)dy/step; x=x1; y=y1; putpixel(int(x),int(y),color); for (int k=1;k<=step;k++){ x=x+x_inc; y=y+y_inc; putpixel((int)x,(int)y,color); delay(10); } } void vedothi() { //char* t[7]; lichthi lt[10]; lichthi b[10]; int mh=DETECT,mode=0; initgraph(&mh,&mode,"C:\\Dev-Cpp"); int x[7],y[7]; int x_center=300,y_center=250,rad=180; int i,j; char* a[]={"ngay 1","ngay 2","ngay 3","ngay 4","ngay 5","ngay 6","ngay 7"}; for (int i=0; i<7; i++) { setfillstyle (SOLID_FILL, b[i].mau); y[i]=y_center+ (int)(rad*sin((360/7)*i*3.14159/180)); x[i]=x_center+ (int)(rad*cos((360/7)*i*3.14159/180)); fillellipse(x[i],y[i],40,30); delay(150); outtextxy(x[i],y[i],d[i].mon); outtextxy(x[b[i].thutu]-20,y[b[i].thutu]-20,a[i]); }
for(i=0;i<7;i++) {if(i<6) j=i+1; DDA(x[b[i].thutu],y[b[i].thutu],x[b[j].thutu],y[b[j].thutu],14); } getch(); }
int main() {start:; int c; printf("\n\t******************************* NIEN LUAN 1 *********************"); printf("\n\n\t*** DE TAI : SAP XEP LICH THI CUA HOC SINH PHO THONG\n"); printf("\n\t*** GVHD: NGUYEN THI THU AN"); printf("\n\t** SV Thuc Hien: THAI VINH TAN"); printf("\n\t** MSSV : 1081603"); printf("\n\t** MA LOP : DI0897A2"); printf("\n\n (^_^) !!... \n\n"); printf("\n\n nhan 0 de thoat, nhan 1 de vao chuong trinh "); scanf("%d",&c); switch(c) { { case 0: system("cls"); goto loop;} case 1: { system("cls"); fflush(stdin); nhap(); sapxep(); lich(); hien(); vedothi(); } } getch(); loop:; return 0; } | |
|