C/C++课程设计 ——货物管理系统
生活随笔
收集整理的這篇文章主要介紹了
C/C++课程设计 ——货物管理系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1) 貨物管理系統1.0
- 2) 貨物管理系統2.0
1) 貨物管理系統1.0
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<windows.h> typedef struct goods//結構體 {int num;int price;char name[100];int amount;int kg;struct goods *next;} goods;struct goods *creathead()//建立 {struct goods *head;head=(struct goods *)malloc(sizeof(struct goods ));if(head==NULL){exit(0);}else{head->next==NULL;return head;} } void g()//定義函數 { system("color 6F"); 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"); } void fun()//定義函數 { system("color 3F"); printf("************************************\n"); printf("************************************\n"); printf("*******歡迎使用貨物管理系統*********\n"); printf("************************************\n"); printf("************************************\n"); printf("************************************\n"); printf("********請按Enter鍵進入下一步*******\n"); getchar(); system("cls"); } void show(goods*head) //輸出 {goods *p1,*p2;p1=p2=head;printf("請輸入貨物編號 貨物價格 貨物名稱 貨物數量 貨物質量 \n");while(1){p1=(struct goods*)malloc(sizeof(struct goods)); if(p1==NULL){printf("輸入貨物失敗\n");exit(-1); }else{scanf("%d %d %s %d %d",&p1->num,&p1->price,&p1->name,&p1->amount,&p1->kg);}p2->next=p1;p2=p1;if(p1->num==0){break;}}p1->next=NULL; } void addlist(goods *head)//增加 {goods *p1,*p2;p1=p2=head;while(p1->next!=NULL){p1=p1->next;}p2=(goods*)malloc(sizeof(goods));scanf("%5d %5d %5s %5d %5d",&p2->num,&p2->price,&p2->name,&p2->amount,&p2->kg);p2->next=NULL;p1->next=p2; }void change(goods *head)//修改 {int a; printf("----------請輸入你要修改的編號:");scanf("%d",&a);goods *p;p=head->next;while(1){if(p->num==a){break; }p=p->next;} scanf("%d %d %s %d %d", &p->num,&p->price,&p->name,&p->amount,&p->kg);}void inquiry(goods *head)//查詢 {int b; goods *p;p=head;printf("請輸入你要查詢的貨物編號:\n"); scanf("%d",&b);while(p->num!=b){p=p->next;}printf("----------查詢結果----------");printf("貨物編號%d,貨物價格%d,貨物名稱%s,貨物數量%d,貨物重量%d:\n",p->num,p->price,p->name,p->amount,p->kg); } void deletelist(goods *head)//刪除 {int c;printf("請輸入你要刪除的貨物編號:\n");scanf("%d",&c);goods*p1=head;goods*p2=head;while(p1!=NULL){if(p1->num==c){p1->next=p2->next;free(p1);printf("刪除成功!\n");break; }p2=p2->next;p1=p2->next;} } void print(goods *head)//輸出 {goods *p;p=head->next;while(p->next!=NULL){printf("貨物信息:貨物編號%5d,貨物價格%5d,貨物名稱%5s,貨物數量%5d,貨物重量%5d\n",p->num,p->price,p->name,p->amount,p->kg); p=p->next; } } void destroy(goods*head)//銷毀 {goods *p;p=head;while(p->next!=NULL){p=p->next;free(p);}printf("該貨物信息已經被銷毀\n"); } void QQ()//登錄 { char name[20],sercret[20];printf("請輸入你的用戶名\n");scanf("%s",&name);printf("請輸入你的密碼\n"); scanf("%s",&sercret); if(strcmp("1219913130",name)==0&&strcmp("666666",sercret)==0){printf("登錄成功"); }else{printf("登錄失敗");exit(-1); }} void sort(goods*head)//排序 {goods *p1,*p2,*p3;int x,i;int t;char name_[20];int num,amount,kg;for(x=0,p3=head->next;p3!=NULL;p3=p3->next){x++; } for(i=0;i<x;i++){for(p1=head->next,p2=head->next->next;p1!=NULL,p2!=NULL;p1=p1->next,p2=p2->next){if(p1->price<p2->price){t =p2->price;p2->price=p1->price;p1->price=t;strcpy(name_,p2->name);strcpy(p2->name,p1->name);strcpy(p1->name ,name_);num=p2->num;p2->num=p1->num;p1->num=num;amount=p2->amount;p2->amount=p1->amount;p1->amount=amount; kg=p2->kg;p2->kg=p1->kg;p1->kg=kg; }} }goods *p;p=head->next;while(p->next!=NULL){printf("貨物信息:貨物編號%5d,貨物價格%5d,貨物名稱%5s,貨物數量%5d,貨物重量%5d\n",p->num,p->price,p->name,p->amount,p->kg); p=p->next; } }int main() //調用 {struct goods*head;head=creathead();QQ();//system("date/t");//system("time/t");while(1){system("date/t");system("time/t");//fun();g();int n;printf("請輸入編號1-9\n");scanf("%d",&n);switch(n){case 1:{system("CLS\n");show(head);break; }case 2:{system("CLS\n");addlist(head);break;}case 3:{system("CLS\n");deletelist(head);break;}case 4:{system("CLS\n"); inquiry(head);break; }case 5:{system("CLS\n");change(head);break;}case 6:{system("CLS\n");print(head);break;}case 7:{system("CLS\n");destroy(head);break;}case 8:{system("CLS\n");sort(head);break;}case 9:{system("CLS\n");system("color 6F");printf("=============================================================\n");printf("|| ||\n");printf("|| ||\n");printf("|| 謝謝使用 ||\n");printf("|| ||\n");printf("|| ||\n");printf("=============================================================\n");exit(0);default:printf("輸入有誤!"); } } }}2) 貨物管理系統2.0
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<windows.h> typedef struct storage{int num;int price;char name[20];int quantity;struct storage *next; }storage; void add(storage *head){//輸入貨物信息printf("請選擇:1 接著上次輸入 2 新建輸入\n");int chose;scanf("%d",&chose);switch(chose){case 1:printf("請輸入文件名:\n");char filename1[20];scanf("%s",filename1);printf("結束輸入請輸入0 0 0 0\n");printf("貨物編號 貨物價格 貨物名稱 貨物數量\n");FILE *fp;fp=fopen(filename1,"a+");if(fp==NULL){printf("無法打開文件!");exit(0); } storage *p1,*p2;p1=p2=head;while(1){p1=(storage*)malloc(sizeof(storage));if(p1==NULL){printf("節點創建失敗!");exit(0); }else{scanf("%d %d %s %d",&p1->num,&p1->price,&p1->name,&p1->quantity);fprintf(fp,"%d %d %s %d\n",p1->num,p1->price,p1->name,p1->quantity);p2->next=p1;p2=p1;if(p1->num==0){break;}}}p2->next=NULL;fclose(fp);break;case 2:FILE *fn;printf("請輸入文件名:\n");char filename2[20];scanf("%s",filename2);fn=fopen(filename2,"w");printf("結束輸入請輸入0 0 0 0\n");printf("貨物編號 貨物價格 貨物名稱 貨物數量\n");if(fn==NULL){printf("無法打開文件!");exit(0); } storage *p3,*p4;p3=p4=head;while(1){p3=(storage*)malloc(sizeof(storage));if(p3==NULL){printf("節點創建失敗!");exit(0); }else{scanf("%d %d %s %d",&p3->num,&p3->price,&p3->name,&p3->quantity);fprintf(fn,"%d %d %s %d\n",p3->num,p3->price,p3->name,p3->quantity);p4->next=p3;p4=p3;if(p3->num==0){break;}}}p4->next=NULL;fclose(fn);break; } } void amend(storage *head){//修改貨物信息 printf("請輸入要想修改的文件名稱:\n");char filename[20];scanf("%s",filename);int i,j,l;char k[20];FILE *fp,*ftn;fp=fopen(filename,"r");ftn=fopen("tmp.txt","w");if(fp==NULL||ftn==NULL){printf("無法打開文件!");exit(0); }printf("請輸入要修改的貨物編號:");int c;scanf("%d",&c);while(!feof(fp)){fscanf(fp,"%d %d %s %d\n",&i,&j,k,&l);if(i==c){printf("%d %d %s %d\n",i,j,k,l); printf("修改為:"); scanf("%d %d %s %d",&i,&j,k,&l);fprintf(ftn,"%d %d %s %d\n",i,j,k,l);continue;}fprintf(ftn,"%d %d %s %d\n",i,j,k,l);}fclose(fp);fclose(ftn);remove(filename);rename("tmp.txt",filename); } void search(storage *head){//查詢貨物信息 printf("請輸入要想修改的文件名稱:\n");char filename[20];scanf("%s",filename);int i,j,l;char k[20];FILE *fp;fp=fopen(filename,"r");printf("請輸入要查詢的貨物編號:");int d;scanf("%d",&d); while(!feof(fp)){fscanf(fp,"%d %d %s %d\n",&i,&j,k,&l);if(i==d){printf("\n貨物編號 貨物價格 貨物名稱 貨物數量\n"); printf("%-10d %-10d %-10s %-10d\n",i,j,k,l);break;}}fclose(fp); } void deletestorage(storage *head){printf("請輸入要想修改的文件名稱:\n");char filename[20];scanf("%s",filename);storage *p3;int m,z,l;char k[20];FILE *fp;fp=fopen(filename,"r");while(!feof){fscanf(fp,"%d %d %s %d\n",&m,&z,k,&l);p3->num=m;p3->price=z;strcpy(p3->name,k);p3->quantity=l;p3=p3->next;} p3->next=NULL;printf("請輸入要刪除的貨物編號:");int b;scanf("%d",&b);storage *p1=head->next,*p2=head;while(p1!=NULL){if(p1->num==b){p2->next=p1->next;free(p1);break;}p2=p2->next;p1=p2->next;}storage *p4;p4=head->next;FILE *ftp;ftp=fopen(filename,"w");if(ftp==NULL){printf("無法打開文件!");exit(0); } while(p3->next!=NULL){fprintf(ftp,"%d %d %s %d\n",p4->num,p4->price,p4->name,p4->quantity);p4=p4->next;}fclose(ftp); } void paixu(storage *head){printf("請輸入要想修改的文件名稱:\n");char filename[20];scanf("%s",filename);storage *p3;int m,z,l;char k[20];FILE *fp;fp=fopen(filename,"r");while(!feof){fscanf(fp,"%d %d %s %d\n",&m,&z,k,&l);p3->num=m;p3->price=z;strcpy(p3->name,k);p3->quantity=l;p3=p3->next;} p3->next=NULL;fclose(fp);int n=0,i,j,t1,t2,t3;char t4[20];storage *p1,*p;p=head->next;while(p!=NULL){n++;p=p->next;}for(i=0;i<n-2;i++){p1=head->next;for(j=0;j<n-i-2;j++){if(p1->price>p1->next->price){t1=p1->num;p1->num=p1->next->num;p1->next->num=t1;t2=p1->price;p1->price=p1->next->price;p1->next->price=t2;t3=p1->quantity;p1->quantity=p1->next->quantity;p1->next->quantity=t3;strcpy(t4,p1->name);strcpy(p1->name,p1->next->name);strcpy(p1->next->name,t4);}p1=p1->next;}} p=head->next;printf("貨物編號 貨物價格 貨物名稱 貨物質量\n"); while(p->num!=0){printf("%-10d %-10d %-10s %-10d\n",p->num,p->price,p->name,p->quantity);p=p->next;} } void print(storage *head){//顯示全部貨物信息 printf("請輸入要想修改的文件名稱:\n");char filename[20];scanf("%s",filename);int i,j,l;char k[20];FILE *fp;fp=fopen(filename,"r");if(fp==NULL){printf("無法打開文件!");exit(0); } printf("貨物編號 貨物價格 貨物名稱 貨物數量\n");while(fscanf(fp,"%d %d %s %d\n",&i,&j,k,&l)!=EOF){if(i==0)continue;printf("%-10d %-10d %-10s %-10d\n",i,j,k,l);}fclose(fp); } int main(){system("color 2F");storage *head;head=(storage*)malloc(sizeof(storage));if(head==NULL){printf("頭結點創建失敗!");exit(0); } head->next=NULL;char usename[10],password[7];while(1){system("date/t");system("time/t");printf("=================================================================\n");printf("\\\\ 歡迎使用倉庫貨物管理系統 //\n");printf("=================================================================\n");printf("|| ||\n");printf("|| ||\n");printf("|| 請輸入賬號密碼 ||\n");printf("|| ||\n");printf("|| ||\n");printf("=================================================================\n");printf("賬號:");scanf("%s",usename);printf("密碼:");scanf("%s",password); if(strcmp("666", usename) == 0&&strcmp("666",password)==0){system("CLS");while(1){int a;system("date/t");system("time/t");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("|| 【0】退出系統 ||\n");printf("=================================================================\n");printf("請選擇程序種類:"); scanf("%d",&a);switch(a){case 1:system("CLS");add(head);break;case 2:system("CLS");amend(head);break;case 3:system("CLS");search(head);break;case 4:system("CLS");print(head);break;case 5:system("CLS");deletestorage(head);break;case 6:system("CLS");paixu(head);break;case 0:system("CLS");printf("=============================================================\n");printf("|| ||\n");printf("|| ||\n");printf("|| 謝謝使用 ||\n");printf("|| ||\n");printf("|| ||\n");printf("=============================================================\n");exit(0);default:printf("輸入有誤!");}} } else{printf("=============================================================\n");printf("|| ||\n");printf("|| ||\n");printf("|| 賬號或密碼輸入錯誤! ||\n");printf("|| 退出系統請輸入 0 ||\n");printf("|| 重新輸入請輸入 1 ||\n");printf("|| ||\n");printf("|| ||\n");printf("=============================================================\n");int a;scanf("%d",&a);system("CLS");if(a==0){printf("=============================================================\n");printf("|| ||\n");printf("|| ||\n");printf("|| 謝謝使用 ||\n");printf("|| ||\n");printf("|| ||\n");printf("=============================================================\n");exit(0);} } }return 0; }總結
以上是生活随笔為你收集整理的C/C++课程设计 ——货物管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 信用卡如何激活
- 下一篇: 《团队激励与沟通》第 1 讲——激励理论