c語言寫超市儲物箱,c語言編程超市自動寄存櫃

本文目錄一覽:

C語言 自動寄存機程序

while(i!=0)

{

printf(“存物請輸入1,取物請輸入2,退出請輸入0\n”);

scanf(“%d”,i);

if(i==1)

{

for(;k[y].flag==1;y++);

printf(“寄存櫃%d已經打開,您的密碼為%d\n”,y,rand());

}

}

改成:

do

{

printf(“存物請輸入1,取物請輸入2,退出請輸入0\n”);

scanf(“%d”,i);

if(i==1)

{

for(;k[y].flag==1;y++);

printf(“寄存櫃%d已經打開,您的密碼為%d\n”,y,rand());

}

}while(i!=0)

C語言編寫的超市管理系統

有一個小型超市,出售N(N=10)種商品,設計並實現一個系統,完成下列功能:

1. 保存及輸出。超市中的各種商品信息保存在指定文件中,可以把它們輸出顯示。

2. 計算並排序。計算每類商品的總價值(sum,單精度)及平均價(aver,單精度,輸出一位小數),將每類商品按平均價從大到小的順序排序列印出來。

3. 統計。統計輸出庫存量低於100的貨號及類別。統計輸出有兩種以上(含兩種)商品庫存量低於100的商品類別。

1.2總體結構

本程序主要分為八個模塊:主模塊、信息輸出修改模塊、新建信息模塊、排序模塊、計算模塊、統計模塊1、統計模塊2、列印模塊。

1) 主模塊:通過調用各分模塊實現功能;

2) 信息輸出修改模塊:輸出顯示文件中商品信息內容,添加商品信息,刪除商品信息,修改商品信息;

3) 新建商品信息模塊:建立一個新結構體,為鏈表存信息用,並且將信息保存在指定的文件中;

4) 排序模塊:把文件中順序零亂的商品信息按單價的大小從高到低進行排序,放到鏈表裡存儲;

5) 計算模塊:將所有商品的價格與庫存量進行累加求和;

6) 列印模塊:將商品信息按每類平均價格排序(從高到低)按順序列印出來;

7) 統計模塊1:統計庫存量低於100的貨名及類別;

8) 統計模塊2:統計商品庫存量有2種以上(含2種)低於100的商品類別。

附 錄(程序清單)

#include “stdio.h” /*輸入,輸出頭文件*/

#include “stdlib.h” /*申請空間頭文件*/

#include “string.h” /*對字元串加工頭文件*/

#include “conio.h” /*清屏頭文件*/

FILE *fp;

int n=0; /*定義文件指針類型*/

int i,j,a[4],m; /*定義整數類型*/

float aver[4],sum[4],g[4],h; /*定義浮點類型*/

char c[5]=”elec”; /*定義字元數組類型*/

char d[5]=”comm”; /*定義字元數組類型*/

char e[5]=”food”; /*定義字元數組類型*/

char f[5]=”offi”; /*定義字元數組類型*/

struct good /*定義結構體*/

{

int num; /*商品編號*/

char name[20]; /*商品名稱*/

char kind[40]; /*商品類型*/

float price; /*商品價格*/

char unit[10]; /*商品單位*/

int quantity; /*商品數量*/

struct good *next; /*定義結構體指針類型*/

}*head,*p1,*p2;

struct good *createlist() /*創建鏈表函數*/

{

struct good *head1,*p1,*p2; /*定義結構體指針類型*/

if((fp=fopen(“goods message.txt”,”w”))==NULL) /*判斷能否打開文件*/

{

printf(“can not open the file”);

exit(0); /*結束程序*/

}

head1=(struct good *)malloc(sizeof(struct good)); /*申請頭結點空間*/

p1=head1;

p2=head1;

printf(“*********************************************\n”);

printf(“請輸入信息:編號,名稱,類型,價格,單位,數目\n”);

printf(” (以輸入「-1」表示結束輸入)\n”);

printf(“*********************************************\n”);

printf(“____________________\n”);

scanf(“%d %s %s %f %s %d”,p1-num,p1-name,p1-kind,p1-price,p1-unit,p1-quantity); /*輸入商品信息*/

printf(“____________________\n”);

p1-next=NULL;

fprintf(fp,”%d %s %s %f %s %d “,p1-num,p1-name,p1-kind,p1-price,p1-unit,p1-quantity); /*將商品信息寫入文件*/

while(1)

{

p1=(struct good *)malloc(sizeof(struct good)); /*申請新空間*/

printf(“*********************************************\n”);

printf(“請輸入信息:編號,名稱,類型,價格,單位,數目\n”);

printf(” (以輸入「-1」表示結束輸入)\n”);

printf(“*********************************************\n”);

printf(“____________________\n”);

scanf(“%d”,p1-num);

if(p1-num==-1) /*申請空間結束條件*/

{

printf(“____________________\n\n”);

fprintf(fp,”%d”,-1);

fclose(fp);

return head1; /*返回頭指針*/

}

scanf(“%s %s %f %s %d”,p1-name,p1-kind,p1-price,p1-unit,p1-quantity); /*輸入商品信息*/

printf(“________________\n”);

fprintf(fp,”%d %s %s %f %s %d “,p1-num,p1-name,p1-kind,p1-price,p1-unit,p1-quantity); /*將商品信息寫入文件*/

p1-next=NULL;

p2-next=p1;

p2=p1;

}

}

