大学工程实践c语言代码大于250行要求如图,货物类型,货物入库,货物出库,退出
2条回答 默认 最新
关注 有问题,可以问
#include <stdio.h> #include <string.h> #include <stdlib.h> #include<time.h> #define LEN sizeof(shop) typedef struct shoping { char barcode[20]; //编码 char name[20]; //名字 float price; //价格 int count; //数量 struct shoping *next; } shop; void welcome() { //欢迎函数 printf("\n"); printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * 欢迎使用112仓库管理系统 *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n"); printf("\n \n \n \n"); } int verify() { int num; srand(time(0)); //防止伪随机数 时间复杂度 char node[7]; //node[6]='\0'; char node_[6]; char eng[62]= {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; for(int i=0; i<6; i++) { num=rand()%60+0; node[i]=eng[num]; //验证码 } node[6]='\0'; //解决bug printf("验证码为:%s ",node); printf("请输入验证码:"); scanf("%s",node_); if(strcmp(node,node_)==0) { printf("验证成功!!!\n"); return 1; } else { printf("验证失败!!!\n"); return 2; } } int lading () { //登陆函数 int i=1,j; while(i) { welcome(); printf(" * * * * * * 登陆 * * * * * *\n"); char name[20]; char password[20]; printf(" 请输入name:"); scanf("%s",name); printf("\n"); printf(" 请输入password:"); scanf("%s",password); printf("\n"); j=verify(); if(strcmp(name,"xiaoyi")==0 && strcmp(password,"112548")==0) { if(j == 1) { printf("* * * * * * * * * * * * * 登陆成功* * * * * * * * * * * *\n \n \n \n"); i=0; return 1; } else if(j == 2) { printf("* * * * * * * * *登陆失败,请重新登陆 * * * * * * * * * * * * * *\n \n \n \n"); } } else { if(i>0 && i<3) printf("* * * * * * * * *登陆失败,请重新登陆 * * * * * * * * * * * * * *\n \n \n \n"); if((i++)==3) { printf("* * * * * * * * * 登陆失败,请重启系统后重试 * * * * * * * * * *\n \n \n \n"); i=0; return 0; } } system("pause"); system("cls"); } } void byebye() { //再见函数 printf("\n"); printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * 感谢使用112仓库管理系统 *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n"); printf("\n \n \n \n"); } void menu() { //菜单函数 printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * (1) 增加货物 *\n"); printf(" * (2) 删除货物 *\n"); printf(" * (3) 搜索货物 *\n"); printf(" * (4) 查看货物 *\n"); printf(" * (5) 改变货物 *\n"); printf(" * (6) 货物排序 *\n"); printf(" * (7) 保存货物信息 *\n"); printf(" * (8) 查看保存的货物信息 *\n"); printf(" * (9) 退出程序 *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n"); } shop *creat() { //创建链表 shop *head=(shop*)malloc(LEN); head->next=NULL; return head; } int add(shop *head,int j) { //增加函数 int n; printf("输入增加货物的数量: \n"); printf("输入0可返回菜单\n"); scanf("%d",&n); if(n == 0) { system("cls"); menu(); } while(n--) { if(n<0) { printf("您输入的数据有误,请重新输入\n"); break; } shop *p=head; shop *q=(shop*)malloc(LEN); tp: printf("请输入货物编码 货物名称 货物价格 货物数量\n"); scanf("%s %s %f %d",q->barcode,q->name,&q->price,&q->count); int k=1; // 查看是否重复 for(int i=1; i<=j; i++) { p=p->next; if(strcmp(p->barcode,q->barcode)==0 && strcmp(p->name,q->name)==0) { if(p->price==q->price) { printf("货物添加成功!!!\n"); //利用p遍历以前链表 p->count+=q->count; free(q); k=2; break; } else { printf("货物添加失败\n"); free(q); k=3; n++; break; } } else if(strcmp(p->barcode,q->barcode)==0 || strcmp(p->name,q->name)==0) { printf("货物添加失败\n"); free(q); k=4; n++; break; } } if(k==1) { printf("货物添加成功\n"); p->next=q; q->next=NULL; j++; } } return j; } void print(shop *head) { //输出函数 shop *p=head->next; while(p) { printf("编码:%s\t 货物名称:%s\t 货物价格:%.2f\t货物数量:%d\t\n",p->barcode,p->name,p->price,p->count); p=p->next; } } void change(shop *head) { //改变函数 shop *p; p=head->next; printf("请输入要改变货物的编码:\n"); printf("输入0可返回菜单\n"); char barcode[20]; scanf("%s",barcode); if(barcode == 0) { system("cls"); menu(); } int i=1; while(p) { if(strcmp(p->barcode,barcode)==0) { printf("请输入改变后货物的名称 价格 数量\n"); scanf("%s %f %d",p->name,&(p->price),&p->count); i=1; break; } else { i=0; } p=p->next; } if(i==0) { printf("该货物不存在! ! !\n"); } } void search(shop *head) { //搜索函数 shop *p=head->next; printf("请输入要搜索的货物的名称:\n"); printf("输入0可返回菜单\n"); char name [20]; scanf("%s",name); if(name == 0) { system("cls"); menu(); } int count =0; int i=1; while(p) { if(strcmp(p->name,name)==0) { i=1; printf("货物的编码为: %s\n货物的名称为:%s\n货物价格为:%.2f\n货物数量为:%d\n",p->barcode,p->name,p->price,p->count); break; } else { i=0; } p=p->next; } if(i==0) { printf("该货物不存在! ! !\n"); } } void del(shop *head) { //删除函数 shop *p=head; shop *q=p->next; printf("请输入要删除货物的编码:\n"); printf("输入0可返回菜单\n"); char del_barcode[20]; scanf("%s",del_barcode); int i=1; while(q) { if(strcmp(q->barcode,del_barcode)==0) { p->next=q->next; free(q); printf("删除成功!\n"); i=1; break; } else { p=p->next; q=q->next; i=0; } } p=p->next; // if(i==0) { printf("未找到该货物的编码,删除失败 ! ! !\n"); } if(del_barcode == 0) { system("cls"); menu(); } } void sort(shop *head) { //排序 int temp; char temp_[20]; float _temp; shop *q = head->next; shop *p = head->next; shop *cur = head->next; shop *tail = head; //标记尾端指针 while(tail != NULL) { tail=tail->next; //tail为尾节点 } int n; printf("输入1按价格排序*******输入2按数量排序\n"); printf("输入0可返回菜单\n"); char scan[200]; while(1) { scanf("%s",scan); if(scan[0] >= '0' && scan[1] <= '9') { if(scan[1] == '\0') { break; } } printf("输入指令错误!!!从新输入!!!\n"); } switch(scan[0]) { case '1': while(p->next != tail) { if(scan == 0) { system("cls"); menu(); } cur = head->next; while(cur->next != tail) { if(cur->price>cur->next->price) { //交换 strcpy(temp_,cur->barcode); strcpy(cur->barcode,cur->next->barcode); strcpy(cur->next->barcode,temp_); //交换条形码 strcpy(temp_,cur->name); strcpy(cur->name,cur->next->name); //交换商品名称 strcpy(cur->next->name,temp_); temp = cur->count, cur->count = cur->next->count; //交换商品数量 cur->next->count = temp; _temp = cur->price; cur->price = cur->next->price; //交换商品价格 cur->next->price = _temp; } cur = cur->next; } tail = cur; } printf("排序成功!!!\n"); while(p) { printf("货物的编码为: %s\t货物的名称为:%s\t货物价格为:%.2f\t货物数量为:%d\t\n",p->barcode,p->name,p->price,p->count); p = p->next; } break; case '2': while(p->next != tail) { cur = head->next; while(cur->next != tail) { if(cur->count>cur->next->count) { //交换 strcpy(temp_,cur->barcode); strcpy(cur->barcode,cur->next->barcode); strcpy(cur->next->barcode,temp_); strcpy(temp_,cur->name); strcpy(cur->name,cur->next->name); strcpy(cur->next->name,temp_); temp = cur->count, cur->count = cur->next->count; cur->next->count = temp; _temp = cur->price; cur->price = cur->next->price; cur->next->price = _temp; } cur = cur->next; } tail = cur; } printf("排序成功!!!\n"); while(p) { printf("货物的编码为: %s\t货物的名称为:%s\t货物价格为:%.2f\t货物数量为:%d\t\n",p->barcode,p->name,p->price,p->count); p = p->next; } break; default: printf("输入的指令不正确,请重新输入!!!\n"); break; } } void save(shop *head) { //保存货物信息 shop *p=head->next; FILE *fp=fopen("货物.txt","w+"); while(p) { fprintf(fp,"编号:%s\t",p->barcode); fprintf(fp,"名称:%s\t",p->name); fprintf(fp,"价格:%.2f\t",p->price); fprintf(fp,"数量:%d\t",p->count); p=p->next; } printf("保存成功!!!\n"); fclose(fp); } void seek() { //查看保存的货物信息 char a[100]; FILE *fp=fopen("货物.txt","r"); while(fscanf(fp,"%s",a)!=EOF) { printf("%s\n",a); } fclose(fp); } int main() { system("color 0c"); //设置控制台颜色 if(lading()) { //登陆 shop *head=creat(); shop *p=head; int i=1; while(i) { system("pause"); system("cls"); menu(); printf(" 请输入数字 以实现对应的功能:\n"); scanf("%d",&i); if(i==0) { printf("输入错误,请重新输入!\n"); system("pause"); fflush(stdin); continue; } switch(i) { case 1: int k; static int j; k=add( p , j ); j=k; break; //增加货物 case 2: del(p); break; //删除货物 case 3: search(p); break; //搜索货物 case 4: print(p); break; //查看所有货物 case 5: change(p); break; //改变货物的属性 case 6: sort(p); //对保存的货物进行排序 break; case 7: save(p); //保存货物数据 break; case 8: seek(); //查看保存的货物数据 break; case 9: system("cls"); byebye(); //再见 exit(1); break; default: printf("输入的指令不正确,请重新输入!!!\n"); break; } } } system("pause"); system("cls"); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
- ¥30 eclipse开启服务后,网页无法打开
- ¥30 雷达辐射源信号参考模型
- ¥15 html+css+js如何实现这样子的效果?
- ¥15 STM32单片机自主设计
- ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
- ¥15 不小心不正规的开发公司导致不给我们y码,
- ¥15 我的代码无法在vc++中运行呀,错误很多
- ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
- ¥60 fail to initialize keyboard hotkeys through kernel.0000000000