C语言中的货
A. 用c语言编写一个仓库货物管理系统的程序
个人觉得,题主的题的难度不亚于一个C语言的课程设计哈,在这提问不太合适。
就提供给你思路吧。
职工信息可以存入一个结构体数组中,此结构体元素包含有货物编号(unsigned int cargo_number;);货物名称(char cargo_name[10];);货物价格(unsigned int cargo_price;);货物数量(unsigned int cargo_price;)。。。其他元素,题主根据要求添加元素。
然后,构建函数用来添加货物名称:void add_cargo_info(...)(形参元素为结构体数组名),即手动添加货物信息,完事后记得要将信息写入磁盘文件中;
然后,构建函数显示信息,这个简单,void display_cargo_info(...)(形参为结构体数组名),用一个while循环输出即可;
然后,查询函数,void cargo_info_search(...)(形参可为多种,名字,编号。。。),同样用while循环搞定;
然后,修改信息,void cargo_info_update(...)(形参同为结构体数组),调用查找函数,找到要修改的货物,然后在此信息中修改即可;
然后,删除信息,void cargo_info_delete(...)(形参同为结构体数组),也是首先找到要删除的信息,然后要调用保存函数。
这个就是我的思路,题主可以参考,希望解决了题主的问题。
B. c语言程序设计 用链表编写商品库存管理。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node{
char no[20];//存放编号
char name[40];//存放名称
int reserve;//库存
struct node *next;
}NODE;
typedef struct link{
NODE *front;//头指针
NODE *rear;//尾指针
}LINK;
NODE *create_node(void){
NODE *node = (NODE *)malloc(sizeof(NODE));
printf("请输入货物编号:");
gets(node->no);
printf("请输入货物名称:");
gets(node->name);
printf("请输入货物名称:");
char ch;
while( (ch= getchar()) != '\n');//rewind(stdin);
scanf("%d",&node->reserve);
node->next = NULL;
return node;
}
void init_link(LINK *link){
link->rear = NULL;
link->front = NULL;
}
int link_empty(LINK *link){
return link->front == NULL ? 1: 0;
}
int node_num(LINK *link){
int num = 0;
if( link_empty(link)){
return num;
}
num = 1;
NODE *node = link->front;
while(node != link->rear){
node = node->next;
++num;
}
return num;
}
/*NODE *node_find(LINK *link,const int n){
int num = node_num(link);
if(num < n){
printf("公有节点%d个,无法找到第%d个节点\n",num,n);
}
else{
}
}
*/
void node_push(LINK *link){
NODE *node = create_node();
if(link->front == NULL){
link->front = node;
link->rear = node;
node->next = NULL;
}
else{
link->rear->next = node;
link->rear = node;
node->next = NULL;
}
}
void node_insert(LINK *link,const int n){
int num = 0,i = 1;
NODE *node = link->front;
NODE *new_node = NULL;
if ( link_empty(link) ){
printf("链表为空,将建立链表!\n");
node_push(link);
}
else{
if( n <= 1){
printf("在链表头插入数据\n");
new_node = create_node();
new_node->next = link->front;
link->front = new_node;
}
else if( n>= num = node_num(link) ){
printf("节点数少于%d,将在末尾插入节点.\n",n);
node_push(link);
}
else{
printf("在第n个节点后插入数据\n");
if(num >= n){
while( i != n){
node = node->next;
++i;
}
new_node = create_node();
new_node-next = node->next;
node->next = new_node;
}
}
}
void find_node_insert(LIKNK *link,const char *name){
NODE *node = link->front;
if( link_empty(link) )
node_push(link);
else {
while(strcmp(node->name,name) != 0){
if(node != link->rear)
node = node->next;
else break;
}
if(node != NULL){
NODE *new_node = create_node();
new_node-next = node->next;
node->next = new_node;
}
else {
printf("没有找到相关货物,将在头节点插入数据\n");
intsert(link,0);
}
}
/*由于我不知到你对货物统计具体实现的要求,关于货物数量统计就你自己写了,应该比较简单。*/
/* 代码没有具体运行过,如果你学过C结构体与指针,就这个代码思路应该看得明白,真正的实现你自己实现吧
这样对你会更好写。可能会有错误的地方,请谨慎。 */
C. C语言编程:货物管理系统
可以提供一个很类似的:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#defineN100
structhardware
{
intID;
charname[35];
intnum;
floatprice;
}output={0,"empty",0,0};
intmain()
{
voidinit(hardware*output);
voiddelect(void);
voidfoutput(void);
voidrenew(void);
inti=0,select;//记录静态链表的长度
do
{
printf("************************** ");
printf("*请输入您要执行的操作:* ");
printf("*0------>创建商品文件* ");
printf("*1------>更新商品信息* ");
printf("*2------>打印商品文件* ");
printf("*3------>删除商品信息* ");
printf("*4------>确定退出程序* ");
printf("************************** ");
printf("请输入您的选择:");
scanf("%d",&select);
if(select==4)
{
return0;
}
elseif(i==0&&select!=0)
{
printf("商品文件尚未建立,不能进行该操作! ");
select=5;
}
switch(select)
{
case0:init(&output);printf("文件commodity.dat已创建完成! ");i++;break;
case1:renew();printf("指定的信息已经更新完成. ");break;
case2:foutput();printf("指定的文件commodity.dat已经打印完成. ");break;
case3:delect();printf("库存为零的商品已经删除完成. ");break;
case4:break;
default:printf("输入有误!请重新输入. ");
}
}while(select!=4);
return0;
}
voidrenew(void)
{
FILE*pf;
hardware*tem;
inti=0,j,num,ID;
if((tem=(hardware*)malloc(sizeof(hardware)))==NULL)
{
printf("memoryerror! ");
exit(0);
}
printf("请输入您要您要更新的商品条数: ");
scanf("%d",&num);
while(i<num)
{
z:printf("请输入需要更新的商品号: ");
scanf("%d",&ID);
if(ID>N||ID<1)
{
printf("输入的商品号有误,请重新输入! ");
gotoz;
}
if((pf=fopen("D:\commodity.dat","rb+"))==NULL)
{
printf("openfileerror! ");
exit(0);
}
for(j=0;j<N;j++)//读出数据
{
if(!fread(tem,sizeof(hardware),1,pf))
{
printf("outputerror! ");
}
if(tem->ID==ID)
{
printf("记录号:%d 工具名%s 数量%d 价格%.3f ",tem->ID,tem->name,tem->num,tem->price);
printf(" 请输入新的商品信息: ");
printf("请输入需要更新的第%d件的工具名: ",i+1);
scanf("%s",tem->name);
printf("请输入需要更新的第%d件商品数量和价格(以空格隔开): ",i+1);
scanf("%d%f",&tem->num,&tem->price);
fseek(pf,-1L*sizeof(hardware),1);
if(!fwrite(tem,sizeof(hardware),1,pf))
{
printf("inputerror! ");
}
printf("第%d个商品数据更新成功! ",i+1);
break;
}//if
}//for
fclose(pf);
i++;
}//while
free(tem);
}
voidfoutput(void)
{
FILE*pf;
hardwaretem;
inti;
if((pf=fopen("D:\commodity.dat","rb"))==NULL)
{
printf("openfileerror! ");
exit(0);
}
printf(" *********打印列表如下:********* ");
for(i=0;i<N;i++)//读出数据
{
if(!fread(&tem,sizeof(hardware),1,pf))
{
printf("outputerror! ");
}
if(strcmp(tem.name,"empty"))//
{
printf("记录号:%d 工具名%s 数量%d 价格%.3f ",tem.ID,tem.name,tem.num,tem.price);
}
}
fclose(pf);
}
voiddelect(void)
{
FILE*pf;
hardware*tem;
inti;
if((tem=(hardware*)malloc(sizeof(hardware)))==NULL)
{
printf("memoryerror! ");
exit(0);
}
if((pf=fopen("D:\commodity.dat","rb+"))==NULL)
{
printf("openfileerror! ");
exit(0);
}
for(i=0;i<N;i++)//读出数据
{
fseek(pf,0,1);
if(!fread(tem,sizeof(hardware),1,pf))
{
printf("outputerror! ");
}
if(tem->num==0)
{
strcpy(tem->name,"empty");//
tem->price=0;
fseek(pf,-1L*sizeof(hardware),1);
if(!fwrite(tem,sizeof(hardware),1,pf))
{
printf("inputerror! ");
}
}//if
}//for
fclose(pf);
free(tem);
}
voidinit(hardware*output)
{
FILE*pf;
inti;
if((pf=fopen("D:\commodity.dat","wb"))==NULL)
{
printf("openfileerror! ");
exit(0);
}
for(i=0;i<N;i++)//初始化100个元素
{
output->ID=i+1;
if(!fwrite(output,sizeof(hardware),1,pf))
{
printf("inputerror! ");
}
}
fclose(pf);//关闭文件,完成初始化的所有操作
}