⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bwl.cpp

📁 这是1个备忘录程序
💻 CPP
字号:
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
#include<time.h>
#include<conio.h>
#include<windows.h>
#include<mmsystem.h> 
#define NULL 0
#define LEN sizeof(struct bwl)

struct bwl
{
	long num;
	long num1;
	char a[20];
	char b[40];
	char c[80];
	struct bwl *next;
};
int n,i;
long m,j;
void tixing(struct bwl *head)
{
	struct bwl *p;
	p=head;
	do
	{
		if(j==p->num)
		{
			PlaySound("今天有事.wav", NULL, SND_FILENAME | SND_ASYNC);
            printf("编号:%d\t%-10ld %-10s %-20s %-20s\n",p->num1,p->num,p->a,p->b,p->c);
		}
		p=p->next;
	}
	while(p!=NULL);
}

void print(struct bwl *head)
{
	struct bwl *p;
	i=1;
	system("cls");
	time_t t;
	tm *tp;
	t=time(NULL);   
    tp=localtime(&t);
	printf("今日日期:%d年%d月%d日\n",tp->tm_year+1900,tp->tm_mon+1,tp->tm_mday);
	printf("*******************************************************************************\n");
	p=head;
	if(head!=NULL)
		do
		{
			p->num1=i;
			printf("编号:%d\t%-10ld %-10s %-20s %-20s\n",p->num1,p->num,p->a,p->b,p->c);
			if(m<p->num1)m=p->num1;
			p=p->next;
			i++;
		}
		while(p!=NULL);
	printf("*******************************************************************************\n");
	printf("今天有的事:\n");
	tixing(head);
}

struct bwl *creat(void)
{
	struct bwl *head;
	struct bwl *p1,*p2;
	n=0;m=0;
	p1=p2=(struct bwl*)malloc(LEN);
    printf("请输入日期,例如:20070226,输入0结束\n");
	scanf("%ld",&p1->num);
    printf("请输入时间,例如:下午2点\n");
	scanf("%s",&p1->a);
    printf("请输入内容摘要,例如:小学同学\n");
	scanf("%s",&p1->b);
    printf("请输入记录内容,例如:一定去\n");
	scanf("%s",&p1->c);
	p1->num1=n+1;
	while(p1->num!=0)
	{	
	    n=n+1;
		if(n==1)head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct bwl *)malloc(LEN);
        printf("请继续添加,请输入日期,例如:20070226,输入0结束\n");
	    scanf("%ld",&p1->num);
		if(p1->num==0)break;
        printf("请输入时间,例如:下午2点\n");
	    scanf("%s",&p1->a);
        printf("请输入内容摘要,例如:小学同学\n");
	    scanf("%s",&p1->b);
        printf("请输入记录内容,例如:一定去\n");
	    scanf("%s",&p1->c);
	    p1->num1=n+1;
	}
	p2->next=NULL;
	return head;
}

struct bwl *del(struct bwl *head,long num)
{
	struct bwl *p1,*p2;
	if(head==NULL) {printf("\nlist null!\n");goto end;}
	p1=head;
	while(num!=p1->num1&&p1->next!=NULL)
	{
		p2=p1;p1=p1->next;
	}
	if(num==p1->num1)
	{
		if(p1==head)head=p1->next;
		else p2->next=p1->next;
	    printf("delete:%ld\n",num);
	    n=n-1;
	}
	else printf("%ld not been found!\n",num);
end:{};
	return head;
}

struct bwl *insert(struct bwl *head,struct bwl *stud)
{
	struct bwl *p0,*p1,*p2;
	p1=head;
	p0=stud;
	if(head==NULL)
	{
		head=p0;p0->next=NULL;
	}
	else
	{
		while((p0->num>p1->num)&&(p1->next!=NULL))
		{
			p2=p1;
		    p1=p1->next;
		}
		if(p0->num<=p1->num)
		{
			if(head==p1)head=p0;
			else p2->next=p0;
			p0->next=p1;}
		else
		{
			p1->next=p0;p0->next=NULL;
		}
	}
	n=n+1;
	return head;
}

void save(struct bwl *head)
{
	struct bwl *p;
	FILE *fp;
	if((fp=fopen("备忘录.cpp","wb"))==NULL)
	{
		printf("cannot open file\n");
	    return;
	}
	p=head;
	while(p!=NULL)
	{
		if(fwrite(p,LEN,1,fp)!=1)
			printf("file write error\n");
		p=p->next;
	}
	fclose(fp);
}