struct good *paixu(struct good*head2) /*鏈表排序函數*/

{

struct good *p6,*p7,*r,*s; /*定義結構體指針類型*/

for(i=0;i=3;i++) /*賦初值值*/

{

a[i]=0;

sum[i]=0;

aver[i]=0;

}

p6=(struct good *)malloc(sizeof(struct good)); /*申請新空間*/

p6-next=head2;

head2=p6;

while(p6-next!=NULL) /*判斷循環結束條件*/

{

p7=p6-next;

r=p6;

while(p7-next!=NULL) /*判斷循環結束條件*/

{

if((p7-next-price)(r-next-price)) /*判斷是否調換*/

r=p7;

p7=p7-next;

}

if(p6!=r) /*判斷循環結束條件*/

{

s=r-next; /*指針調換*/

r-next=s-next;

s-next=p6-next;

p6-next=s;

}

p6=p6-next;

}

p6=head2;

head2=head2-next;

free(p6); /*釋放第一個無效空間*/

return head2;

}

void jisuan()

{

p1=head;

do

{

if(strcmp(p1-kind,c)==0) /*判斷是否為電器類型*/

{

sum[0]=sum[0]+(p1-price)*(p1-quantity); /*求電器總價*/

a[0]=a[0]+p1-quantity; /*求電器總件數*/

}

if(strcmp(p1-kind,d)==0) /*判斷是否為日用品類型*/

{

sum[1]=sum[1]+(p1-price)*(p1-quantity); /*求日用品總價*/

a[1]=a[1]+p1-quantity; /*求日用品總件數*/

}

if(strcmp(p1-kind,e)==0) /*判斷是否為辦公用品類型*/

{

sum[2]=sum[2]+(p1-price)*(p1-quantity); /*求辦公用品總價*/

a[2]=a[2]+p1-quantity; /*求辦公用品總件數*/

}

if(strcmp(p1-kind,f)==0) /*判斷是否為食品類型*/

{

sum[3]=sum[3]+(p1-price)*(p1-quantity); /*求食品總價*/

a[3]=a[3]+p1-quantity; /*求食品總件數*/

}

p1=p1-next;

}while (p1!=NULL); /*遍歷鏈表結束條件*/

for(i=0;i4;i++)

aver[i]=sum[i]/a[i]; /*求每類商品平均價*/

printf(“****************************************************\n”);

printf(“商品類型 \t 平均價\t 總庫存量\n”);

printf(“****************************************************\n”);

printf(“____________________________________________________\n”);

printf(“電器總價值:%0.1f\t平均價:%0.1f\t總庫存量:%d\n”,sum[0],aver[0],a[0]);

printf(“____________________________________________________\n”);

printf(“日用品總價值:%0.1f\t平均價:%0.1f\t總庫存量:%d\n”,sum[1],aver[1],a[1]);

printf(“____________________________________________________\n”);

printf(“食品總價值:%0.1f\t平均價:%0.1f\t總庫存量:%d\n”,sum[2],aver[2],a[2]);

printf(“____________________________________________________\n”);

printf(“辦公用品總價值:%0.1f\t平均價:%0.1f\t總庫存量:%d\n”,sum[3],aver[3],a[3]);

printf(“____________________________________________________\n”);

}

void shuchu() /*輸出商品信息函數*/

