当前位置:百问九>百科问答>C语言课程设计题目

C语言课程设计题目

2023-04-08 18:21:18 编辑:zane 浏览量:596

C语言课程设计题目

#include void add(void);int check(void);int rent(void);void useradd(void);void returnn (void);int user_number = 2;int cd_number = 1;struct cd{ char film_name[10]; char country[10]; char type[10]; int n; /*标记是否被借阅,借阅:0;存在:1*/};struct rent{ char username[10]; char film_name[10][10]; int rent_time; int return_time; int money;};struct cd CD[1000];struct rent RENT[1000];void main (void){ char choice;a: printf("please input you choice\n"); printf("A: add CD\n"); printf("B: check CD\n"); printf("C: rent CD\n"); printf("D: return CD\n"银燃森); printf("E:useradd \n"); printf("F: quit the program\n"); scanf("%c",&choice);switch(choice) { case 'A': { add(); break; } case 'B': { check(); break; } case 'C': { rent(); break; } case 'D': { returnn(); break; } case'E': { useradd(); break; } case'F': { exit(0); } }goto a; }void add(void){ FILE *a; printf("please input the cd name\n"); scanf("%s",CD[cd_number].film_name); printf("please input the cd country\n"); scanf("%s",CD[cd_number].country); printf("please input the cd type\n"); scanf("段慎%s",CD[cd_number].type); CD[cd_number].n = 1; if (0 == cd_number) { a = fopen("cd.txt","wb"); fwrite(&CD[cd_number], sizeof(struct cd), 1, a); } else { a = fopen("cd.txt","ab"); fwrite(&CD[cd_number], sizeof(struct cd), 1, a); } cd_number++; fclose(a);}int check(void){ int i; FILE *a; char cd_name[10];a = fopen("cd.txt","rb"); for(i = 0; i < cd_number; i++) { fread(&CD[i], sizeof(struct cd), 1, a); } printf("锋亩please input the cd name\n"); scanf("%s",cd_name); for(i = 0; i < cd_number; i++) { if(!(strcmp(CD[i].film_name, cd_name))) { if(1 == CD[i].n) { printf("could rent\n"); fclose(a); return 1; } else { printf("rented\n"); fclose(a); return 1; } } } fclose(a); return 0;}void useradd(void){ FILE *a; printf("please input the username\n"); scanf("%s",RENT[user_number].username);if (0 == user_number) { a = fopen("rent.txt","wb"); fwrite(&RENT[user_number], sizeof(struct rent), 1, a); } else { a = fopen("rent.txt","ab"); fwrite(&RENT[user_number], sizeof(struct rent), 1, a); printf("----- add ------"); } user_number++; fclose(a);}int rent(void){ char user_name[10]; char cd_name[10]; FILE *a; FILE *b; int i = 0; int j; int k = 0; char choice; a = fopen("rent.txt","r"); b = fopen("cd.txt","r");for (i = 0; i < cd_number; i++) { fread(&CD[i], sizeof(struct cd), 1, b); }for (i = 0; i < user_number; i++) { fread(&RENT[i], sizeof(struct rent), 1, a); }printf("please input the username\n"); scanf("%s",user_name);for (i = 0; i < user_number; i++) { if (!(strcmp(user_name, RENT[i].username))) {a: printf("please input the cd_name\n"); scanf("%s",cd_name); printf("pleae input the cd_name again\n"); scanf("%s", RENT[i].film_name[k]); k++; for (j = 0; j < cd_number; j++) { if(!(strcmp(CD[j].film_name, cd_name))) { CD[j].n = 0; break; } } } } printf("pleae input the date to rent\n"); printf("--- i : %d ---\n", i); scanf("%d",&RENT[i].rent_time); getchar(); printf("A: to rent another\n"); printf("B: quit\n"); scanf("%c",&choice); switch(choice){ case 'A': goto a; break; case 'B': return 0; } fclose(a); fclose(b);}void returnn (void){ char user_name[10]; char cd_name[10]; FILE *a; FILE *b; int i; int j; int k = 0; char choice; a = fopen("rent.txt","r"); b = fopen("cd.txt","r");for (i = 0; i < cd_number; i++) { fread(&CD[i], sizeof(struct cd), 1, b); }for (i = 0; i < user_number; i++) { fread(&RENT[i], sizeof(struct rent), 1, a); }printf("please input the username\n"); scanf("%s",user_name);for (i = 0; i < user_number; i++) { if (!(strcmp(user_name, RENT[i].username))) {a: printf("please input the cd_name to return \n"); scanf("%s",cd_name);for (j = 0; j < cd_number; j++) { if(!(strcmp(CD[j].film_name, cd_name))) { CD[j].n = 1; break; } } } } printf("pleae input the data to rturn\n"); scanf("%d",&RENT[i].return_time); if (0 == ((RENT[i].return_time - RENT[i].rent_time) % 3)) { RENT[i].money = (RENT[i].return_time - RENT[i].rent_time) / 3; } else { RENT[i].money = (RENT[i].return_time - RENT[i].rent_time) / 3 + 1; } printf("%d\n",RENT[i].money);printf("A: to rent another\n"); printf("B: quit\n"); scanf("%c",&choice); switch(choice){ case 'A': goto a; break; case 'B': return 0; } fclose(a); fclose(b);}才学编程两个月,很龊啊,包涵 请参考

版权声明:文章由 百问九 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.baiwen9.com/answer/133397.html
热门文章
二维码