欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

一个简单的信息管理系统

程序员文章站 2022-05-06 18:18:16
...

问题描述:
要求程序有主菜单,执行时显示实例为:
Ostrich 管理系统功能菜单
1.增加Ostrich ;
2.删除Ostrich ;
3.修改Ostrich ;
4.查询Ostrich 信息;
5.统计Ostrich 个数;
6.输出Ostrich 列表;
7.退出;
请输入你的选择(1-7):
请实现以上功能。

#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include "DancersDef.h"
#include "DancersAlgo.h"
int main(){
	linklist *head,*p;int flag=0;
	//char name[4],biaohao;
	system("color E5");
	int SelectNumber;int bianhao;
	
    do{
	SelectNumber=menu();
	switch(SelectNumber){
		case 1:
			head=create();
			break;
		case 2:
			printf("						请输入要删除的编号:");
			scanf("%d",&bianhao);
			delet(head,bianhao);
			PrintList(head);
			break;
		case 3:
			ChangeMenu();
			printf("						请输入要修改的信息的编号:");
			scanf("%d",&bianhao);
			change(head,bianhao);
			PrintList(head);
			break;
		case 4:
			printf("						请输入要查询的编号:");
			scanf("%d",&bianhao);
			flag=search(head,bianhao);
			if(flag!=1) printf("\n						查无此人\n");
			break;		
		case 5:
			counts(head);
			break;
		case 6:
			//printf("						----------------------------------------------------\n");
			PrintList(head);
			
			break;
		case 7:
			sort(head);
			PrintList(head);
			break;
		
		case 8:
			PrintList1(head);
			break;
		case 9:
			exit(0); 
		}
	}while (SelectNumber<9);
}

typedef struct dan{
  char name[5];
  int bianhao;
  char sex[5];
  int height;
  int weight;
  int nianling;
  int dengji;
  struct dan *next;
}dancer,linklist;


int  menu(){
	int m;printf("\n						----------------------------------------------------");
	printf("\n						鸵鸟信息管理系统菜单:\n");
	printf("\n						1. 建立信息链表");
	printf("\n						2. 删除信息");
	printf("\n						3. 修改信息");
	printf("\n						4. 查询信息");
	printf("\n						5. 统计数目");
	printf("\n						6. 打印信息");
	printf("\n						7. 按照等级降序");
	printf("\n						8. 打印链表");
	printf("\n						9. 退出");
printf("\n						----------------------------------------------------");
	printf("\n						请输入1-8选择功能:");
	
	scanf("%d",&m);
	return m;
}

linklist *create(){
	linklist *head,*p,*q;
	head = (linklist *) malloc ( sizeof( linklist ) ); 
	head->next = NULL;
	q=head;
	printf("\n						请输入鸵鸟者的编号直到输入0结束\n");

	while(1){
		p = (linklist *) malloc ( sizeof( linklist ) ); 	
		printf("\t\t				编号:");
		scanf("%d",&p->bianhao);
	if(p->bianhao==0)	break;
		printf("\t					食性:");
		scanf("	%s",&p->name);
		//gets(p->name);
		printf("\t					性别:");
		scanf("	%s",&p->sex);
		printf("\t					身高:");
		scanf("	%d",&p->height);
		printf("\t					体重:");
		scanf("		%d",&p->weight);
		printf("\t					年龄:");
		scanf("		%d",&p->nianling);
		printf("\t					等级:");
		scanf("		%d",&p->dengji);
		p->next=NULL;
		q->next=p;
		q=p;

	
	}
return head;
}

void PrintList1(linklist *head)
{printf("\n						----------------------------------------------------\n");
	linklist  *p = head->next;
	printf("\n						顶点符号   领接信息\n");
	printf("                                                   %d",p->bianhao);
	while(p)
	{	p=p->next;
		
		if(!p) printf("      NULL");
        	else
			 printf("      %d",p->bianhao);	
		
	}


	printf("\n						----------------------------------------------------\n");
}




void PrintList(linklist *head){
printf("						----------------------------------------------------\n");
	linklist  *p = head->next;
	//for(int i=0;i<7;i++) printf("%c",information[i]);
	printf("						%s	%s	%s	%s	%s	%s	%s\n","编号","食性","性别","身高","体重","年龄","等级");
	while(p!=NULL){
		printf("						%d	%s	%s	%d	%d	%d	%d\n",p->bianhao,p->name,
			p->sex,p->height,p->weight,p->nianling,p->dengji);
		p=p->next;
	
	}printf("						----------------------------------------------------");
}
void delet(linklist *head,int bianhao){
	linklist *p=head->next ,*q=head;
	while(p!=NULL&&p->bianhao!=bianhao){q=p;p=p->next;}
		
	if(p->bianhao==bianhao){
		q->next =p->next;
		free(p);

		
	}
}
int search(linklist *head,int bianhao){
	linklist *p=head->next;
	while(p){
		
		if(p->bianhao!=bianhao) 	p=p->next;
		else  {printf("\n						%s	%s	%s	%s	%s	%s	%s\n","编号","食性","性别","身高","体重","年龄","等级");
		printf("\n						%d	%s	%s	%d	%d	%d	%d\n",p->bianhao,p->name,
			p->sex,p->height,p->weight,p->nianling,p->dengji);return 1;break;

	}
	}

}
void  counts(linklist*head){
	linklist *p=head->next;int i=0;
	if(p==NULL) printf("\n						个数为:%d",0);
	else{while(p){
		p=p->next;i++;
	}printf("\n						个数为:%d\n",i);}
}
void ChangeMenu(){
	
	printf("\n						修改的项目的号码如下:\n");
	printf("\n						1.编号");
	printf("  2.食性");
	printf("  3.身高");
	printf("  4.年龄");
	printf("  5.体重");
	printf("  6.性别");
	printf("  7.等级\n");
	
	

}
void change(linklist *head,int bianhao){
	linklist *p=head->next;int m;
	while(p!=NULL&&p->bianhao!=bianhao) p=p->next;
	printf("\n						输入要修改信息的号码:");
	scanf("%d",&m);
	switch(m){
		case 1:
			printf("						输入要修改的编号信息:");
			scanf("%d",&p->bianhao);
			
			break;
		case 2:
			printf("						输入要修改的食性信息:");
			scanf("%s",&p->name);
			
		//	gets(t);p->name=t;
			break;
		case 3:
			printf("						输入要修改的身高信息:");
			scanf("%d",&p->height);
		
			break;
		case 4:	
			printf("						输入要修改的年龄信息:");
			scanf("%d",&p->nianling);
			
			break;
		case 5:
			printf("						输入要修改的体重信息:");
			scanf("%d",&p->weight);
		
			break;
		case 6:
			printf("						输入要修改的性别信息:");
			scanf("%s",&p->sex);
			
			break;
		case 7:
			printf("						输入要修改的等级信息:");
			scanf("%d",&p->dengji);
			
			break;
	}
}

运行结果:
一个简单的信息管理系统
一个简单的信息管理系统
一个简单的信息管理系统
一个简单的信息管理系统
一个简单的信息管理系统

这是我们大一期末课设的一部分,,,哈哈,看完代码是不是觉得很简单呢

相关标签: 链表 算法