#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>
using namespace std;
struct things //物品结构体 编号、名字、朝代、简短介绍、价格
{
int id;
char name[50];
char time[20];
char introduce[300];
double price;
struct things * next;
struct yonghu *yonghu;
} thing1,*pp1;
struct yonghu // 用户结构体 编号、姓名、性别、年龄、密码、电话、邮件、积分
{
int id;
char name[50];
char sex[6];
int age;
char key[12];
char phone[12];
char email[30];
int score;
struct yonghu * next;
struct yhthings * yhthings;
} yonghu1;
struct adm //管理员结构体 编号、姓名、性别、年龄、密码、电话、邮件、积分
{
int id;
char name[50];
char sex[6];
int age;
char key[12];
char phone[12];
int score;
char email[30];
struct yhthings * yhthings;
struct adm * next;
} adm1;
struct yhthings //用户物品结构体 物品编号、物品名称、物品原价格、物品竞拍后价格
{
int id;
int id1;
char name[50];
char time[20];
char yonghu_name[50];
double f_price;
double n_price;
struct yhthings *next;
struct yhthings *follow;
struct yhthings *adm;
} yhthings1;
struct times
{
int sec;
int min;
int hour;
int mday;
int mon;
int year;
int yday;
} time1;
struct paimairen
{
int id;
double price;
struct paimairen *next;
} renyuan1;
struct paimaipin
{
int id;
int id1;
int id2;
char name[50];
char yonghu_name[50];
double f_price;
double n_price;
char introduce[300];
char time[20];
int situ;
struct times tb;
struct times te;
struct paimairen *ren;
struct paimaipin *next;
} pai1;
struct order // 为了用户积分排名
{
struct yonghu *pointer;
struct order *next;
};
struct info //信息结构体
{
int num; // the amount of yonghu or yhthings or things
char key[11];
} in1,in2,in3,in4,in5;
FILE *fp3,*fp1,*fp2,*fp4,*fp5;
struct things * head=NULL,*p1,*p2;
struct yonghu * head_yonghu=NULL;
struct adm * head_adm=NULL;
struct yhthings * head_yhthings=NULL,*yhthingsp,*headc;
struct paimaipin *head_pai=NULL,*paimaipinsp;
void copy_things(struct things *p1,struct things thing1);// 用于复制物品信息 减少代码量
void copy_paimaipin(struct paimaipin *p1,struct paimaipin wupin1);// 用于复制拍卖物品信息 减少代码量
void buy(struct yonghu *p);//竞购自己想要的物品
void checkpai(struct yonghu *p);//查看可以竞购的物品的相关信息
void del_things();//删除用户信息
void del_yhthings();//删除用户物品信息
void del_yonghu();//删除用户信息
void copy_yonghu(struct yonghu *p1,struct yonghu yonghu1);// 用于复制用户信息 减少代码量
void insert_thing(struct things thing1); //物品结构体插入
void file_open(); //用来打开文件和构建链表
void file_close(); //关闭文件
void input_thing(); //物品信息录入
void input_yonghu();//用户录入
void input_yhthings();//用户物品信息录入
void insert_adm(struct adm adm1); //管理员结构体插入
void insert_yhthings1(struct yhthings yhthings1); //将物品信息插入用户
void insert_yhthings2(struct yhthings yhthings1); //将物品信息插入管理员
void insert_paimaipin1(struct paimaipin wupin1); //将拍卖物品结构体插入
void jingpai(struct yonghu *p);//竞拍功能
void jinggou(struct yonghu *p);//竞购物品功能界面
void key(char *key);//以星号形式接受密码并放到地址key上
void key_yonghu();//用户ID与密码验证
void key_adm();//管理员ID与密码验证
int idc(char *id); //id装换 char 到int
void modify_thing_adm();// 管理员修改物品信息
void modify_yonghu(struct yonghu *p1);// 用户修改自己信息
void modify_yonghu_adm();//管理员进入某一用户系统 修改用户信息 如密码
void yonghu_ui(struct yonghu *p);//学生界面
void input_adm(); //管理员录入
void adm_ui_1();//管理员界面1
void adm_ui_2();//管理员界面2
void adm_key();//管理员密码修改
void st_key_yonghu(struct yonghu *p);//用户密码修改
void paimai(struct yonghu *p);//用户拍卖物品
void pairesult(struct yonghu *p);//用户拍卖的物品的结果,并删除用户物品信息
void zuigaojia(struct paimaipin *p,struct yonghu *ppp);//获得竞购的商品结果,并完成用户的物品插入
void skim_thing_kind(); // 根据类别查看物品 管理员功能
void skim_yonghu_score();//按积分查看用户
void skim_yhthings(struct yonghu *p);//查看所有用户物品信息
void pfree_yhthings(struct yonghu *p_yonghu,struct things *p_things,struct yhthings yhthings1);//解锁及释放用户物品内存
void skim_yonghu_score(struct yonghu *p);//查看所有用户积分
void skim_thing_all();//查看所有物品信息
void insert_yonghu(struct yonghu yonghu1); //用户结构体插入
void help();//帮助
void develop();//作者
void file_open() //用来打开文件和构建链表
{
struct things thing1;
struct yonghu yonghu1;
struct yhthings yhthings1;
struct adm adm1;
//struct yhthings *cp;
int a1=0,a2=0,a3=0,a4=0,a5=0;
if((fp1=fopen("things","rb"))==NULL||(fp2=fopen("yhthings","rb"))==NULL||(fp3=fopen("yonghu","rb"))==NULL||(fp4=fopen("adm","rb"))==NULL||(fp5=fopen("paimaiping","rb"))==NULL) //can't open the file
{
if((fp1=fopen("things","wb"))==NULL||(fp2=fopen("yhthings","wb"))==NULL||(fp3=fopen("yonghu","wb"))==NULL||(fp4=fopen("adm","wb"))==NULL||(fp5=fopen("paimaiping","wb"))==NULL)
printf("\n客官,出错了呢,文件打不开了呦~");
exit(0);
}
else // open file successfully
{
fread(&in1,sizeof(struct info),1,fp1);
fread(&in2,sizeof(struct info),1,fp2);
fread(&in3,sizeof(struct info),1,fp3);
fread(&in4,sizeof(struct info),1,fp4);
fread(&in5,sizeof(struct info),1,fp5);
strcpy(in2.key,"00000000");
if(in1.num==0&&in2.num==0) strcpy(in1.key,"123456");
// 创建物品线性表
if(in3.num==0) strcpy(in3.key,"1345");//创建用户线性表
if(in1.num<=0)//没物品数据或者没有初始化
{
fclose(fp1);
in1.num=0;
head=NULL;
}
else
{
a1=in1.num;
in1.num=0;
do
{
fread(&thing1,sizeof(struct things),1,fp1);
insert_thing(thing1);
a1--;
}
while(a1!=0);
fclose(fp1);
}
// 加入管理员结构
if(in4.num<=0)// 没管理员数据或没有初始化
{
fclose(fp4);
in4.num=0;
head_adm=NULL;
}
else
{
a4=in4.num;
in4.num=0;
do
{
fread(&adm1,sizeof(struct adm),1,fp4);
insert_adm(adm1);
a4--;
}
while(a4!=0);
fclose(fp4);
}
// 加入用户结构
if(in3.num<=0)// 没用户数据或没有初始化
{
fclose(fp3);
in3.num=0;
head_yonghu=NULL;
}
else
{
a3=in3.num;
in3.num=0;
do
{
fread(&yonghu1,sizeof(struct yonghu),1,fp3);
insert_yonghu(yonghu1);
a3--;
}
while(a3!=0);
fclose(fp3);
}
// 加入用户物品结构
if(in2.num<=0)// 没用户物品数据或者没有初始化
{
fclose(fp2);
in2.num=0;
head_yhthings=NULL;
}
else
{
a2=in2.num;
in2.num=0;
do
{
fread(&yhthings1,sizeof(struct yhthings),1,fp2);
insert_yhthings1(yhthings1);
insert_yhthings2(yhthings1);
a2--;
}
while(a2!=0);
fclose(fp2);
}
// 加入拍卖物品结构
if(in5.num<=0||head_pai==NULL)// 没拍卖物品数据或者没有初始化