
枚举数舞类型实险 实险:定义一个枚举类型teach,有6个枚举元素:chinese,ath,english,ym, msic.art. 已知一个表,用二推数组(5×6)实观,该数组是上面定义的【each校举类型,5行表 示星期一至星期五,6列表示每一天的课程名称。该表在定久数组的同时初始化,或从键盘 输入均可(注意赋值是枚举元素,不是字符串》。 屋期一 chinese nath chinese music english art 星期二 chinese math english chinese 9 星期三 englis动 chinese art chinese msic 星期四 chinese
枚举数据类型实验 实验: 定义一个枚举类型 teach,有 6 个枚举元素:chinese,math, english,gym, music,art。 已知一个表,用二维数组(5×6)实现,该数组是上面定义的 teach 枚举类型,5 行表 示星期一至星期五,6 列表示每一天的课程名称。该表在定义数组的同时初始化,或从键盘 输入均可(注意赋值是枚举元素,不是字符串)。 星期一 chinese math chinese music english art 星期二 math chinese math english chinese gym 星期三 english math chinese art chinese music 星期四 chinese

math english chinese math 屋期五 chinese english nusic english 空 编写一个程序,输入某教师teacher的授课课程(以上枚举元素植之一),输入查面日 期(星期数),查询该数师这一天是否上误。 学生程序 #include 年include adefine M 5 M means weekdays of one week/ adefine N 6 /N means lessons of one day*/ emun teach (chinese.math,english,gym,rusic,art]: void output(): main( enun teach plan [M][N]=chinese,math,chinese,music,english,art). aath,chinese,aath,english,chinese,gy间, (english,math,chinese,art,chinese,musicl. [chinese,math.english,chinese,math,gyn, (math,chinese,english,music,english,gym: emun teach lesson: int day.i,j.flag=0: elrser0:
math english chinese math gym 星期五 math chinese english music english 空 编写一个程序,输入某教师 teacher 的授课课程(以上枚举元素值之一),输入查询日 期(星期数),查询该教师这一天是否上课。 学生程序: #include #include #define M 5 /* M means weekdays of one week */ #define N 6 /* N means lessons of one day */ enum teach {chinese,math,english,gym,music,art}; void output(); main() { enum teach plan[M][N]={{chinese,math,chinese,music,english,art}, {math,chinese,math,english,chinese,gym}, {english,math,chinese,art,chinese,music}, {chinese,math,english,chinese,math,gym}, {math,chinese,english,music,english,gym}}; enum teach lesson; int day,i,j,flag=0; clrscr();

output O: printf("Input which day(1-5)you will to search:"); sanf(d,kday): printf("Input which lesson you will to search:\n"): printf("l--chinese 2-math 3--english\n"); rintf'4-wyn5-sie8artn门: sanf(”,最i): switch(i-1) (case 0:lessom=chinese:break: case 1:lesson=math:break: case 2:lesson"english:break; cas03:1 esson=gy■:break: case 4:lesson=music:break: case 5:lesson"art: 1 for(j=0:j1 (plan[day-1】[j]=lesson)flax+: if (flag=0) printf(No this lessom!\n"): else printf("Yes,there are %d classes of this lesson.\n",flag): getch(): 1 void output() printf("- n): printf(Mon:chinese math chinese music english art\n"); printf("Tue:math chinese mth english chinese gyw\n"): printf("Ved:english math chinese art chinese music\n") printf(Thu:chinese math english chinese math gym\n"): printf('Fri:mth chinese english music english gym\n"); printf("- -ln):
output(); printf("Input which day(1-5) you will to search:"); scanf("%d",&day); printf("Input which lesson you will to search:\n"); printf("1--chinese 2--math 3--english\n"); printf("4--gym 5--music 6--art\n"); scanf("%d",&i); switch(i-1) {case 0: lesson=chinese; break; case 1: lesson=math; break; case 2: lesson=english; break; case 3: lesson=gym; break; case 4: lesson=music; break; case 5: lesson=art; } for(j=0;j if(plan[day-1][j]==lesson) flag++; if(flag==0) printf("No this lesson!\n"); else printf("Yes, there are %d classes of this lesson.\n",flag); getch(); } void output() { printf("--------------------------------------------------------\n"); printf("Mon: chinese math chinese music english art\n"); printf("Tue: math chinese math english chinese gym\n"); printf("Wed: english math chinese art chinese music\n"); printf("Thu: chinese math english chinese math gym\n"); printf("Fri: math chinese english music english gym\n"); printf("--------------------------------------------------------\n\n");

}