{

do

{

struct good *p3,*p4,*p5; /*定義結構體指針類型*/

int n=0,p=0,q=0,r=0;

printf(“所有商品信息:\n”);

printf(“編號,名稱,類型,價格,單位,數目\n”);

printf(“**********************************\n”);

if((fp=fopen(“goods message.txt”,”rb+”))==NULL) /*判斷能否打開文件*/

{

printf(“can not open the file”);

exit(0); /*結束程序*/

}

head=(struct good *)malloc(sizeof(struct good)); /*申請頭結點空間*/

p3=head;

fscanf(fp,”%d %s %s %f %s %d “,p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*從文件中寫到鏈表*/

while(1)

{

p4=(struct good *)malloc(sizeof(struct good)); /*申請頭結點空間*/

fscanf(fp,”%d “,p4-num);

if(p4-num!=-1) /*判斷循環結束條件*/

{

fscanf(fp,”%s %s %f %s %d “,p4-name,p4-kind,p4-price,p4-unit,p4-quantity); /*從文件中寫到鏈表*/

p4-next=NULL;

p3-next=p4;

p3=p4;

}

else

{

p3-next=NULL;

break;

}

}

fclose(fp); /*關閉文件*/

p3=head;

while(p3!=NULL)

{

printf(” %d %s %s %0.1f %s %d\n\n”,p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity);

printf(“__________________________________\n”);

p3=p3-next;

}

printf(“**********************************\n”);

printf(“//////////////////////////////////\n”);

while(n!=4)

{

p3=head;

printf(“**********************************\n”);

printf(“1 添加商品信息\n”);

printf(“2 刪除某商品信息\n”);

printf(“3 修改某商品信息\n”);

printf(“4 返回(當你完成了對某一商品的添加、刪除或者修改後請按4返回)\n”);

printf(“**********************************\n”);

scanf(“%d”,n);

if(n==1) /*添加商品信息*/

{

printf(“請輸入商品 編號 名稱 類型 價格 單位 數目\n”);

printf(“**********************************\n”);

p4=(struct good *)malloc(sizeof(struct good)); /*申請空間*/

scanf(“%d %s %s %f %s %d”,p4-num,p4-name,p4-kind,p4-price,p4-unit,p4-quantity); /*輸入商品信息*/

p4-next=NULL;

while(p3-next!=NULL) /*判斷循環結束條件*/

{

p3=p3-next;

}

p3-next=p4;

p3=head;

if((fp=fopen(“goods message.txt”,”w”))==NULL) /*判斷能否打開文件*/

{

printf(“can not open the file”);

exit(0); /*結束程序*/

}

while(p3!=NULL)

{

fprintf(fp,”%d %s %s %f %s %d “,p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity) /*將商品信息寫入文件*/

p3=p3-next;

}

fprintf(fp,”%d”,-1);

fclose(fp); /*關閉文件*/

printf(“**********************************\n”);

printf(“__________________________________\n”);

printf(“————請按4返回————-\n”);

printf(“__________________________________\n”);

printf(“**********************************\n”);

}

if(n==2) /*刪除商品*/

{

printf(“**********************************\n”);

printf(“請輸入需要刪除的商品編號\n”);

printf(“**********************************\n”);

scanf(“%d”,p);

printf(“**********\n”);

printf(“1 確認刪除\n2 取消刪除\n”);

printf(“**********\n”);

scanf(“%d”,r);

if(r==1)

{

if((head-num)==p)

{

head=head-next;

free(p3); /*釋放空間*/

}

else

{

p4=head;

p3=p4-next;

while(p3!=NULL) /*判斷循環結束條件*/

{

if((p3-num)==p)

{

p5=p3-next;

free(p3); /*釋放空間*/

p4-next=p5;

break;

}

p3=p3-next;

p4=p4-next;

}

}

if((fp=fopen(“goods message.txt”,”w”))==NULL) /*判斷能否打開文件*/

{

printf(“can not open the file”);

exit(0); /*結束程序*/

}

p3=head;

while(p3!=NULL) /*判斷循環結束條件*/

{

fprintf(fp,”%d %s %s %f %s %d “,p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*將商品信息寫入文件*/

p3=p3-next;

}

fprintf(fp,”%d”,-1);

fclose(fp); /*關閉文件*/

}

if(r==2)

continue; /*繼續循環*/

printf(“**********************************\n”);

printf(“__________________________________\n”);

printf(“————請按4返回————-\n”);

printf(“__________________________________\n”);

printf(“**********************************\n”);

}

if(n==3) /*修改某商品信息*/

{

printf(“請輸入需要修改的商品編號\n”);

scanf(“%d”,q);

while(p3!=NULL) /*判斷循環結束條件*/

{

if((p3-num)==q) /*判斷是否為所需要修改的商品*/

{

printf(“請輸入商品單價與庫存量(如果單價不變請輸入原來的單價)\n”);

scanf(“%f %d”,p3-price,p3-quantity); /*輸入商品價格與庫存量*/

}

p3=p3-next;

}

if((fp=fopen(“goods message.txt”,”w”))==NULL) /*判斷能否打開文件*/

{

printf(“can not open the file”);

exit(0); /*結束程序*/

}

p3=head;

while(p3!=NULL) /*判斷循環結束條件*/

{

fprintf(fp,”%d %s %s %f %s %d “,p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*將商品信息寫入文件*/

p3=p3-next;

}

fprintf(fp,”%d”,-1);

fclose(fp); /*關閉文件*/

printf(“**********************************\n”);

printf(“__________________________________\n”);

printf(“————請按4返回————-\n”);

printf(“__________________________________\n”);

printf(“**********************************\n”);

}

if(n==4) /*退出*/

break;

}

printf(“**********\n”);

printf(“1 繼續修改\n———\n2 返回\n”);

printf(“**********\n”);

scanf(“%d”,p);

if(p==1)

continue; /*繼續循環*/

if(p==2)

break; /*跳出循環*/

}while(n!=2);

fclose(fp); /*關閉文件*/

}

void printf0(struct good *p) /*遍歷鏈表並列印電器類商品函數*/

{

struct good *p3; /*定義結構體指針類型*/

p3=p;

while (p3!=NULL) /*判斷遍歷鏈表循環結束條件*/

{

if(strcmp(p3-kind,c)==0) /*判斷商品類型是否為電器類型*/

{

printf(“%d\t%s\t%s\t%0.1f\t%s\t%d\n”,p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*輸出電器類商品信息*/

printf(“________________________________________________\n”);

}

p3=p3-next;

}

return;

}

void printf1(struct good *p) /*遍歷鏈表並列印日用品類商品函數*/

{

struct good *p3; /*定義結構體指針類型*/

p3=p;

while (p3!=NULL) /*判斷遍歷鏈表循環結束條件*/

{

if(strcmp(p3-kind,d)==0) /*判斷商品類型是否為日用品類型*/

{

printf(“%d\t%s\t%s\t%0.1f\t%s\t%d\n”,p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*輸出日用品類商品信息*/

printf(“________________________________________________\n”);

}

p3=p3-next;

}

return;

}

void printf2(struct good *p) /*遍歷鏈表並列印辦公用品類商品函數*/

{

struct good *p3; /*定義結構體指針類型*/

p3=p;

while (p3!=NULL) /*判斷遍歷鏈表循環結束條件*/

{

if(strcmp(p3-kind,e)==0) /*判斷商品類型是否為辦公用品類型*/

{

printf(“%d\t%s\t%s\t%0.1f\t%s\t%d\n”,p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*輸出辦公用品類商品信息*/

printf(“________________________________________________\n”);

}

p3=p3-next;

}

return;

}

void printf3(struct good *p) /*遍歷鏈表並列印食品類商品函數*/

{

struct good *p3; /*定義結構體指針類型*/

p3=p;

while (p3!=NULL) /*判斷遍歷鏈表循環結束條件*/

{

if(strcmp(p3-kind,f)==0) /*判斷商品類型是否為食品類型*/

{

printf(“%d\t%s\t%s\t%0.1f\t%s\t%d\n”,p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*輸出食品類商品信息*/

printf(“________________________________________________\n”);

}

p3=p3-next;

}

return;

}

void shunxudayin()

{

for(i=0;i4;i++)

g[i]=aver[i]; /*將平均價賦給新數組*/

for(j=0;j3;j++) /*將新數組用冒泡排序法排序*/

for(i=j+1;i4;i++)

{

if(g[j]g[i])

{

h=g[j];

g[j]=g[i];

g[i]=h;

}

}

printf(“\n****************************\n”);

printf(“商品平均價格排序表(從高到低)\n”);

printf(“****************************\n”);

printf(“________________________________________________\n”);

printf(“編號\t名稱\t類別\t單價\t單位\t數量\n”);

printf(“________________________________________________\n”);

for(j=0;j4;j++)

for(i=0;i4;i++)

{

if (aver[i]==g[j]) /*判斷每類商品平均價格的先後順序*/

switch(i)

{

case 0:

printf0(head); /*調用遍歷鏈表並列印電器類商品函數*/

break;

case 1:

printf1(head); /*調用遍歷鏈表並列印日用品類商品函數*/

break;

case 2:

printf2(head);/*調用遍歷鏈表並列印辦公用品類商品函數*/

break;

case 3:

printf3(head); /*調用遍歷鏈表並列印食品類商品函數*/

break;

}

}

}

void tongji1()

{

p1=head;

printf(“\n************************\n”);

printf(“庫存量低於100的貨名及類別\n”);

printf(“************************\n”);

printf(“________________________\n”);

printf(“商品名稱\t商品類型\n”);

printf(“________________________\n”);

while(p1!=NULL) /*判斷遍歷鏈表循環結束條件*/

{

if(p1-quantity100) /*判斷庫存量是否小於100*/

{

printf(“%s\t%s\n”,p1-name,p1-kind); /*輸出商品名稱及類別*/

printf(“________________________\n”);

}

p1=p1-next;

}

}

void tongji2()

{

printf(“\n**********************************************\n”);

printf(“商品庫存量有2種以上(含2種)低於100的商品類別:\n”);

printf(“**********************************************\n”);

printf(“________\n”);

if((a[0]100)(a[0]=2)) /*判斷電器類庫存量是否為2種以上(含2種)低於100*/

{

printf(“電器\n”);

printf(“________\n”);

}

if((a[1]100)(a[1]=2)) /*判斷日用品類庫存量是否為2種以上(含2種)低於100*/

{

printf(“日用品\n”);

printf(“________\n”);

}

if((a[2]100)(a[2]=2)) /*判斷食品類庫存量是否為2種以上(含2種)低於100*/

{

printf(“食品\n”);

printf(“________\n”);

}

if((a[3]100)(a[3]=2)) /*判斷辦公用品類庫存量是否為2種以上(含2種)低於100*/

{

printf(“辦公用品\n”);

printf(“________\n”);

}

}

int main(int argc, char* argv[])

{

struct good *p1,*p2; /*定義結構體指針類型*/

while(1)

{

printf(“***********************************************\n”);

printf(“1 ———-輸出查看或者修改已存信息———–\n”);

printf(“———————————————–\n”);

printf(“2 —–重新輸入新信息(並且刪除原有信息)——\n”);

printf(“———————————————–\n”);

printf(“3 統計商品信息(如果您還沒有查看過信息請先按1)\n”);

printf(“———————————————–\n”);

printf(“4 ——————-退出———————\n”);

printf(“***********************************************\n”);

scanf(“%d”,m);

if(m==1)

shuchu(); /*調用輸出信息函數*/

if(m==2)

{

system(“cls”);

head=createlist(); /*調用建立鏈表函數*/

}

if(m==3)

{

printf(“統計結果如下\n”);

head=paixu(head); /*調用鏈表排序函數*/

jisuan(); /*調用計算函數*/

shunxudayin(); /*調用順序列印函數*/

tongji1(); /*調用統計1函數*/

tongji2(); /*調用統計2函數*/

}

if(m==4)

{

p1=head;

while(p1!=NULL) /*判斷遍歷鏈表結束條件*/

{

p2=p1-next;

free(p1); /*釋放空間*/

p1=p2;

}

break;

}

}

return 0; /*結束程序*/

}

用c語言實現超市商品管理系統,用指針實現商品的插入、刪除操作。

可以用鏈表,大致就是,你創建一個結構體,結構體里有商品的一些信息,然後關鍵的是有個該結構體的指針,這個指針是指向下一個商品的結構體地址的,依次類推,直到最後一個商品的指針是指向null的,然後開始插入商品的思路:①創建新商品的信息②先讓你要插入的結構體的指針指向要插入的那個位置後邊的地址,③然後插入位置的前面的結構體指向要插入商品④如果是插在末尾,或者開頭,你就注意是誰指向誰的問題。刪除商品思路:直接修改要刪除的商品之前的指針,繞過要刪除的商品,指向下一個不擅長的商品就ok。

struct book

{

long  book_number;   //記錄書的編號 

char book_name[N];  //儲存書的名字

double book_price;  //記錄書的價格

char book_author[N];//記錄書的作者 

char book_state[N]; //記錄書的借還狀態 

int  book_num;      //記錄書的數量 

char borrower_name[N];//記錄借書人姓名

char borrower_sex[M];//記錄借書人性別

long borrower_number;  //記錄借書人學號

struct book *book_next;//指向下一個結構體

};//以前寫的圖書管理系統作為鏈表元素的結構體,只要關注最後一個指針就好了

BOOK *DelBook(BOOK *book_head) /* 此函數負責刪除圖書 *//*思路為連續讀取文件內容,找到要刪除的文件內容的位置,寫入一份新的文件,再替換掉舊文件*/

{

long num;//記錄書籍號

int flag = 0;//控制開關

char ch;//記錄用戶的選擇

BOOK *p = book_head;

BOOK *pr = NULL;

printf(“\n功能:刪除一本圖書的所有信息\n”);

printf(“輸入你要刪除的書籍號”);

scanf(“%ld”,num);

read_book_file(book_head);//將圖書信息寫入節點

while(num != p-book_number  p-book_next != NULL)//查找節點並顯示節點內容並且記錄節點的地址

pr = p;

p = p-book_next;

}

if (book_head == NULL)/*數據不能正常獲取*/

{

exit(0);

}

else if(num = p-book_num) /*找到了對應的*/

{

PrintBook(p);

printf(“你確定要刪除么?”);

scanf(” %c”,ch);

if (ch == ‘y’||ch == ‘Y’)

{

while(!flag)

{

if (book_head == NULL)

{

printf(“鏈表為空\n”);

return book_head;

}

if (p == book_head)//如果是頭節點要刪除

{

book_head = p-book_next;

free(p);//釋放刪除節點

flag = 1;

}

else if (p-book_next == NULL)//如果是末節點

{

free(p);//釋放刪除的節點

p= pr; //改變p的指向

p-book_next == NULL;

flag = 1;

}

else

{

pr-book_next = p-book_next;//刪除中間節點

free(p);//釋放刪除的節點

flag = 1;

}

/*節點刪除結束*//*接下來將新的內容寫入文件,之前那些內容被覆蓋*/

save_book_file(book_head);//調用文件寫入函數重新寫入

//這樣直接就實現了內容的覆蓋,相當於刪除文本內容

return book_head;//最後返回頭節點

}

}

else/*未找到*/

{

fflush(stdin);

return book_head;

}

}

return book_head;

}

以前寫的令一個管理系統的一部分,將就著看吧,插入商品和這個差不多

C語言的關於超市的代碼

case ‘1’:if (number1 – n 10);這句中case後面的1不用打引號,直接跟數字就可以了,單引號一般用於其字元的ascll碼,後面的幾句case也是同一個問題

急求C語言超市儲物器管理程序

#include stdio.h

#include string.h

struct product

{

char p_num[12];

char name[12];

char spec[12];

int amount;

int price;

int s_price;

struct product *next;

};

struct product *head;

struct in_product

{

char num[12];

char p_num[12];

char name[12];

int amount;

int price;

int t_price;

struct in_product *next;

};

struct in_product *ihead;

struct out_product

{

char num[12];

char p_num[12];

char name[12];

int amount;

int price;

int t_price;

struct out_product *next;

};

struct out_product *ohead;

struct quit_product

{

char num[12];

char p_num[12];

char name[12];

int amount;

int price;

int t_price;

struct quit_product *next;

};

struct quit_product *qhead;

int init()

{

head=ihead=ohead=qhead=NULL;

printf(“0: Quit\n”);

printf(“1: Enter the information of in product\n”);

printf(“2: Enter the information of out product\n”);

printf(“3: Enter the information of quit product\n”);

printf(“4: Total the information of product\n”);

}

int menu()

{

printf(“1:insert data\n”);

printf(“2:delete data\n”);

printf(“3:modify data\n”);

printf(“4:select data\n”);

printf(“Other to quit\n”);

}

int menu2()

{

printf(“0: Quit\n”);

printf(“1: Enter the information of in product\n”);

printf(“2: Enter the information of out product\n”);

printf(“3: Enter the information of quit product\n”);

printf(“4: Total the information of product\n”);

}

int insert_product()

{

struct product * p1,* p;

p1=(struct product *)malloc(sizeof(struct product));

p=head;

if (p==NULL)/*開始沒有數據*/

{

printf(“Enter the data of product\n”);

printf(“Include the spbh,name,style,num,price,sale_price of product\n”);

scanf(“%s%s%s%d%d%d”,

p1-p_num,p1-name,p1-spec,p1-amount,p1-price,p1-s_price);

設計一個簡單的倉儲管理系統,要求具有基本的操作功能:插入(添加)、刪除、查找、修改和統計。

業務簡介

1.採購人員將採購物資清單交與財務人員,其中包含一些必要的數據.財務人員據此作帳,將數據記入,並開一張票據,交與採購人員實現物資入庫.

2.當有物資賣出時,即物資出庫,財務人員會查閱目前此類貨物的庫存情況,如此類貨物還有存量,且有不同的出價時,財務人員會根據情況,調出相應價的貨物.

由於市場行情時常波動,管理人員可能會據此對物資做出相應的調價.

3.當貨物出現問題,需要退給供貨商,並把退還的貨物名,數量,金額,記錄下來.

4.到一定時期的時候,例如月底,年終,需要將各種物資的出入庫,庫存金額整理出來,以便為管理人員提供詳盡,可靠的數據,為下一步制定目標方案提供依據.

2、1數據結構

用4個結構數組(或鏈表)來存儲下述4類信息,每類信息的每條記錄用結構類型自定義:

1.商品信息:商品編號、商品名、型號/規格、數量、進貨價、銷售價

2.入庫信息:入庫編號、商品編號、入庫商品名、入庫數量、入庫價格、總價

3.出庫信息:出庫編號、商品編號、出庫商品名、出庫數量、出庫價格、總價

4.退貨信息:退貨編號、商品編號、退還貨物名、退貨數量、退貨價格、總價

2、2 設計要求

5. 對以上每類信息建立數據結構

6. 對以上每類信息進行插入操作

7. 對以上每類信息進行刪除操作

8. 對以上每類信息進行修改操作

9. 對以上每類信息進行查找操作(查找關鍵字用下劃線標出)

10. 數據統計;

i. 統計入庫商品的總數及總價:

ii. 統計出庫商品的總數及總價:

iii. 統計倉庫中現有商品的總數及總價格:

用c語言編寫超市商品管理系統 每一步旁邊希望有小小的解釋 希望會的…

#include “stdio.h” //需要的一些頭文件

#include “stdlib.h”

#include “cstring”

#define COUNT 30 //聲明商品的種類為30中,你也可以修改

//函數聲明

void start(); //啟動界面

void input(); //商品數據信息輸入函數

void change(); //商品數據信息修改函數

void dele(); //給定指定商品名稱,刪除商品信息

void output(); //商品信息輸出

void search(); //商品信息查找

struct MarketGoods{ //存數商品信息的結構體

char goods_id[30]; //商品編號

char goods_name[30]; //商品名稱

double goods_price; //商品價格

double goods_discount;//商品折扣

int goods_amount;//商品總數目

int goods_remain;//商品剩餘數目

}goods[COUNT];

int count=0; //全局變數,用於保存實際上有多少個商品

void main() //主函數

{

while(1)

start();

}

void start() //啟動菜單

{

int chi;

printf(” 超市商品管理系統\n”);

printf(” ********************************************\n”);

printf(” 1.商品信息的錄入:\n”);

printf(” 2.商品信息的修改:\n”);

printf(” 3.刪除某個商品信息:\n”);

printf(” 4.查找商品信息:\n”);

printf(” 5.退出系統:\n”);

printf(” ********************************************\n”);

printf(” 輸入你的選擇: “);

scanf(“%d”,chi); //根據你的選擇執行相應的函數

if(chi==1) input();

else if(chi==2) change();

else if(chi==3) dele();

else if(chi==4) search();

else if(chi==5) { printf(“你已經退出超市商品管理系統!\n”); exit(0);}

else { printf(” You Enter The Choice Is Not valid ! \n”); }

}

void input() //數據錄入

{

char flag[20];

do{

printf(“請輸入你的商品信息:\n”); //錄入商品的信息

printf(“商品編號:”);

scanf(“%s”,goods[count].goods_id);

printf(“商品名字:”);

scanf(“%s”,goods[count].goods_name);

printf(“商品價格:”);

scanf(“%lf”,goods[count].goods_price);

printf(“商品折扣:”);

scanf(“%lf”,goods[count].goods_discount);

printf(“商品總數目:”);

scanf(“%d”,goods[count].goods_amount);

printf(“商品剩餘數目:”);

scanf(“%d”,goods[count].goods_remain);

count++; //存數的商品數加一

printf(“是否繼續輸入數據 y是 n否 : “); //是否還想繼續輸入數據

scanf(“%s”,flag);

}while(strcmp(flag,”y”)==0||strcmp(flag,”Y”)==0);

output(); //調用顯示商品數據

}

void change() //數據修改

{

char ch[20],a[20];

int i;

printf(“\nyou sure want change goodsInfor y/n): “); //根據商品的id來修改數據

scanf(“%s”,ch);

if(strcmp(ch,”y”)==0||strcmp(ch,”Y”)==0)

{ printf(“\nenter you want change goods_id:”);

scanf(“%s”,a);

for(i=0;icount;i++)

{

if(strcmp(goods[i].goods_id,a)==0)

{ printf(“\nyou sure want change goods name(y/n): “);

scanf(“%s”,ch);

if(strcmp(ch,”y”)==0||strcmp(ch,”Y”)==0) { printf(“\nname:”); scanf(“%s”,goods[i].goods_name);}

printf(“\nyou sure want change goods price(y/n): “);

scanf(“%s”,ch);

if(strcmp(ch,”y”)==0||strcmp(ch,”Y”)==0) { printf(“\nprice”); scanf(“%lf”,goods[i].goods_price);}

printf(“\nyou sure want goods discount(y/n): “);

scanf(“%s”,ch);

if(strcmp(ch,”y”)==0||strcmp(ch,”Y”)==0) { printf(“\ndiscount”); scanf(“%lf”,goods[i].goods_discount);}

printf(“\nyou sure want goods amount(y/n): “);

scanf(“%s”,ch);

if(strcmp(ch,”y”)==0||strcmp(ch,”Y”)==0) { printf(“\namount”); scanf(“%d”,goods[i].goods_amount);}

printf(“\nyou sure want goods remain(y/n): “);

scanf(“%s”,ch);

if(strcmp(ch,”y”)==0||strcmp(ch,”Y”)==0) { printf(“\nremain”); scanf(“%d”,goods[i].goods_remain);}

}

} }

output();

}

void dele() //數據刪除

{

int i,j;

char c[20];

printf(“\nenter you want delete name :\n”); //根據商品的名稱來刪除數據

printf(“name:”);

scanf(“%s”,c);

for(i=0;icount;i++)

if(strcmp(c,goods[i].goods_name)==0) break; //找到,即跳出循環

for(j=i;jcount-1;j++)

goods[j]=goods[j+1];

printf(“\t\t\tyou had delete %s\n”,c);

count–;

output();

}

void output() //數據輸出

{

int i;

for(i=0;icount;i++)

{

printf(“%s %s %lf %lf %d %d \n”,goods[i].goods_id,goods[i].goods_name,goods[i].goods_price,goods[i].goods_discount,goods[i].goods_amount,goods[i].goods_remain);

}

}

void search() //數據查找

{

int i;

char a[20],ch[10];

printf(“\nenter you want look name:”); //根據商品的名稱來查找數據

scanf(“%s”,a);

for(i=0;icount;i++)

if(strcmp(goods[i].goods_name,a)==0)

printf(“%s %s %lf %lf %d %d \n”,goods[i].goods_id,goods[i].goods_name,goods[i].goods_price,goods[i].goods_discount,goods[i].goods_amount,goods[i].goods_remain);

}

代碼在vc++6.0測試通過 有問題可以hi我

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/190661.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-11-30 09:05
下一篇 2024-11-30 09:05

相關推薦

  • AES加密解密演算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密演算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES演算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演著非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28
  • Python語言實現人名最多數統計

    本文將從幾個方面詳細介紹Python語言實現人名最多數統計的方法和應用。 一、Python實現人名最多數統計的基礎 1、首先,我們需要了解Python語言的一些基礎知識,如列表、字…

    編程 2025-04-28
  • Python作為中心語言,在編程中取代C語言的優勢和挑戰

    Python一直以其簡單易懂的語法和高效的編碼環境而著名。然而,它最近的發展趨勢表明Python的使用範圍已經從腳本語言擴展到了從Web應用到機器學習等廣泛的開發領域。與此同時,C…

    編程 2025-04-28
  • Python基礎語言

    Python作為一種高級編程語言擁有簡潔優雅的語法。在本文中,我們將從多個方面探究Python基礎語言的特點以及使用技巧。 一、數據類型 Python基礎數據類型包括整數、浮點數、…

    編程 2025-04-28

發表回復

登錄後才能評論