C语言程序设计-计算机设备管理

#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
struct node 
{
char no[12];
char name[40];
float dj;//单价
int num;//数量
float jine;//金额
struct node *link;//指向下一个节点的指针
};
struct node *p,*p1;
void main()
{
    struct node *create(struct node *);
void search(struct node *);
void fuzhi(struct node *);
void geshu(struct node *);
void print(struct node *);
struct node *head;
int g;
printf("\n\n\t\t             计算机设备管理             \t\n");
printf("\t\t|---------------------------------------|\n");
printf("\t\t|                                       |\n");
printf("\t\t|       [1]建立管理表                   |\n");
printf("\t\t|       [2]查找指定设备编号的记录       |\n");
printf("\t\t|       [3]复制管理表                   |\n");
printf("\t\t|       [4]输出管理表                   |\n");
printf("\t\t|       [0]退出系统                     |\n");
printf("\t\t|                                       |\n");
printf("\t\t|       请先创建新表                    |\n");
printf("\t\t|                                       |\n");
printf("\t\t|---------------------------------------|\n\n\n");
head=NULL;
for(;;)
{
printf("\n请输入你要选择的功能(输入对应编号即可):");
   scanf("%d",&g);
switch(g)
{
case 0:exit(0);break;
case 1:head=create(head);break;
case 2:search(head);break;
case 3:fuzhi(head);break;
case 4:print(head);break;
}
}
}
struct node * create(struct node *head)//创建链表函数
{
struct node *p1,*p2;
int n,i;
p1=p2=(struct node *)malloc(sizeof(struct node));
printf("\t\t * * * * * * * * * * * * * * * * * *\n\t\t*************************************\n");
printf("请输入记录的个数:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n请输入第%d位员工的信息:\n",i+1);
   printf("请输入设备编号:");
   scanf("%s",&p1->no);
        printf("请输入名称:");
      scanf("%s",p1->name);
    printf("请输入单价:");
   scanf("%f",&p1->dj);
        printf("请输入数量:");
scanf("%d",&p1->num);
p1->jine=p1->dj*p1->num;
   p1->link=NULL;
if(head==NULL)
head=p1;
else
p2->link=p1;
p2=p1;
p1=(struct node *)malloc(sizeof(struct node));
}
printf("\n                                 输入完成!");
printf("\n\t\t * * * * * * * * * * * * * * * * * *\n\t\t*************************************\n");
return head;
}
void search(struct node *head)//查找结点函数
{
char n[12];
struct node *temp;
printf("\n请输入设备编号:");
scanf("%s",n);
temp=head;
while(temp!=NULL)
{
if(strcmp(temp->no,n)==0)
{
printf("名称:%s--单价:%.2lf--数量:%d\n",temp->name,temp->dj,temp->num);
   printf("\n                                 查找完成!");
       printf("\n\t\t * * * * * * * * * * * * * * * * * *\n\t\t*************************************\n");
  break;
}
temp=temp->link;
}
if(temp==NULL)
{
printf("\n您输入的设备编号有误,无法查询!\n");
   printf("\n\t\t * * * * * * * * * * * * * * * * * *\n\t\t*************************************\n");
}
}


void fuzhi(struct node *head)//将head赋给p1
{
p=p1=(struct node *)malloc(sizeof(struct node));
p=head;
p1=p;
while(head!=NULL)
{
p=(struct node *)malloc(sizeof(struct node));
p=p->link;
head=head->link;
p=head;
}
printf("\n                                 复制完成!");
    printf("\n\t\t * * * * * * * * * * * * * * * * * *\n\t\t*************************************\n");
}
void print(struct node *head)//输出函数
{
struct node *temp;
temp=head;
printf("\t\t * * * * * * * * * * * * * * * * * *\n\t\t*************************************\n");
printf("\n\t-----计算机设备管理表------\n");
printf("\n编号-----名称-----单价-----数量-----金额");
while(temp!=NULL)
{
printf("\n%s-------%s-------%.2f-------%d-------%.2f\n",temp->no,temp->name,temp->dj,temp->num,temp->jine);
temp=temp->link;
}
printf("\t\t * * * * * * * * * * * * * * * * * *\n\t\t*************************************\n");
return;
}

发布了17 篇原创文章 · 获赞 11 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_33360009/article/details/75543938