|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char adminname[20] = "admin1";
char adminpassword[20] = "a123456";
struct Date
{
int year;
int month;
int day;
};
typedef struct Infor
{
char name[20];
char gender[10];
int age;
char address[30];
char buytype[50];
char color[20];
long price;
struct Date date;
struct Infor *next;
}INFOR,*Pointer;
Pointer infor = NULL;
int login(void);
void Menushow(void);
void Add(Pointer *infor);
void Modify(Pointer *infor);
void Show(Pointer *infor);
void Search_name(Pointer *infor);
void Printuser(Pointer infor);
void Del(Pointer infor);
//void Sort(Pointer infor);
//void Loadfromfile(Pointer infor);
void Xuigai(char adminname[],char adminpassword[]);
int login(void)
{
char username[20];
char userpassword[20];
printf("请输入用户名:");
gets(username);
printf("请输入密码:");
gets(userpassword);
if(!strcmp(adminname,username) && !strcmp(adminpassword,userpassword))
{
return 1;
}
else
{
return 0;
}
}
void Menushow(void)
{
int i;
do/////////////////////////////
{
printf("\n");
printf(" |----1.增加购买电瓶车用户信息-----|\n");
printf(" |----2.修改购买电瓶车用户信息-----|\n");
printf(" |----3.显示购买电瓶车用户信息-----|\n");
printf(" |----4.查询用户信息---------------|\n");
printf(" |----5.删除用户信息---------------|\n");
printf(" |----6.按购买日期进行排序---------|\n");
printf(" |----7.从文件中读取用户信息-------|\n");
printf(" |----8.将购买用户信息保存到文件---|\n");
printf(" |----9.修改密码-------------------|\n");
printf(" |----10.退出系统------------------|\n");
printf("\n");
printf("请输入你选择的编号:");
scanf("%d",&i);
switch(i)
{
case 1:Add(&infor);break;
case 2:Modify(&infor);break;
case 3:Show(&infor);break;
case 4:Search_name(&infor);break;
case 5:Del(infor);break;
//case 6:Sort(&infor);break;
//case 7:Loadfromfile(&infor);break;
//case 8:Save();break;
//case 9:Xuigai(adminname,adminpassword);break;
//case 10:Quit();break;
}
//int test=0;
}while(i >=1 && i <=10);
}
void Add(Pointer *infor)
{
Pointer p;
static Pointer tail;
char ch;
do{
p = (Pointer)malloc(sizeof(INFOR));
if(p == NULL)
{
printf("内存分配失败\n");
exit(1);
}
printf("请输入姓名:");
scanf("%s",p->name );
printf("请输入性别(男/女):");
scanf("%s",p->gender );
printf("请输入年龄:");
scanf("%d",&p->age);
printf("请输入地址:");
scanf("%s",p->address );
printf("请输入购品牌和型号:");
scanf("%s",p->buytype );
printf("请输入购买的颜色:");
scanf("%s",p->color );
printf("请输入价格:");
scanf("%ld",&p->price );
printf("请输入购买时间:(yyyy-mm-dd):");
scanf("%d-%d-%d",&p->date.year,&p->date.month ,&p->date.day);
getchar();
printf("请问是否需要继续插入用户信息(Y/N):");
ch = getchar();
if((*infor )!= NULL)
{
tail->next = p;
p->next = NULL;
}
else
{
(*infor )= p;
p->next = NULL;
}
tail = p;
}while(ch == 'Y'||ch=='y');
}
void Modify(Pointer *infor)
{
Pointer p = *infor;
int flag = 0;
char sename[20];
getchar();
printf("请输入你要修改的用户名字:");
gets(sename);
if(p == NULL)
{
printf("并未存在任何数据,不能进行修改!!");
return ;
}
while(p != NULL)
{
if(!strcmp(p->name,sename))
{
flag = 0;
break;
}
else
{
flag = 1;
p = p->next;
}
}
if(flag)
{
printf("并未查询到该用户的信息T_T\n");
}
else
{
printf("请输入修改后的信息:\n");
printf("请输入姓名:");
scanf("%s",p->name );
printf("请输入性别(男/女):");
scanf("%s",p->age );
printf("请输入年龄:");
scanf("%d",&p->age);
printf("请输入地址:");
scanf("%s",p->address );
printf("请输入购品牌和型号:");
scanf("%s",p->buytype );
printf("请输入购买的颜色:");
scanf("%s",p->color );
printf("请输入价格:");
scanf("%ld",&p->price );
printf("请输入购买时间:(yyyy-mm-dd):");
scanf("%d-%d-%d",&p->date.year,&p->date.month,&p->date.day);
}
}
void Show(Pointer *infor)
{
Pointer p = *infor;
if(p == NULL)
{
printf("\n暂时还未存入数据!!\n");
printf("显示失败!!\n\n");
}
else
{
while(p != NULL)
{
printf("\n姓名:%s\n",p->name);
printf("性别:%s\n",p->gender );
printf("年龄:%d\n",p->age );
printf("地址:%s\n",p->address );
printf("购买品牌型号:%s\n",p->buytype );
printf("颜色:%s\n",p->color );
printf("价格:%ld\n",p->price );
printf("购买时间:%d-%d-%d\n\n",p->date.year ,p->date.month ,p->date.day);
p = p->next ;
}
}
}
void Search_name(Pointer *infor)
{
Pointer p = *infor;
char sename[20];
getchar();
printf("请输入你要查询的用户信息:");
gets(sename);
while(p != NULL)
{
if(!strcmp(sename,p->name))
{
Printuser(p);
break;///////////////
}
else{
p = p->next;
}
}
}
void Printuser(Pointer infor)
{
Pointer p = infor;
printf("姓名:%s\n",p->name );
printf("性别:%s\n",p->gender );
printf("年龄:%d\n",p->age );
printf("地址:%s\n",p->address );
printf("购买品牌型号:%s\n",p->buytype );
printf("颜色:%s\n",p->color );
printf("价格:%.2f\n",(float)p->price );
printf("购买时间:%d-%d-%d\n",p->date.year ,p->date.month ,p->date.day);
}
void Del(Pointer infor)
{
Pointer previous,current;
getchar();
current = infor;
previous = NULL;
char delname[20];
printf("请输入你要删除的用户姓名:");
gets(delname);
while(strcmp(delname,current->name) && current != NULL)
{
previous = current;
current = current->next ;
}
if(current == NULL)
{
printf("并未找到该用户的信息");
return ;
}
else
{
if(previous == NULL)
{
infor = current->next ;
}
else
{
previous->next = current->next ;
}
printf("删除成功");
free(current);
}
}
void Sort(Pointer infor)
{
;
}
void Loadfromfile(Pointer infor)
{
;
}
void Xuigai(char adminname[],char adminpassword[])
{
char username[20];
char userpassword[20];
do{
printf("请输入用户名:");
gets(username);
printf("请输入密码:");
gets(userpassword);
if(!strcmp(adminname,username) && !strcmp(adminpassword,userpassword))
{
do{
printf("请输入修改后的用户名:");
gets(adminname);
printf("请输入密码:");
gets(adminpassword);
printf("请再次输入密码:");
gets(userpassword);
}while(strcmp(userpassword,adminpassword));
}
}while(strcmp(adminname,username) || strcmp(adminpassword,userpassword));
printf("修改完毕");
}
int main(void)
{
Menushow();
return 0;
}
printf("请输入修改后的信息:\n");
printf("请输入姓名:");
scanf("%s",p->name );
printf("请输入性别(男/女):");
scanf("%s",p->age );
printf("请输入年龄:");
scanf("%d",&p->age);
printf("请输入地址:");
scanf("%s",p->address );
printf("请输入购品牌和型号:");
scanf("%s",p->buytype );
printf("请输入购买的颜色:");
scanf("%s",p->color );
printf("请输入价格:");
scanf("%ld",&p->price );
printf("请输入购买时间:(yyyy-mm-dd):");
scanf("%d-%d-%d",&p->date.year,&p->date.month,&p->date.day);
|
|