APP管理系统

/
/
           APP管理系统           
                                 
        学号:xxxxxxxxxxx         
           姓名:xxxxxx           
                        2020年8月
/
/

#include<stdio.h> 
#include<stdlib.h>
#include<string.h>
#include<conio.h>

#define USER "1234"
#define PASSWORD "1234"

struct  APP{
 int no;//编号
 char name[20];//名称 
 char version[20];//版本
 char time[20];//发布时间
};

struct List
{
	struct APP data;
	struct List* next;
};//单链表结构体

	
struct List* load();//加载文件函数的声明
void print(struct List* head);//打印链表 
void save(struct List* head);//保存文件
struct List* add(struct List* head);//新增
void init(); 
int menu();
void search(struct List* head);//查询
void change(struct List* head);//修改
struct List* del(struct List* head);//删除
void sort(struct List* head);//排序

int main()
{
	int choice;
	struct List* head;
	init(); 
	head=load();
	do
	{
		choice=menu();
		switch(choice)
		{
		case 1:
			head=add(head);
		case 2:
			print(head);
			break;
		case 3:
			search(head);
			break;
		case 4:
		    change(head);
			break; 
		case 5:
			head=del(head);
			break;
		case 6:
			sort(head);
			print(head);
			break;	
		}
	}while(choice!=0);
	save(head);
	return 0;
}

int menu()
{
	int choice;
	system("cls");
	printf("\n\n\n\n\n\n\n");
	printf("                         ********** 欢迎光临 **********\n\n");
	printf("         ************************ APP管理系统 ************************\n\n\n");
	printf("\n\n"); 
	printf("                      ***********************************\n"); 
	printf("                      *1:新增APP信息       2:显示APP信息*\n");
	printf("                      *3:查询APP信息       4:修改APP信息*\n");
	printf("                      *5:删除APP信息       6:排序APP信息*\n"); 
	printf("                      *0:退出                           *\n");
	printf("                      ***********************************\n"); 
	printf("                      请输入选择:");
	scanf("%d",&choice);
	return choice;
}

void search(struct List* head)
{
	int no;
	struct List* p=head;
	printf("请输入要查询的APP编号:");
	scanf("%d",&no);
	while(p)
	{
		if(p->data.no==no)
		{
			printf("%d %s %s %s\n",p->data.no,p->data.name,p->data.version,p->data.time);
			break;
		}
		p=p->next;
		
	}
	if(p==NULL)
	{
		printf("无该APP信息!\n");
	}
	system("pause");
}
void change(struct List* head)
{
	struct APP t;
	struct List* p=head;
	system("cls");
	printf("请输入要修改的APP编号:");
	scanf("%d",&t.no);
	while(p)
	{
		if(p->data.no==t.no)
		{
			printf("%d %s %s %s\n",p->data.no,p->data.name,p->data.version,p->data.time);
			break;
		}
		p=p->next;
	}
	if(p==NULL)
	{
		printf("无该APP信息!\n");
	}
	else
	{
		printf("请修改APP名称:");
		scanf("%s",t.name);
		printf("请修改APP版本:");
		scanf("%s",t.version);
		printf("请修改APP发布时间:");
		scanf("%s",t.time);
		p->data=t;
		printf("修改成功!\n");
	}
}
struct List* del(struct List* head)
{
	int no;
	struct List* p=head,*q;
	printf("请输入要删除的APP编号:");
	scanf("%d",&no);
	while(p)
	{
		if(p->data.no==no)
		{
			printf("%d %s %s %s\n",p->data.no,p->data.name,p->data.version,p->data.time);
			break;
		}
		q=p;
		p=p->next;
	}
	if(p==NULL)
	{
		printf("无该APP信息!\n");
	}
	else
	{
		if(p==head)
		{
			head=head->next;
		}
		else
		{
			q->next=p->next;
		}
		free(p);
		printf("删除成功!\n");
	}
	return head;
}
void sort(struct List* head)
{
	struct List* i,*j;
	struct  APP temp;
	for(i=head;i!=NULL;i=i->next)
	{
		for(j=i->next;j!=NULL;j=j->next)
		{
			if(i->data.no>j->data.no)
			{
				temp=i->data;
				i->data=j->data;
				j->data=temp;
			}
		}
	}
}