struct bwl *load()
{
	struct bwl *head,*p;    
	FILE *fp;   
	if((fp=(fopen("备忘录.cpp","rb")))==NULL)   
	{
		printf("\t\t\t------------------------\n");
		printf("\t\t\t the file open error !\n");
		printf("\t\t\t------------------------\n");
		return NULL; 
	}
	head=NULL;
	while((p=(struct bwl *)malloc(LEN))&&(fread(p,LEN,1,fp)==1))  
	{
        p->next=head;
	    head=p;	
	}
	free(p);
	fclose(fp);
	return head;
}

struct bwl *sort(struct bwl *head)
{ 
struct bwl *first,*tail,*p_min,*min,*p; 
first=NULL;
while (head!=NULL) 
{
for(p=head,min=head;p->next!=NULL;p=p->next) 
{   
if(p->next->num<min->num) 
{
p_min=p;  
min=p->next; 
}
}
if(first==NULL) 
{
first=min; 
tail=min; 
}
else 
{
tail->next = min; 
tail=min;
}
if(min==head) 
{
head=head->next;
}
else 
{
p_min->next=min->next; 
}
}
if(first!=NULL) 
tail->next=NULL; 
head=first;
return head;
}

void windows()
{
	printf("\n");
	printf("\t┌─────────────────────────────┐\n");
	printf("\t│                                                          │\n");
	printf("\t│                   欢迎来到备忘录系统!                   │\n");
	printf("\t│                                                          │\n");
	printf("\t│ ***   ***  *********  ***        ***           ***       │\n");
	printf("\t│ ***   ***  *********  ***        ***        ***   ***    │\n");
	printf("\t│ ***   ***  ***        ***        ***       ***     ***   │\n");
	printf("\t│ *********  *********  ***        ***       ***     ***   │\n");
	printf("\t│ *********  *********  ***        ***       ***     ***   │\n");
	printf("\t│ ***   ***  ***        ***        ***       ***     ***   │\n");
	printf("\t│ ***   ***  *********  *********  *********  ***   ***    │\n");
	printf("\t│ ***   ***  *********  *********  *********     ***       │\n");
	printf("\t│                                                          │\n");
	printf("\t│                                              严  俊  杰  │\n");
	printf("\t│                                              2006121063  │\n");
	printf("\t│                                              网络(2)班 │\n");
	printf("\t│                                              网 络 工 程 │\n");
	printf("\t│                                                          │\n");
	printf("\t└─────────────────────────────┘\n");
	printf("\t");
	getch();
}

void main()
{
	time_t t;
	tm *tp;
	t=time(NULL);   
    tp=localtime(&t);
	printf("今日日期:%d年%d月%d日\n",tp->tm_year+1900,tp->tm_mon+1,tp->tm_mday);
	j=(tp->tm_year+1900)*10000+(tp->tm_mon+1)*100+tp->tm_mday;  
	char x;
	m=0;
	struct bwl  *head,*stu,*p;
	long del_num;
	p=load();
	head=sort(p);
	p=head;
	windows();
	do{
	p=load();
	head=sort(p);
	p=head;
	print(p);
	printf("\n                          1 创建备忘录请\n");
    printf("                          2 删除指定备忘录\n");
	printf("                          3 添加备忘录\n");
	printf("                          其他输入退出\n");
	x=getch();
	if(x=='1')
	{
		head=creat();
	}
	else if(x=='2')
	{
		printf("\n请输入要删除指定备忘录的编号,输入0结束:\n");
		scanf("%ld",&del_num);
		while(del_num!=0)
		{
			head=del(head,del_num);
		    print(head);
			printf("请输入要删除指定备忘录的编号,输入0结束:");
		    scanf("%ld",&del_num);
		}
	}
	else if(x=='3')
	{
        stu=(struct bwl *)malloc(LEN);
		printf("\n请输入日期,例如:20070226,输入0结束\n");
		scanf("%ld",&stu->num);
	    if(stu->num==0)continue;
        printf("请输入时间,例如:下午2点\n");
	    scanf("%s",&stu->a);
        printf("请输入内容摘要,例如:小学同学\n");
	    scanf("%s",&stu->b);
        printf("请输入记录内容,例如:一定去\n");
	    scanf("%s",&stu->c);
		m=m+1;
	    stu->num1=m;
		while(stu->num!=0)
		{
	
			head=insert(head,stu);
		    print(head);
			stu=(struct bwl *)malloc(LEN);
            printf("\n请输入日期,例如:20070226,输入0结束\n");
	        scanf("%ld",&stu->num);
		    if(stu->num==0)continue;
            printf("请输入时间,例如:下午2点\n");
	        scanf("%s",&stu->a);
            printf("请输入内容摘要,例如:小学同学\n");
	        scanf("%s",&stu->b);
            printf("请输入记录内容,例如:一定去\n");
	        scanf("%s",&stu->c);
			m=m+1;
	        stu->num1=m;
		}
	}
	else exit(0);
	save(head);
	p=load();
	p=sort(p);
	}
	while(1);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -