




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、建議使用VS打開運行#pragma once#include<stdio.h>typedef struct information /商品信息 char number20; /編號 char sname20; /名稱 float price; /價格 int count; /數(shù)量 char dath20; /生產(chǎn)日期 struct information *next;inf;void menu(inf *head); /顯示主菜單 inf *create(); /創(chuàng)建鏈表 void Input(inf *head); /輸入商品信息 void tianjia(inf *head);
2、 /添加商品信息 void output(inf *head); /輸出商品信息 void chaxun(inf *head); /查詢商品信息void chaxun_number(inf *head); /按編號查詢 void chaxun_sname(inf *head); /按名稱查詢 void xiugai(inf *head); /修改商品信息 void shanchu(inf *head); /刪除商品信息 void write_file(inf *head); /保存商品信息到文件 void paixu(inf *head);inf *Read_file(); /讀取文件內(nèi)商品信
3、息 void freeh(inf *head); /退出程序 #define _CRT_SECURE_NO_WARNINGS#include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h> #include <windows.h>#include <mmsystem.h>#pragma comment(lib, "WINMM.lib")#include"標頭.h"void menu(inf *
4、head) /顯示菜單 PlaySound(TEXT("sounds背景.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP); system("color 3B"); printf("tt*n"); printf("tttt歡迎進入商品庫存管理系統(tǒng)n"); printf("tt*n"); printf("n"); printf("tt|=|n"); printf("tt|_基本信息_|n"
5、); printf("tt| 1.商品信息錄入 | 2.添加商品信息 |n"); printf("tt| 3.查找商品信息 | 4.修改商品信息 |n"); printf("tt| 5.刪除商品信息 | 6.保存文件信息 |n"); printf("tt| 7.讀取文件信息 | 8.顯示商品信息 |n"); printf("tt| 9.按價格從高到低進行排序 |n"); printf("tt|_0.釋放鏈表。退出_|"); printf("nttt請輸入你的選項(0
6、-8):n"); printf("n"); printf("t請輸入你的選擇: n");inf *create() /創(chuàng)建鏈表 inf *p; p = (inf *)malloc(sizeof(struct information); if (p = NULL) printf("鏈表創(chuàng)建失敗.n"); exit(0); p->next = NULL; return (p);void Input(inf *head) /錄入貨物信息 inf *p; int i,n; printf("請輸入:你想錄入多少個商品信
7、息: n "); scanf("%d", &n); for (i = 1; i <= n; i+) p = (inf *)malloc(sizeof(struct information); if (p = NULL) printf("結(jié)點創(chuàng)建失敗.n"); exit(0); printf("請輸入商品:編號,名稱,價格,數(shù)量:生產(chǎn)日期n"); printf("編號:"); scanf("%s", p->number); printf("名稱:"
8、); scanf("%s", p->sname); printf("價格:"); scanf("%f", &p->price); printf("數(shù)量:"); scanf("%d", &p->count); printf("生產(chǎn)日期:"); scanf("%s",p->dath); p->next = NULL; while (head->next != NULL) head = head->nex
9、t; head->next = p; void tianjia( inf *head) /添加貨物信息 inf *p; int i,n; printf("請輸入:你想添加多少個商品信息: n"); scanf("%d", &n); for (i = 1; i <= n; i+) p = (inf *)malloc(sizeof(struct information); if (p = NULL) printf("鏈表結(jié)點創(chuàng)建失敗。n"); exit(0); printf("請輸入商品:編號,名稱,價格,數(shù)
10、量:n"); printf("編號:"); scanf("%s", p->number); printf("名稱:"); scanf("%s", p->sname); printf("價格:"); scanf("%f", &p->price); printf("數(shù)量:"); scanf("%d", &p->count); printf("生產(chǎn)日期:"); scanf(
11、"%s",p->dath); p->next = NULL; while (head->next != NULL) head = head->next; head->next = p; void output(inf *head) /輸出貨物信息 int n = 0; inf *p; p = head->next; if (p = NULL) printf("鏈表為空,請先輸入信息!n"); return; while (p != NULL) n+; printf("商品信息:編號: %s,名稱:%s,價格:
12、%.2f 數(shù)量:%d 生產(chǎn)日期:%sn", p->number, p->sname, p->price, p->count,p->dath); p = p->next; printf("商品總數(shù)為:%d n", n);void chaxun(inf *head) /查詢貨物信息 函數(shù) int a; printf("tt查詢信息n"); while (1) printf("t 1.按編號查詢n"); printf("t 2.按名稱查詢n"); printf("請
13、輸入你的選擇:n"); scanf("%d", &a); if (a = 1) chaxun_number(head);/調(diào)用按編號查詢的函數(shù) break; if (a = 2) chaxun_sname(head);/調(diào)用按名稱查詢的函數(shù) break; if (a != 1 && a != 2) printf("輸入錯誤!n"); break; getchar(); void chaxun_number(inf *head) /按編號查詢 char num20; inf *p; int i = -1; p = head
14、; printf("請輸入你要查詢的商品的編號:"); scanf("%s", num); while (p->next != NULL) p = p->next; if (strcmp(p->number, num) = 0) i = 1; printf("已找到該商品信息n"); printf("貨物信息:編號:%s,名稱:%s,價格:%.2f.數(shù)量:%d,生產(chǎn)日期:%sn", p->number, p->sname, p->price, p->count,p->
15、dath); if (i<0) printf("沒有此商品信息!n");void chaxun_sname(inf *head) /按名稱查詢 char a20; int i = -1; inf *p; p = head; printf(" 請輸入要查找商品的名稱 :n"); scanf("%s", a); while (p->next != NULL) p = p->next; if (strcmp(p->sname, a) = 0) i = 1; printf("已找到該商品信息n");
16、 printf("商品信息:編號:%s,名稱:%s,價格:%.2f.數(shù)量:%d,生產(chǎn)日期n", p->number, p->sname, p->price, p->count,p->dath); if (i<0) printf("沒有此商品!n");void xiugai(inf *head) /修改貨物信息 printf("t*n"); printf("t 請輸入修改的方式:n"); printf("t1.單個信息全部修改。n"); printf("
17、;t2.單個信息逐個修改。n"); printf("t*n"); int a; printf("請輸入選項:n"); scanf("%d", &a); if (a = 1) char no20; int i = -1; inf *p; p = head; printf("請輸入要修改商品的編號:n"); scanf("%s", no); while (p->next != NULL) p = p->next; if (strcmp(p->number, no)
18、 = 0) i = 1; printf("已找到該商品n請輸入新的的編號,名稱,價格,數(shù)量:生產(chǎn)日期:n"); printf("編號:"); scanf("%s", p->number); printf("名稱:"); scanf("%s", p->sname); printf("價格:"); scanf("%f", &p->price); printf("數(shù)量:"); scanf("%d"
19、, &p->count); printf("生產(chǎn)日期:"); scanf("%s",p->dath); if (i<0) printf("沒有此商品信息!n"); if (a = 2) inf *p = NULL; int b; char number220; char name2100; float price2; int count2; p = head->next; if (p = NULL) printf("沒有商品信息,請先保存商品信息!n"); printf("
20、tt 請輸入要修改的內(nèi)容n"); printf("tt 1.修改編號 2.修改名稱n"); printf("tt 3.修改價格 4.修改數(shù)量n"); printf("tt 5.修改生產(chǎn)日期n"); printf("請選擇 n"); scanf("%d", &b); switch (b) case 1: printf("請輸入原商品編號:n"); scanf("%s", &number2); while (p != NULL) if
21、 (strcmp(p->number, number2) = 0) printf("已找到該商品n請輸入新的編號:n"); scanf("%s", &p->number); p = p->next; printf("該商品信息已修改成功。n"); break; case 2: printf("請輸入原名稱:n"); scanf("%s", &name2); while (p != NULL) if (strcmp(p->sname, name2) = 0)
22、 printf("請輸入新的名稱:n"); scanf("%s", &p->sname); break; p = p->next; printf("該商品信息已修改成功。n"); break; case 3: printf("請輸入該商品編號:"); scanf("%s",&number2); printf("請輸入原價格:n"); scanf("%f", &price2); while (p != NULL) if (
23、strcmp(p->number, number2) = 0&&price2=p->price) printf("請輸入新的價格:n"); scanf("%f", &p->price); break; p = p->next; printf("該商品信息已修改成功。n"); break; case 4: printf("請輸入該商品編號:"); scanf("%s",&number2); printf("請輸入被修改的數(shù)量:n&q
24、uot;); scanf("%d", &count2); while (p != NULL) if (count2 = p->count&&strcmp(p->number, number2) = 0) printf("請輸入新的數(shù)量:n"); scanf("%d", &p->count); break; p = p->next; printf("該商品信息已修改成功。n"); break; default: printf("修改內(nèi)容有錯誤!n&qu
25、ot;); void shanchu(inf *head) /刪除貨物信息 int a; printf("tt 1.按編號刪除 2.按名稱刪除n"); printf("tt請輸入選項:n"); scanf("%d", &a); switch (a) case 1: char number20; int i = -1; inf *p, *h; p = head; printf("請輸入你要刪除的商品的編號:n"); scanf("%s", number); while (p->nex
26、t != NULL) if (strcmp(number, p->next->number) = 0) i = 1; h = p->next; p->next = p->next->next; free(h); printf("已刪除該商品信息。n"); break; p = p->next; if (i<0) printf("沒有此商品信息!n"); break; case 2: char name20; int i = -1; inf *p, *h; p = head; printf("請輸入
27、你要刪除的商品的名稱:n"); scanf("%s", name); while (p->next != NULL) if (strcmp(name, p->next->sname) = 0) i = 1; h = p->next; p->next = p->next->next; free(h); printf("已刪除該商品信息。n"); break; p = p->next; if (i<0) printf("沒有此商品信息!n"); break; void wri
28、te_file(inf *head) /保存貨物信息到文件 inf *p; FILE *fp; p = head; if (fp = fopen("商品信息.txt", "wb") = NULL) printf("Do not have this filen"); exit(0); while (p->next != NULL) p = p->next; fwrite(p, sizeof(struct information), 1, fp); fclose(fp);inf *Read_file() /讀取文件內(nèi)的貨物信息
29、 inf *p, *d, *head; FILE *fp; head = (inf *)malloc(sizeof(struct information); p = (inf *)malloc(sizeof(struct information); if (fp = fopen("商品信息.txt", "rb") = NULL) printf("不能打開文件!n"); exit(0); if (fread(head, sizeof(struct information), 1, fp) d = head; while (fread(p
30、, sizeof(struct information), 1, fp) d->next = p; d = p; p = (inf *)malloc(sizeof(struct information); d ->next = NULL; fclose(fp); return (head);void freeh(inf *head) /釋放空間 退出程序 inf *p; p = (inf *)malloc(sizeof(struct information); p = head; while (head->next != NULL) head = head->next; free(p); p = head; free(p);void paixu(inf *head) inf *p=head,*q=NULL,*t=NULL,*subhead=NULL; int i, j, count = 0; while (p->next != NULL) count+; p = p->next; for (i = 0; i < count - 1
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 房地產(chǎn)行業(yè)工作計劃制定
- 游戲活動對幼兒發(fā)展的影響計劃
- 品牌重塑中的領導力作用計劃
- 2025年紡粘法非織造布生產(chǎn)線項目建議書
- 分析企業(yè)強弱勢的管理方式計劃
- 智研咨詢發(fā)布-2025年中國玄武巖纖維行業(yè)現(xiàn)狀、發(fā)展環(huán)境及投資前景分析報告
- 2025年高精度帶材軋機項目合作計劃書
- 古氣候變遷在沉積記錄中的體現(xiàn)方式
- 2025年數(shù)控超精密磨床項目建議書
- 地球的故事之環(huán)境保護讀后感
- 08SS523建筑小區(qū)塑料排水檢查井
- 江蘇省南京市2021年中考英語試卷【及答案】
- 煉鋼廠增效降本攻關方案
- 燃氣管道及設施的安全間距優(yōu)質(zhì)資料
- LY/T 2709-2016木蠟油
- GB/T 22919.1-2008水產(chǎn)配合飼料第1部分:斑節(jié)對蝦配合飼料
- GB/T 14800-2010土工合成材料靜態(tài)頂破試驗(CBR法)
- 2023年西交大少年班試題
- 第6課《老山界》課件【備課精研+高效課堂】 部編版語文七年級下冊
- 第八節(jié) 元代散曲
- 前置胎盤詳解課件
評論
0/150
提交評論