【求助】求补全c语言日程管理系统代码,最迟明早 9 点就要
题目要求:用户表:用户姓名、登录密码。
日程表:日程编号、日程内容、创建日期、开始时间、结束时间、所属用户。
功能要求:
1.用户进入系统之前有、登录和注册的功能。注册时、应判断是否用户名重复
2.用户使用这个系统成功登录的时候,列出一个菜单、菜单里面包含所有的选择
3.用户具有:新建日程、查看当前未过时日程、和历史日程、删除日程
4.用户只能操作所属自己的日程
5.要求将数据保存在数据文件中。每一类信息存放在一个文件中,在程序中以链表的形式来存储和处理数据。
代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <conio.h>
#include <time.h>
typedef struct User
{
char Name[20];
char Pass[7];
}User;
typedef struct Date
{
int Year;
int Month;
int Day;
}Date;
typedef struct Data
{
int No;
int Count;
char Name[20];
Date Time;
char Info[401];
struct Data *Next;
}Data;
int Enroll();
Data *Creat();
void Clock();
int See();
int Add();
void Browse(Data *Head, int count);
int Delete();
void Menu();
int Login();
int Mode(int slec, char Name[]);
int main()
{
FILE *fp;
int slec;
int Run=1;
char New[20]="Admin",Key[20]="admin";
if (fopen("Users.list","rb") == NULL)
{
printf("初始化...");
fp=fopen("Users.list","wb");
printf("内置账户:%s,长度:%d",New,strlen(New));
fwrite(New,20,1,fp);
printf("初始密码:%s,长度:%d",Key,strlen(Key));
fwrite(Key,20,1,fp);
fclose(fp);
printf("完成!\n");
}
while (Run)
{
printf("====================欢迎使用日程管理系统!======================\n");
printf(" 请选择 1.注册 2.登录 ");
scanf("%d",&slec);
if (slec==1) Run=Enroll();
else if (slec==2) Run=Login();
else printf("该功能尚未开发。\n");
}
return 0;
}
int Enroll()
{
FILE *fp;
char Name[20],New[20],Key[20];
getchar();
fp=fopen("Users.list","rb+");
if (fp == NULL) {printf("文件打开失败!\n"); return 1;}
printf("请输入要新建的用户名(至多19个字符):");
fgets(New,20,stdin);
New[strlen(New)-1]='\0';
while(1)
{
if(fread(Name,20,1,fp) != 1) break;
if (strcmp(New, Name) == 0)
{
printf("用户名已存在!请重新创建...\n");
fclose(fp);
return 1;
}
fread(Key,7,1,fp);
}
printf("请输入密码:(至多19个字符)");
fgets(Key,20,stdin);
Key[strlen(Key)-1]='\0';
fwrite(New,20,1,fp);
fwrite(Key,20,1,fp);
printf("创建完成,请重新登录!\n");
fclose(fp);
return 1;
}
void Clock()
{
time_t t;
struct tm *tp;
t=time(NULL);
tp=localtime(&t);
printf("当前本机时间为 ");
printf("%d:%d:%d\n ",tp->tm_hour,tp->tm_min,tp->tm_sec);
printf("%d年%d月%d日 ",tp->tm_year+1900,tp->tm_mon+1,tp->tm_mday);
printf("今天是本周第%d天,今年的第%d天\n ",tp->tm_wday,tp->tm_yday);
}
Data *Creat(Data *Last)
{
Data *New=NULL;
New=(Data*)malloc(sizeof(Data));
if (New == NULL)
{
printf("内存分配失败!\n");
return NULL;
}
Last=New;
Clock();
printf("请输入日程时间(格式:年.月.日)");
scanf("%d.%d.%d",&New->Time.Year,&New->Time.Month,&New->Time.Day);
getchar();
printf("请输入日程内容:(至多400字符)\n ");
fgets(New->Info,400,stdin);
New->Info[400]='\0';
New->Next=NULL;
return New;
}
int Add(char Name[20])
{
FILE *fp;
Data New;
fp=fopen("Users.list","rb+");
if (fp == NULL) {printf("文件打开失败!\n"); return 1;}
Clock();
printf("请输入日程时间(格式:年.月.日)");
scanf("%d.%d.%d",&New.Time.Year,&New.Time.Month,&New.Time.Day);
getchar();
printf("请输入日程内容:(至多400字符)\n ");
fgets(New.Info,400,stdin);
New.Info[400]='\0';
fwrite(&New.Time.Year,sizeof(int),1,fp);
fwrite(&New.Time.Month,sizeof(int),1,fp);
fwrite(&New.Time.Day,sizeof(int),1,fp);
fwrite(New.Info,401,1,fp);
return 1;
}
int Mode(int slec, char Name[20])
{
FILE *fp;
Data *New=NULL,*Temp=NULL,*Head=NULL;
int count=0;
fp=fopen(Name,"rb+");
if (fp == NULL) {printf("文件打开失败!\n"); return 1;}
while(1)
{
New=(Data*)malloc(sizeof(Data));
if (New == NULL)
{
printf("内存分配失败!\n");
return 1;
}
if (Head == NULL) {Head=New;Temp=New;} printf("ready!\n");
if(fread(&New->Time.Year,sizeof(int),1,fp) != 1) break; printf("start!\n");
fread(&New->Time.Month,sizeof(int),1,fp);
fread(&New->Time.Day,sizeof(int),1,fp);
fread(New->Info,401,1,fp); New->Next=NULL;
New->Count=(++count); printf("over!\n");
printf("序号%d 日期%d.%d.%d",&Head->Count,
&New->Time.Year,&New->Time.Month,&New->Time.Day);
puts(New->Info);
Temp=New;
}
if (slec==3) Browse(Head,count);
fclose(fp);
return 1;
}
void Menu(char Name[20])
{
int Run=1;
char slec;
FILE *fp;
printf("===========================登录成功=============================\n");
if (fopen(Name,"rb") == NULL)
{
printf("您是新用户,来创建您的第一个日程!\n");
fp=fopen(Name,"wb");
fclose(fp);
Run=Add(Name);
}
while (Run)
{
printf("================================================================\n",Name);
printf("已登录为%s\n",Name);
printf("================================================================\n",Name);
printf(" 1.新建日程\n");
printf(" 2.查看当前日程\n");
printf(" 3.浏览所有日程\n");
printf(" 4.删除日程\n");
printf(" 5.退出登录\n");
printf(" 请选择相应序号: ");
scanf("%d",&slec);
if (slec==1) Add(Name);
else if (slec>=2 && slec<=4) Run=Mode(slec,Name);
else if (slec==5) break;
else printf("该功能尚未开发。\n");
}
}
int Login()
{
FILE *fp;
int Run=0;
char Name[20],Pass[20],New[20],Key[20];
getchar();
fp=fopen("Users.list","rb+");
if (fp == NULL) {printf("文件打开失败!\n"); return 1;}
printf("请输入用户名:");
gets(New);
while(1)
{
if(fread(Name,20,1,fp) != 1) break;
fread(Pass,20,1,fp);
if (strcmp(New, Name) == 0) {Run=1;break;}
}
fclose(fp);
if (Run == 1)
{
printf("请输入密码:");
gets(Key);
if (strcmp(Key,Pass) != 0)
printf("密码错误!\n");
else
{
Menu(Name);
printf("已退出登录!three\n");
}
}
else
printf("用户不存在!\n");
return 1;
}
void Browse(Data *Head, int count)
{
printf("以下为您的所有日程,共%d条:\n",&count);
while(count--)
{
printf("序号%d 日期%d.%d.%d",&Head->Count,
&Head->Time.Year,&Head->Time.Month,&Head->Time.Day);
puts(Head->Info);
Head=Head->Next;
}
}