c语言商品管理系统

Python021

c语言商品管理系统,第1张

假设某超市经营各种商品,每种商品包括以下信息:商品编号、商品名称、商品品牌、库存数量、售价、已售数量。系统的主要功能包括:1. 创建商品信息文件:根据提示输入若干商品的信息,并将信息保存至一个文件中。2. 商品进货管理:每次购入新商品,需按要求输入商品所含各项信息并存入商品信息文件中。如果已经存在该商品(以商品编号为准),则修改相应的库存数量信息,否则生成新的商品信息记录。3. 商品销售管理:每次有商品销售出去,则按要求输入商品编号和商品名称信息,并修改相应的商品信息文件。注意:商品销售时要检查库存数量的合法性(即销售出去的数量必须小于库存数量)。4. 按不同条件进行查询操作,输出满足条件的商品信息。(1) 输入商品名称,在商品信息文件中查找相应的商品信息并输出。(2) 输入商品品牌,在商品信息文件中查找该品牌的所有信息并输出。5. 按不同条件对商品信息进行统计工作。(1) 输入商品名称,在商品信息文件中统计该商品的销售总额。(2) 设置一个库存数量警戒值,输出库存数量小于该警戒值的所有库存商品的信息。(3) 输入商品品牌,在商品信息文件中统计其不同商品名称的库存量,并输出库存量最高的那个商品的信息。

满意请采纳。

首先要创建数据库啊,也就是一个txt文件,要让里面有内容啊。其次是你的增加删除商品种类,修改指定商品的数目之类的,具体看老师的要求。

例程(基本框架,具体的操作需进一步开发):

#include <stdio.h> 

#include <stdlib.h> 

#include <conio.h> 

#include <memory.h>

int count=0

struct commodity

{

int id  /*商品编号*/

int number  /*库存数量*/

int price   /*单价*/

char name[20]  /*商品名称*/

char indate[9]  /*入库时间*/

char deadline[9] /*有效日期*/

}a[100]

void page_title(char *menu_item) 

printf("【商品库存管理系统】\n",menu_item) 

void return_confirm(void) 

printf("\n按任意键返回……\n") 

getch() 

}

void insert(void)     /*1插入*/

int search(void)     /*2商品信息的查询*/

}

void del(void)       /*3删除*/

void sort()        /*4排序*/

}

int modify(void)    /*5修改*/

{

}

int main(void)

{ menu: page_title("操作选单") 

printf("\t\t\t 1 信息查询\t2 全部商品\n\n") 

printf("\t\t\t 3 商品增加\t4 商品删除\n\n") 

printf("\t\t\t 5 信息修改\t0 退出程序\n\n ")

switch(getch()) 

case '1' : search()break 

case '2' : sort()break 

case '3' : insert()break 

case '4' : del()break

case '5' : modify()break

case '0' : exit(0) 

goto menu

   return 0

}

我这里有一个!

具体的,稍微改一下就可以了!

#include "stdio.h" /*I/O函数*/

#include "stdlib.h" /*其它说明*/

#include "string.h" /*字符串函数*/

#include "conio.h" /*屏幕操作函数*/

#include "mem.h" /*内存操作函数*/

#include "ctype.h" /*字符操作函数*/

#include "alloc.h" /*动态地址分配函数*/

struct score

{

int mingci

char xuehao[8]

char mingzi[20]

float score[6]

}data,info[1000]

int i,j,k=0

char temp[20],ch

FILE *fp,*fp1

void shuru()

{

if((fp=fopen("s_score.txt","ab+"))==NULL)

{

printf("cannot open this file.\n")

getch()exit(0)

}

for(i=0i<=1000i++)

{

printf("\nPlease shuru xuehao:")

gets(data.xuehao)

printf("Please shuru mingzi:")

gets(data.mingzi)

printf("Please shuru yuwen score:")

gets(temp)data.score[0]=atof(temp)

printf("Please shuru shuxue score:")

gets(temp)data.score[1]=atof(temp)

printf("Please input yingyu score:")

gets(temp)data.score[2]=atof(temp)

printf("Please shuru wuli score:")

gets(temp)data.score[3]=atof(temp)

printf("Please shur huaxue score:")

gets(temp)data.score[4]=atof(temp)

data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4]

fwrite(&data,sizeof(data),1,fp)

printf("another?y/n")

ch=getch()

if(ch=='n'||ch=='N')

break

} fclose(fp)

}

void xianshi()

{

float sint n

if((fp=fopen("s_score.txt","rb+"))==NULL)

{

printf("Cannot reading this file.\n")

exit(0)

}

for(i=0i<=1000i++)

{

if((fread(&info[i],sizeof(info[i]),1,fp))!=1)

break

}

printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n")

for(j=0,k=1j<ij++,k++)

{

info[j].mingci=k

printf("%6s %8s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],

info[j].score[5])

}

getch()

fclose(fp)

}

void xiugai()

{

if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)

{

printf("Cannot open this file.\n")

exit(0)

}

printf("\nPLease shuru xiugai xuehao:")

scanf("%d",&i)getchar()

while((fread(&data,sizeof(data),1,fp))==1)

{

j=atoi(data.xuehao)

if(j==i)

{

printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi)

printf("Please shuru mingzi:")

gets(data.mingzi)

printf("Please shuru yuwen score:")

gets(temp)data.score[0]=atof(temp)

printf("Please shuru shuxue score:")

gets(temp)data.score[1]=atof(temp)

printf("Please input yingyu score:")

gets(temp)data.score[2]=atof(temp)

printf("Please input wuli score:")

gets(temp)data.score[3]=atof(temp)

printf("Please input huaxue score:")

gets(temp)data.score[4]=atof(temp)

data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4]

} fwrite(&data,sizeof(data),1,fp1)

}

fseek(fp,0L,0)

fseek(fp1,0L,0)

while((fread(&data,sizeof(data),1,fp1))==1)

{

fwrite(&data,sizeof(data),1,fp)

}

fclose(fp)

fclose(fp1)

}

void chazhao()

{

if((fp=fopen("s_score.txt","rb"))==NULL)

{

printf("\nCannot open this file.\n")

exit(0)

}

printf("\nPLease shuru xuehao chakan:")

scanf("%d",&i)

while(fread(&data,sizeof(data),1,fp)==1)

{

j=atoi(data.xuehao)

if(i==j)

{

printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5])

}getch()

}

}

void shanchu()

{

if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)

{

printf("\nopen score.txt was failed!")

getch()

exit(0)

}

printf("\nPlease input ID which you want to del:")

scanf("%d",&i)getchar()

while((fread(&data,sizeof(data),1,fp))==1)

{

j=atoi(data.xuehao)

if(j==i)

{

printf("Anykey will delet it.\n")

getch()

continue

}

fwrite(&data,sizeof(data),1,fp1)

}

fclose(fp)

fclose(fp1)

remove("s_score.txt")

rename("temp.txt","s_score.txt")

printf("Data delet was succesful!\n")

printf("Anykey will return to main.")

getch()

}

main()

{

while(1)

{

clrscr()/*清屏幕*/

gotoxy(1,1)/*移动光标*/

textcolor(YELLOW)/*设置文本显示颜色为黄色*/

textbackground(BLUE)/*设置背景颜色为蓝色*/

window(1,1,99,99)/* 制作显示菜单的窗口,大小根据菜单条数设计*/

clrscr()

printf("*************welcome to use student manage******************\n")

printf("*************************menu********************************\n")

printf("* ========================================================= * \n")

printf("* 1>shuru 2>xiugai * \n")

printf("* 3>shanchu 4>chazhao * \n")

printf("* 5>xianshi 6>exit * \n")

printf("* * \n")

printf("* --------------------------------------------------------- * \n")

printf(" Please input which you want(1-6):")

ch=getch()

switch(ch)

{

case '1':shuru()break

case '2':xiugai()break

case '3':shanchu()break

case '4':chazhao()break

case '5':xianshi()break

case '6':exit(0)

default: continue

}

}

}