void init()
{
	int n,y=1,i=0;
	char a,d,b[10];
	char code[100];
	struct hotelinfo *head=NULL;
	while(y)
	{	
		system("cls");
        printf("\n\n\n\n\n\n\n");
	    printf("                         ********** 欢迎光临 **********\n\n");
	    printf("         ************************ APP管理系统 ************************\n\n\n");
		printf("\n\n"); 
		printf("                      ***********************************\n"); 
		printf("                      ************1-用户登录***********\n");
		printf("                      ************0-退出系统***********\n");
		printf("                      ***********************************"); 
		printf("\n");
		printf("       请输入您的选择:");
		scanf("%d",&n);
		printf("\n");
		getchar();
		switch(n){
		case 0:
			exit(0);
			break;
		case 1:
	    	printf("       请输入您的用户名(1234):");
        	gets(b);
	    	printf("\n");	
	    	printf("       请输入您的密码(1234):");
	    	//scanf("%d",&c);
			/*********/
			while((a=getch())!='\r')
			{
				if(a=='\b')
				{
					if(i>0)
					{
						printf("\b \b");
						i--;
					}
				}
				else
				{
					code[i++]=a;
					printf("*");
				}
			}
			code[i]='\0';
			/*********/
	    	printf("\n");
	    	if(strcmp(b,USER)!=0||strcmp(code,PASSWORD)!=0)
			{
				printf("           验证失败,请重新输入!\n");
				scanf("%c",&d);
				getchar();
				system("cls");
			} 
			else
			{
					return;
			}
			break;
		default:
			printf("        您的输入有误!  请重新输入!\n");
			printf("        按任意键继续!\n");
			getchar();
			break;
		} 
	}
}	 
struct List* add(struct List* head)
{
	struct  APP newapp;
	struct List* p;
	printf("请输入APP编号:");
	scanf("%d",&newapp.no);
	printf("请输入APP名称:");
	scanf("%s",newapp.name);
	printf("请输入APP版本:");
	scanf("%s",newapp.version);
	printf("请输入APP发布时间:");
	scanf("%s",newapp.time);
	p=(struct List*)malloc(sizeof(struct List));
	p->data=newapp;
	p->next=head;
	return p;
}

void save(struct List* head)
{
	struct List *p=head;
	FILE* fp=fopen("f1.txt","w");
	if(fp==NULL)
	{
		printf("写入文件时,文件无法打开!");
		exit(0);
	}
	while(p)
	{
		fprintf(fp,"%d %s %s %s\n",p->data.no,p->data.name,p->data.version,p->data.time);
		p=p->next;
	}
	fclose(fp);
}

struct List* load() 
{
	FILE* fp;
	struct List *head,*tail,*p1;
	head=tail=NULL;
	if((fp=fopen("f1.txt","r"))==NULL)
	{
		printf("不存在此文件,无法打开!");
		fp=fopen("f1.txt","w");
		fclose(fp);
		exit(0);
	}
	if(fgetc(fp)!=EOF)
	{
		fp=fopen("f1.txt","r");
		while(!feof(fp))
		{
			p1=(struct List*)malloc(sizeof(struct List));
			fscanf(fp,"%d %s %s %s\n",&p1->data.no,p1->data.name,p1->data.version,p1->data.time);
			if(head==NULL)
			{
				head=p1;
				tail=head;
			}
			else
			{
				tail->next=p1;
			}
			tail=p1;
		}
		tail->next=NULL;
		fclose(fp);
	} 
	return head;
 }

void print(struct List* head)
{ 
	struct List* temp=head;
	while(temp!=NULL)
	{
		printf("%d %s %s %s\n",temp->data.no,temp->data.name,temp->data.version,temp->data.time);
		temp=temp->next;
	}
	system("pause");
} 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值