本文主要是介绍C/C++NBA球星数据,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
结构体:C 版本
#include <stdio.h>#include <windows.h> //定义 球员 结构体struct Startman {char name[15] ; // 球员姓名char team[15] ; // 所属球队int sumcore ; // 生涯累计得分int maxcore ; // 最高得分int count ; // 生涯参赛场次int number ; // 号码char jiaol[15] ; // 教练double avgitem ; // 平均分};//定义全局 球员 数组struct Startman startmanList [100];//定义全局 球员 数组栈指针int startmanCount = 0;//定义 用户 结构体struct User {char username[15] ; // 用户名char password[15] ; // 密码};//定义全局 用户 数组struct User userList [100];//定义全局 用户 数组栈指针int userCount = 0;//球员 读入文件void readStartman ();//球员 写入文件void writeStartman ();//球员 添加记录void addStartman ();//球员 删除记录void delStartman ();//球员 根据下标删除int delStartmanByIndex (int index);//球员 修改记录void modStartman ();//球员 查找记录void findStartman (int all);//球员 排序void sortStartman ();//交换void exchangeStartman (int i ,int j);//存在判断函数int getOneStartman (const char *name,char *s);//用户 读入文件void readUser ();//用户 写入文件void writeUser ();//用户 添加记录void addUser ();//用户 删除记录void delUser ();//用户 根据下标删除int delUserByIndex (int index);//用户 修改记录void modUser ();//用户 查找记录void findUser (int all);//用户 排序void sortUser ();//交换void exchangeUser (int i ,int j);//存在判断函数int getOneUser (const char *name,char *s);void modUserInfo ();//菜单void login();void regist();struct User loginUser;void menuUser ();int loginStatus = 0;//意义:0 未登录// 主函数int main(){//读取数据readStartman ();//读取球员readUser ();//读取用户while(1){printf("*---------------------------------------------*\n*------------1:登陆\n*------------2:注册\n*---------------------------------------------*\n请输入选择:"); int logout=0; //返回上一级标志int select =0;scanf("%d",&select);if(select!=2){login();}else{regist();}int choice;if(loginStatus == 1)while(logout==0){ menuUser ();scanf("%d",&choice);switch(choice){case 1 :addStartman ();//添加球员break;case 2 :findStartman (1);//查找球员delStartman ();//删除球员break;case 3 :findStartman (1);//查找球员modStartman ();//修改球员break;case 4 :findStartman (0);//查找球员break;case 5 :sortStartman ();//排序球员break;case 6 :findUser (0);//查找用户break;case 7 :sortUser ();//排序用户break;case 0:printf("\n\n\n\t\t\t感谢使用\n\n\n"); exit(0);case -1:printf("\n"); logout =1;loginStatus = 0;break;case -2:modUserInfo ();//修改个人信息break;default :getchar();printf("\n\n\n\t提示:没有这个选项!请重新输入!\n\n\n\n"); system("pause");break;}} }return 0;}void login(){int i;while(loginStatus==0){char username[20],password[20];printf("请输入账号:"); scanf("%s",username);printf("请输入密码:"); scanf("%s",password);// 用户 登录if(loginStatus==0){for(i=0;i < userCount ;i++){if(strcmp(userList [i].username,username)==0 && strcmp( userList [i].password,password)==0){loginUser = userList [i];loginStatus = 1;break;}}}//判断登录情况if(loginStatus == 0){printf("\n用户名密码错误请重新登录!\n\n"); } else{printf("\n登录成功!\n\n"); ;}}}void regist(){int flag = 0;//注册状态 0 失败 ,1 成功while(flag ==0){printf("*---------------------------------------------*\n*------------0:返回 \n"); printf("*------------1:注册用户 \n"); printf("*---------------------------------------------*\n请输入选择:"); int select = 0;scanf("%d",&select);;if(select == 0){flag = 1;//返回} else{char username[20],password[20];printf("请输入账号:"); scanf("%s",username);;printf("请输入密码:"); scanf("%s",password);if( select == 1 ){ //注册用户if( getOneUser ("username",username)>=0) { //根据用户名查找用户是否存在printf("\n用户名已存在!\n\n"); }else{ //不存在则成功注册并且填写剩余属性strcpy( userList [userCount].username,username);strcpy(userList [userCount].password,password);loginUser = userList [userCount];userCount ++;loginStatus = 1;writeUser ();flag = 1;}}if(flag == 1)printf("注册成功\n\n"); elseprintf("注册失败!\n\n"); }}}//球员 是否存在判断
int getOneStartman (const char *name,char *s){int res = -1,i;for( i = 0;i < startmanCount ;i++){if( strcmp(name,"name")==0 && strcmp(s, startmanList [i]. name )==0){res = i;break;}}return res;
}
//球员 读入文件
void readStartman (){FILE *fp = NULL;if (NULL == (fp = fopen("Startman.txt", "r")))//读打开{return;}int i=0;//从文件读取数据while (fscanf(fp, "%s%s%d%d%d%d%s%lf",startmanList[i].name ,startmanList[i].team ,&startmanList[i].sumcore ,&startmanList[i].maxcore ,&startmanList[i].count ,&startmanList[i].number ,startmanList[i].jiaol ,&startmanList[i].avgitem ) != EOF)//读取{i++;}//记录总数startmanCount = i;fclose(fp);
}//球员 写入文件
void writeStartman (){FILE *fp = NULL;int i;fp = fopen("Startman.txt", "w+");for( i = 0;i< startmanCount ;i++){fprintf(fp,"%s %s %d %d %d %d %s %lf\n",startmanList[i].name ,startmanList[i].team ,startmanList[i].sumcore ,startmanList[i].maxcore ,startmanList[i].count ,startmanList[i].number ,startmanList[i].jiaol ,startmanList[i].avgitem );}fclose(fp);
}//球员 添加记录
void addStartman (){char selectYNFlag = 'y';while(selectYNFlag == 'y' || selectYNFlag == 'Y' ){printf("\n"); printf("请输入球员姓名 :"); char name[15]; scanf("%s",name);strcpy(startmanList [ startmanCount ] . name,name);//检索Startman 不重复int getOneStartmanname = getOneStartman ("name",startmanList [ startmanCount ] . name);if( getOneStartmanname >=0){//检索不为空printf("球员姓名已存在!\n"); break;}printf("请输入所属球队 :"); char team[15]; scanf("%s",team);strcpy(startmanList [ startmanCount ] . team,team);printf("请输入生涯累计得分 :"); int sumcore; scanf("%d",&sumcore);startmanList [ startmanCount ] . sumcore = sumcore ;printf("请输入最高得分 :"); int maxcore; scanf("%d",&maxcore);startmanList [ startmanCount ] . maxcore = maxcore ;printf("请输入生涯参赛场次 :"); int count; scanf("%d",&count);startmanList [ startmanCount ] . count = count ;printf("请输入号码 :"); int number; scanf("%d",&number);startmanList [ startmanCount ] . number = number ;printf("请输入教练 :"); char jiaol[15]; scanf("%s",jiaol);strcpy(startmanList [ startmanCount ] . jiaol,jiaol);double avgitem = sumcore/count*1.0 ; startmanList [ startmanCount ] . avgitem = avgitem ;//startmanCount 是全局变量startmanCount ++;printf("\n是否继续录入?(y/n)"); getchar();scanf("%c",&selectYNFlag);}writeStartman ( );printf("\n*****************************\n"); printf("录入完成\n"); printf("*****************************\n"); }//球员 删除
void delStartman (){printf("请输入您要删除的 球员 序号(输入-1退出):"); int index;scanf("%d",&index);if(index >= 0){int res = delStartmanByIndex (index);if(res){printf("删除成功!\n\n"); writeStartman ();}else{printf("删除失败!\n\n"); }}}//球员 根据下标删除
int delStartmanByIndex (int index){if(index >= startmanCount || index < 0){return 0;}//开始删除!int i;for(i = index; i < startmanCount - 1 ; i++){//元素全部往前移一位。startmanList [i] = startmanList [i+1];}//最后令栈的长度减一startmanCount = startmanCount - 1;return 1;
}//球员 修改
void modStartman (){printf("请输入您要修改的球员 序号(输入-1退出):"); int indexOfMod = -1;scanf("%d",&indexOfMod);if(indexOfMod >= 0 && indexOfMod < startmanCount ){//开始修改printf("请输入球员姓名 :"); char name[15];scanf("%s",name);if(strcmp(startmanList [indexOfMod] . name,name) != 0 && getOneStartman ("name",name)>=0){//检索不为空printf("球员姓名 已存在!\n"); return;}printf("请输入所属球队 :"); char team[15];scanf("%s",team);printf("请输入生涯累计得分 :"); int sumcore;scanf("%d",&sumcore);printf("请输入最高得分 :"); int maxcore;scanf("%d",&maxcore);printf("请输入生涯参赛场次 :"); int count;scanf("%d",&count);printf("请输入号码 :"); int number;scanf("%d",&number);printf("请输入教练 :"); char jiaol[15];scanf("%s",jiaol);printf("请输入平均分 :"); double avgitem;scanf("%lf",&avgitem);//输入完毕,赋值strcpy(startmanList [ indexOfMod ] . name,name);strcpy(startmanList [ indexOfMod ] . team,team);startmanList [ indexOfMod ] . sumcore = sumcore ;startmanList [ indexOfMod ] . maxcore = maxcore ;startmanList [ indexOfMod ] . count = count ;startmanList [ indexOfMod ] . number = number ;strcpy(startmanList [ indexOfMod ] . jiaol,jiaol);startmanList [ indexOfMod ] . avgitem = avgitem ;printf("修改成功!\n"); writeStartman ();}else{printf("输入错误!\n"); }}
//球员 查找 如果all=1:查询全部 否则按条件查询
void findStartman (int all){int select = 0;char conCharArr[40];double conNum1,conNum2;while(1){printf("\n%-5s%-15s%-15s%-10s%-10s%-10s%-10s%-15s%-12s\n\n","序号" ,"球员姓名","所属球队","生涯累计得分","最高得分","生涯参赛场次","号码","教练","平均分" );if( startmanList ){//用于统计信息所用int count = 0,i;int sumcoreSum=0;for (i = 0;i < startmanCount ; i++){if(select == 0|| select == 1 && strstr(startmanList [i]. name,conCharArr) //根据球员姓名,模糊查询|| select == 2 && strstr(startmanList [i]. team,conCharArr) //根据所属球队,模糊查询|| select == 3 && startmanList [i]. sumcore>= conNum1&&startmanList [i]. sumcore<=conNum2 //根据生涯累计得分 范围查询|| select == 4 && startmanList [i]. maxcore>= conNum1&&startmanList [i]. maxcore<=conNum2 //根据最高得分 范围查询|| select == 5 && startmanList [i]. number>= conNum1&&startmanList [i]. number<=conNum2 //根据号码 范围查询){printf("%-5d%-15s%-15s%-10d%-10d%-10d%-10d%-15s%-12lf \n\n",i,startmanList [i] . name,startmanList [i] . team,startmanList [i] . sumcore,startmanList [i] . maxcore,startmanList [i] . count,startmanList [i] . number,startmanList [i] . jiaol,startmanList [i] . avgitem);//用于统计信息所用sumcoreSum += startmanList [i].sumcore;count++;}else{delStartmanByIndex(i--);//删掉}}printf("共%d条结果\n",count); printf("-----------------------------------------------------------------------------------------------------\n"); printf("【生涯累计得分】平均:%.2lf\n" ,count!=0?sumcoreSum * 1.0 / count :0);printf("\n"); }else{printf("\n【无记录!】\n\n"); }//如果参数all为1,则表示列出所有就退出if(all == 1)break;//进入过滤。printf("【筛选器:你可以在以上结果的基础上,进行以下条件筛选】\n"); printf("0:退出\n"); printf("1:按 球员姓名 筛选\n"); printf("2:按 所属球队 筛选\n"); printf("3:按 生涯累计得分 筛选\n"); printf("4:按 最高得分 筛选\n"); printf("5:按 号码 筛选\n"); printf("请输入选择:"); scanf("%d",&select);if(select>0){if(0 ||select==1 ||select==2 ){printf("请输入筛选条件:"); scanf("%s",conCharArr);}else if(0 ||select==3 ||select==4 ||select==5 ){printf("请输入筛选范围m,n,用空格隔开(m ≤X ≤n):"); scanf("%lf",&conNum1);scanf("%lf",&conNum2);}}else{break;}}readStartman();//从新读取数据。
}//球员 排序
void sortStartman (){int select,i,j;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("请输入选择:"); scanf("%d",&select);for( i = startmanCount -1;i>0;i--){for( j = 0;j < i;j++){if( 0|| select == 1 && strcmp(startmanList [j]. name , startmanList [j+1]. name)>0|| select == 2 && strcmp(startmanList [j]. team , startmanList [j+1]. team)>0|| select == 3 && startmanList [j]. sumcore - startmanList [j+1]. sumcore > 0|| select == 4 && startmanList [j]. maxcore - startmanList [j+1]. maxcore > 0|| select == 5 && startmanList [j]. count - startmanList [j+1]. count > 0|| select == 6 && startmanList [j]. number - startmanList [j+1]. number > 0|| select == 7 && strcmp(startmanList [j]. jiaol , startmanList [j+1]. jiaol)>0|| select == 8 && startmanList [j]. avgitem - startmanList [j+1]. avgitem > 0){exchangeStartman (j,j+1);}}}findStartman (1);writeStartman ();
}
//球员 交换
void exchangeStartman (int i,int j){struct Startman startman = startmanList [i];startmanList [i] = startmanList [j];startmanList [j] = startman ;
}
void modUserInfo (){printf("\n====您的个人信息如下====\n"); printf("用户名:%s\n",loginUser.username); printf("密码:%s\n",loginUser.password); printf("==========================\n1,修改个人信息\n2,返回上一级\n请选择:"); int n,i;scanf("%d",&n);if (n == 1) {for( i = 0;i < userCount ; i++){if(strcmp(userList [i].username,loginUser .username)==0){printf("请输入密码 :"); scanf("%s",loginUser.password);userList [ i ] = loginUser;writeUser ();printf("修改成功!\n"); break;}}}
}
//用户 是否存在判断
int getOneUser (const char *name,char *s){int res = -1,i;for( i = 0;i < userCount ;i++){if( strcmp(name,"username")==0 && strcmp(s, userList [i]. username )==0){res = i;break;}}return res;
}
//用户 读入文件
void readUser (){FILE *fp = NULL;if (NULL == (fp = fopen("User.txt", "r")))//读打开{return;}int i=0;//从文件读取数据while (fscanf(fp, "%s%s",userList[i].username ,userList[i].password ) != EOF)//读取{i++;}//记录总数userCount = i;fclose(fp);
}//用户 写入文件
void writeUser (){FILE *fp = NULL;int i;fp = fopen("User.txt", "w+");for( i = 0;i< userCount ;i++){fprintf(fp,"%s %s\n",userList[i].username ,userList[i].password );}fclose(fp);
}//用户 添加记录
void addUser (){char selectYNFlag = 'y';while(selectYNFlag == 'y' || selectYNFlag == 'Y' ){printf("\n"); printf("请输入用户名 :"); char username[15]; scanf("%s",username);strcpy(userList [ userCount ] . username,username);//检索User 不重复int getOneUserusername = getOneUser ("username",userList [ userCount ] . username);if( getOneUserusername >=0){//检索不为空printf("用户名已存在!\n"); break;}printf("请输入密码 :"); char password[15]; scanf("%s",password);strcpy(userList [ userCount ] . password,password);//userCount 是全局变量userCount ++;printf("\n是否继续录入?(y/n)"); getchar();scanf("%c",&selectYNFlag);}writeUser ( );printf("\n*****************************\n"); printf("录入完成\n"); printf("*****************************\n"); }//用户 删除
void delUser (){printf("请输入您要删除的 用户 序号(输入-1退出):"); int index;scanf("%d",&index);if(index >= 0){int res = delUserByIndex (index);if(res){printf("删除成功!\n\n"); writeUser ();}else{printf("删除失败!\n\n"); }}}//用户 根据下标删除
int delUserByIndex (int index){if(index >= userCount || index < 0){return 0;}//开始删除!int i;for(i = index; i < userCount - 1 ; i++){//元素全部往前移一位。userList [i] = userList [i+1];}//最后令栈的长度减一userCount = userCount - 1;return 1;
}//用户 修改
void modUser (){printf("请输入您要修改的用户 序号(输入-1退出):"); int indexOfMod = -1;scanf("%d",&indexOfMod);if(indexOfMod >= 0 && indexOfMod < userCount ){//开始修改printf("请输入密码 :"); char password[15];scanf("%s",password);//输入完毕,赋值strcpy(userList [ indexOfMod ] . password,password);printf("修改成功!\n"); writeUser ();}else{printf("输入错误!\n"); }}
//用户 查找 如果all=1:查询全部 否则按条件查询
void findUser (int all){int select = 0;char conCharArr[40];double conNum1,conNum2;while(1){printf("\n%-5s%-15s%-15s\n\n","序号" ,"用户名","密码" );if( userList ){//用于统计信息所用int count = 0,i;for (i = 0;i < userCount ; i++){if(select == 0|| select == 1 && strstr(userList [i]. username,conCharArr) //根据用户名,模糊查询){printf("%-5d%-15s%-15s \n\n",i,userList [i] . username,userList [i] . password);//用于统计信息所用count++;}else{delUserByIndex(i--);//删掉}}printf("共%d条结果\n",count); printf("-----------------------------------------------------------------------------------------------------\n"); printf("\n"); }else{printf("\n【无记录!】\n\n"); }//如果参数all为1,则表示列出所有就退出if(all == 1)break;//进入过滤。printf("【筛选器:你可以在以上结果的基础上,进行以下条件筛选】\n"); printf("0:退出\n"); printf("1:按 用户名 筛选\n"); printf("请输入选择:"); scanf("%d",&select);if(select>0){if(0 ||select==1 ){printf("请输入筛选条件:"); scanf("%s",conCharArr);}else if(0 ){printf("请输入筛选范围m,n,用空格隔开(m ≤X ≤n):"); scanf("%lf",&conNum1);scanf("%lf",&conNum2);}}else{break;}}readUser();//从新读取数据。
}//用户 排序
void sortUser (){int select,i,j;printf("1:按 用户名 排序\n"); printf("2:按 密码 排序\n"); printf("请输入选择:"); scanf("%d",&select);for( i = userCount -1;i>0;i--){for( j = 0;j < i;j++){if( 0|| select == 1 && strcmp(userList [j]. username , userList [j+1]. username)>0|| select == 2 && strcmp(userList [j]. password , userList [j+1]. password)>0){exchangeUser (j,j+1);}}}findUser (1);writeUser ();
}
//用户 交换
void exchangeUser (int i,int j){struct User user = userList [i];userList [i] = userList [j];userList [j] = user ;
}void menuUser (){//菜单printf("*------------------主菜单---------------------*\n"); printf("*-------------1 :添加球员\n"); printf("*-------------2 :删除球员\n"); printf("*-------------3 :修改球员\n"); printf("*-------------4 :查找球员\n"); printf("*-------------5 :排序球员\n"); printf("*-------------6 :查找用户\n"); printf("*-------------7 :排序用户\n"); printf("*-------------0:退出\n"); printf("*------------(-1):登出\n"); printf("*------------(-2):我的\n"); printf("*---------------------------------------------*\n"); printf("请输入选择:"); }
结构体:C++版本
#include <io.h>#include <iostream>#include <windows.h>using namespace std; //定义 球员 结构体struct Startman {char name[15] ; // 球员姓名char team[15] ; // 所属球队int sumcore ; // 生涯累计得分int maxcore ; // 最高得分int count ; // 生涯参赛场次int number ; // 号码char jiaol[15] ; // 教练double avgitem ; // 平均分};//定义全局 球员 数组struct Startman startmanList [100];//定义全局 球员 数组栈指针int startmanCount = 0;//定义 用户 结构体struct User {char username[15] ; // 用户名char password[15] ; // 密码};//定义全局 用户 数组struct User userList [100];//定义全局 用户 数组栈指针int userCount = 0;//球员 读入文件void readStartman ();//球员 写入文件void writeStartman ();//球员 添加记录void addStartman ();//球员 删除记录void delStartman ();//球员 根据下标删除int delStartmanByIndex (int index);//球员 修改记录void modStartman ();//球员 查找记录void findStartman (int all);//球员 排序void sortStartman ();//交换void exchangeStartman (int i ,int j);//存在判断函数int getOneStartman (const char *name,char *s);//用户 读入文件void readUser ();//用户 写入文件void writeUser ();//用户 添加记录void addUser ();//用户 删除记录void delUser ();//用户 根据下标删除int delUserByIndex (int index);//用户 修改记录void modUser ();//用户 查找记录void findUser (int all);//用户 排序void sortUser ();//交换void exchangeUser (int i ,int j);//存在判断函数int getOneUser (const char *name,char *s);void modUserInfo ();//菜单void login();void regist();struct User loginUser;void menuUser ();int loginStatus = 0;//意义:0 未登录// 主函数int main(){//读取数据readStartman ();//读取球员readUser ();//读取用户while(1){cout<<"*---------------------------------------------*\n*------------1:登陆\n*------------2:注册\n*---------------------------------------------*\n请输入选择:";int logout=0; //返回上一级标志int select =0;cin>>select;if(select!=2){login();}else{regist();}int choice;if(loginStatus == 1)while(logout==0){ menuUser ();cin>>choice;switch(choice){case 1 :addStartman ();//添加球员break;case 2 :findStartman (1);//查找球员delStartman ();//删除球员break;case 3 :findStartman (1);//查找球员modStartman ();//修改球员break;case 4 :findStartman (0);//查找球员break;case 5 :sortStartman ();//排序球员break;case 6 :findUser (0);//查找用户break;case 7 :sortUser ();//排序用户break;case 0:cout<<"\n\n\n\t\t\t感谢使用\n\n\n";exit(0);case -1:cout<<"\n";logout =1;loginStatus = 0;break;case -2:modUserInfo ();//修改个人信息break;default :getchar();cout<<"\n\n\n\t提示:没有这个选项!请重新输入!\n\n\n\n";system("pause");break;}} }return 0;}void login(){int i;while(loginStatus==0){char username[20],password[20];cout<<"请输入账号:";cin>>username;cout<<"请输入密码:";cin>>password;// 用户 登录if(loginStatus==0){for(i=0;i < userCount ;i++){if(strcmp(userList [i].username,username)==0 && strcmp( userList [i].password,password)==0){loginUser = userList [i];loginStatus = 1;break;}}}//判断登录情况if(loginStatus == 0){cout<<"\n用户名密码错误请重新登录!\n\n";} else{cout<<"\n登录成功!\n\n";;}}}void regist(){int flag = 0;//注册状态 0 失败 ,1 成功while(flag ==0){cout<<"*---------------------------------------------*\n*------------0:返回 \n";cout<<"*------------1:注册用户 \n";cout<<"*---------------------------------------------*\n请输入选择:";int select = 0;cin>>select;;if(select == 0){flag = 1;//返回} else{char username[20],password[20];cout<<"请输入账号:";cin>>username;;cout<<"请输入密码:";cin>>password;if( select == 1 ){ //注册用户if( getOneUser ("username",username)>=0) { //根据用户名查找用户是否存在cout<<"\n用户名已存在!\n\n";}else{ //不存在则成功注册并且填写剩余属性strcpy( userList [userCount].username,username);strcpy(userList [userCount].password,password);loginUser = userList [userCount];userCount ++;loginStatus = 1;writeUser ();flag = 1;}}if(flag == 1)cout<<"注册成功\n\n";elsecout<<"注册失败!\n\n";}}}//球员 是否存在判断
int getOneStartman (const char *name,char *s){int res = -1,i;for( i = 0;i < startmanCount ;i++){if( strcmp(name,"name")==0 && strcmp(s, startmanList [i]. name )==0){res = i;break;}}return res;
}
//球员 读入文件
void readStartman (){FILE *fp = NULL;if (NULL == (fp = fopen("Startman.txt", "r")))//读打开{return;}int i=0;//从文件读取数据while (fscanf(fp, "%s%s%d%d%d%d%s%lf",startmanList[i].name ,startmanList[i].team ,&startmanList[i].sumcore ,&startmanList[i].maxcore ,&startmanList[i].count ,&startmanList[i].number ,startmanList[i].jiaol ,&startmanList[i].avgitem ) != EOF)//读取{i++;}//记录总数startmanCount = i;fclose(fp);
}//球员 写入文件
void writeStartman (){FILE *fp = NULL;int i;fp = fopen("Startman.txt", "w+");for( i = 0;i< startmanCount ;i++){fprintf(fp,"%s %s %d %d %d %d %s %lf\n",startmanList[i].name ,startmanList[i].team ,startmanList[i].sumcore ,startmanList[i].maxcore ,startmanList[i].count ,startmanList[i].number ,startmanList[i].jiaol ,startmanList[i].avgitem );}fclose(fp);
}//球员 添加记录
void addStartman (){char selectYNFlag = 'y';while(selectYNFlag == 'y' || selectYNFlag == 'Y' ){cout<<"\n";cout<<"请输入球员姓名 :";char name[15]; cin>>name;strcpy(startmanList [ startmanCount ] . name,name);//检索Startman 不重复int getOneStartmanname = getOneStartman ("name",startmanList [ startmanCount ] . name);if( getOneStartmanname >=0){//检索不为空cout<<"球员姓名已存在!\n";break;}cout<<"请输入所属球队 :";char team[15]; cin>>team;strcpy(startmanList [ startmanCount ] . team,team);cout<<"请输入生涯累计得分 :";int sumcore; cin>>sumcore;startmanList [ startmanCount ] . sumcore = sumcore ;cout<<"请输入最高得分 :";int maxcore; cin>>maxcore;startmanList [ startmanCount ] . maxcore = maxcore ;cout<<"请输入生涯参赛场次 :";int count; cin>>count;startmanList [ startmanCount ] . count = count ;cout<<"请输入号码 :";int number; cin>>number;startmanList [ startmanCount ] . number = number ;cout<<"请输入教练 :";char jiaol[15]; cin>>jiaol;strcpy(startmanList [ startmanCount ] . jiaol,jiaol);double avgitem = sumcore/count*1.0 ; startmanList [ startmanCount ] . avgitem = avgitem ;//startmanCount 是全局变量startmanCount ++;cout<<"\n是否继续录入?(y/n)";getchar();cin>>selectYNFlag;}writeStartman ( );cout<<"\n*****************************\n";cout<<"录入完成\n";cout<<"*****************************\n";}//球员 删除
void delStartman (){cout<<"请输入您要删除的 球员 序号(输入-1退出):";int index;cin>>index;if(index >= 0){int res = delStartmanByIndex (index);if(res){cout<<"删除成功!\n\n";writeStartman ();}else{cout<<"删除失败!\n\n";}}}//球员 根据下标删除
int delStartmanByIndex (int index){if(index >= startmanCount || index < 0){return 0;}//开始删除!int i;for(i = index; i < startmanCount - 1 ; i++){//元素全部往前移一位。startmanList [i] = startmanList [i+1];}//最后令栈的长度减一startmanCount = startmanCount - 1;return 1;
}//球员 修改
void modStartman (){cout<<"请输入您要修改的球员 序号(输入-1退出):";int indexOfMod = -1;cin>>indexOfMod;if(indexOfMod >= 0 && indexOfMod < startmanCount ){//开始修改cout<<"请输入球员姓名 :";char name[15];cin>>name;if(strcmp(startmanList [indexOfMod] . name,name) != 0 && getOneStartman ("name",name)>=0){//检索不为空cout<<"球员姓名 已存在!\n";return;}cout<<"请输入所属球队 :";char team[15];cin>>team;cout<<"请输入生涯累计得分 :";int sumcore;cin>>sumcore;cout<<"请输入最高得分 :";int maxcore;cin>>maxcore;cout<<"请输入生涯参赛场次 :";int count;cin>>count;cout<<"请输入号码 :";int number;cin>>number;cout<<"请输入教练 :";char jiaol[15];cin>>jiaol;cout<<"请输入平均分 :";double avgitem;cin>>avgitem;//输入完毕,赋值strcpy(startmanList [ indexOfMod ] . name,name);strcpy(startmanList [ indexOfMod ] . team,team);startmanList [ indexOfMod ] . sumcore = sumcore ;startmanList [ indexOfMod ] . maxcore = maxcore ;startmanList [ indexOfMod ] . count = count ;startmanList [ indexOfMod ] . number = number ;strcpy(startmanList [ indexOfMod ] . jiaol,jiaol);startmanList [ indexOfMod ] . avgitem = avgitem ;cout<<"修改成功!\n";writeStartman ();}else{cout<<"输入错误!\n";}}
//球员 查找 如果all=1:查询全部 否则按条件查询
void findStartman (int all){int select = 0;char conCharArr[40];double conNum1,conNum2;while(1){printf("\n%-5s%-15s%-15s%-10s%-10s%-10s%-10s%-15s%-12s\n\n","序号" ,"球员姓名","所属球队","生涯累计得分","最高得分","生涯参赛场次","号码","教练","平均分" );if( startmanList ){//用于统计信息所用int count = 0,i;int sumcoreSum=0;for (i = 0;i < startmanCount ; i++){if(select == 0|| select == 1 && strstr(startmanList [i]. name,conCharArr) //根据球员姓名,模糊查询|| select == 2 && strstr(startmanList [i]. team,conCharArr) //根据所属球队,模糊查询|| select == 3 && startmanList [i]. sumcore>= conNum1&&startmanList [i]. sumcore<=conNum2 //根据生涯累计得分 范围查询|| select == 4 && startmanList [i]. maxcore>= conNum1&&startmanList [i]. maxcore<=conNum2 //根据最高得分 范围查询|| select == 5 && startmanList [i]. number>= conNum1&&startmanList [i]. number<=conNum2 //根据号码 范围查询){printf("%-5d%-15s%-15s%-10d%-10d%-10d%-10d%-15s%-12lf \n\n",i,startmanList [i] . name,startmanList [i] . team,startmanList [i] . sumcore,startmanList [i] . maxcore,startmanList [i] . count,startmanList [i] . number,startmanList [i] . jiaol,startmanList [i] . avgitem);//用于统计信息所用sumcoreSum += startmanList [i].sumcore;count++;}else{delStartmanByIndex(i--);//删掉}}cout<<"共" << count <<"条结果\n";cout<<"-----------------------------------------------------------------------------------------------------\n";cout<<"【生涯累计得分】" <<"平均:"<< (count!=0?sumcoreSum*1.0/count:0)<<"\n";cout<<"\n";}else{cout<<"\n【无记录!】\n\n";}//如果参数all为1,则表示列出所有就退出if(all == 1)break;//进入过滤。cout<<"【筛选器:你可以在以上结果的基础上,进行以下条件筛选】\n";cout<<"0:退出\n";cout<<"1:按 球员姓名 筛选\n";cout<<"2:按 所属球队 筛选\n";cout<<"3:按 生涯累计得分 筛选\n";cout<<"4:按 最高得分 筛选\n";cout<<"5:按 号码 筛选\n";cout<<"请输入选择:";cin>>select;if(select>0){if(0 ||select==1 ||select==2 ){cout<<"请输入筛选条件:";cin>>conCharArr;}else if(0 ||select==3 ||select==4 ||select==5 ){cout<<"请输入筛选范围m,n,用空格隔开(m ≤X ≤n):";cin>>conNum1;cin>>conNum2;}}else{break;}}readStartman();//从新读取数据。
}//球员 排序
void sortStartman (){int select,i,j;cout<<"1:按 球员姓名 排序\n";cout<<"2:按 所属球队 排序\n";cout<<"3:按 生涯累计得分 排序\n";cout<<"4:按 最高得分 排序\n";cout<<"5:按 生涯参赛场次 排序\n";cout<<"6:按 号码 排序\n";cout<<"7:按 教练 排序\n";cout<<"8:按 平均分 排序\n";cout<<"请输入选择:";cin>>select;for( i = startmanCount -1;i>0;i--){for( j = 0;j < i;j++){if( 0|| select == 1 && strcmp(startmanList [j]. name , startmanList [j+1]. name)>0|| select == 2 && strcmp(startmanList [j]. team , startmanList [j+1]. team)>0|| select == 3 && startmanList [j]. sumcore - startmanList [j+1]. sumcore > 0|| select == 4 && startmanList [j]. maxcore - startmanList [j+1]. maxcore > 0|| select == 5 && startmanList [j]. count - startmanList [j+1]. count > 0|| select == 6 && startmanList [j]. number - startmanList [j+1]. number > 0|| select == 7 && strcmp(startmanList [j]. jiaol , startmanList [j+1]. jiaol)>0|| select == 8 && startmanList [j]. avgitem - startmanList [j+1]. avgitem > 0){exchangeStartman (j,j+1);}}}findStartman (1);writeStartman ();
}
//球员 交换
void exchangeStartman (int i,int j){struct Startman startman = startmanList [i];startmanList [i] = startmanList [j];startmanList [j] = startman ;
}
void modUserInfo (){cout<<"\n====您的个人信息如下====\n";cout<<"用户名:" << loginUser.username <<"\n";cout<<"密码:" << loginUser.password <<"\n";cout<<"==========================\n1,修改个人信息\n2,返回上一级\n请选择:";int n,i;cin>>n;if (n == 1) {for( i = 0;i < userCount ; i++){if(strcmp(userList [i].username,loginUser .username)==0){cout<<"请输入密码 :";cin>>loginUser.password;userList [ i ] = loginUser;writeUser ();cout<<"修改成功!\n";break;}}}
}
//用户 是否存在判断
int getOneUser (const char *name,char *s){int res = -1,i;for( i = 0;i < userCount ;i++){if( strcmp(name,"username")==0 && strcmp(s, userList [i]. username )==0){res = i;break;}}return res;
}
//用户 读入文件
void readUser (){FILE *fp = NULL;if (NULL == (fp = fopen("User.txt", "r")))//读打开{return;}int i=0;//从文件读取数据while (fscanf(fp, "%s%s",userList[i].username ,userList[i].password ) != EOF)//读取{i++;}//记录总数userCount = i;fclose(fp);
}//用户 写入文件
void writeUser (){FILE *fp = NULL;int i;fp = fopen("User.txt", "w+");for( i = 0;i< userCount ;i++){fprintf(fp,"%s %s\n",userList[i].username ,userList[i].password );}fclose(fp);
}//用户 添加记录
void addUser (){char selectYNFlag = 'y';while(selectYNFlag == 'y' || selectYNFlag == 'Y' ){cout<<"\n";cout<<"请输入用户名 :";char username[15]; cin>>username;strcpy(userList [ userCount ] . username,username);//检索User 不重复int getOneUserusername = getOneUser ("username",userList [ userCount ] . username);if( getOneUserusername >=0){//检索不为空cout<<"用户名已存在!\n";break;}cout<<"请输入密码 :";char password[15]; cin>>password;strcpy(userList [ userCount ] . password,password);//userCount 是全局变量userCount ++;cout<<"\n是否继续录入?(y/n)";getchar();cin>>selectYNFlag;}writeUser ( );cout<<"\n*****************************\n";cout<<"录入完成\n";cout<<"*****************************\n";}//用户 删除
void delUser (){cout<<"请输入您要删除的 用户 序号(输入-1退出):";int index;cin>>index;if(index >= 0){int res = delUserByIndex (index);if(res){cout<<"删除成功!\n\n";writeUser ();}else{cout<<"删除失败!\n\n";}}}//用户 根据下标删除
int delUserByIndex (int index){if(index >= userCount || index < 0){return 0;}//开始删除!int i;for(i = index; i < userCount - 1 ; i++){//元素全部往前移一位。userList [i] = userList [i+1];}//最后令栈的长度减一userCount = userCount - 1;return 1;
}//用户 修改
void modUser (){cout<<"请输入您要修改的用户 序号(输入-1退出):";int indexOfMod = -1;cin>>indexOfMod;if(indexOfMod >= 0 && indexOfMod < userCount ){//开始修改cout<<"请输入密码 :";char password[15];cin>>password;//输入完毕,赋值strcpy(userList [ indexOfMod ] . password,password);cout<<"修改成功!\n";writeUser ();}else{cout<<"输入错误!\n";}}
//用户 查找 如果all=1:查询全部 否则按条件查询
void findUser (int all){int select = 0;char conCharArr[40];double conNum1,conNum2;while(1){printf("\n%-5s%-15s%-15s\n\n","序号" ,"用户名","密码" );if( userList ){//用于统计信息所用int count = 0,i;for (i = 0;i < userCount ; i++){if(select == 0|| select == 1 && strstr(userList [i]. username,conCharArr) //根据用户名,模糊查询){printf("%-5d%-15s%-15s \n\n",i,userList [i] . username,userList [i] . password);//用于统计信息所用count++;}else{delUserByIndex(i--);//删掉}}cout<<"共" << count <<"条结果\n";cout<<"-----------------------------------------------------------------------------------------------------\n";cout<<"\n";}else{cout<<"\n【无记录!】\n\n";}//如果参数all为1,则表示列出所有就退出if(all == 1)break;//进入过滤。cout<<"【筛选器:你可以在以上结果的基础上,进行以下条件筛选】\n";cout<<"0:退出\n";cout<<"1:按 用户名 筛选\n";cout<<"请输入选择:";cin>>select;if(select>0){if(0 ||select==1 ){cout<<"请输入筛选条件:";cin>>conCharArr;}else if(0 ){cout<<"请输入筛选范围m,n,用空格隔开(m ≤X ≤n):";cin>>conNum1;cin>>conNum2;}}else{break;}}readUser();//从新读取数据。
}//用户 排序
void sortUser (){int select,i,j;cout<<"1:按 用户名 排序\n";cout<<"2:按 密码 排序\n";cout<<"请输入选择:";cin>>select;for( i = userCount -1;i>0;i--){for( j = 0;j < i;j++){if( 0|| select == 1 && strcmp(userList [j]. username , userList [j+1]. username)>0|| select == 2 && strcmp(userList [j]. password , userList [j+1]. password)>0){exchangeUser (j,j+1);}}}findUser (1);writeUser ();
}
//用户 交换
void exchangeUser (int i,int j){struct User user = userList [i];userList [i] = userList [j];userList [j] = user ;
}void menuUser (){//菜单cout<<"*------------------主菜单---------------------*\n";cout<<"*-------------1 :添加球员\n";cout<<"*-------------2 :删除球员\n";cout<<"*-------------3 :修改球员\n";cout<<"*-------------4 :查找球员\n";cout<<"*-------------5 :排序球员\n";cout<<"*-------------6 :查找用户\n";cout<<"*-------------7 :排序用户\n";cout<<"*-------------0:退出\n";cout<<"*------------(-1):登出\n";cout<<"*------------(-2):我的\n";cout<<"*---------------------------------------------*\n";cout<<"请输入选择:";}
链表:C版本
#include <stdio.h>#include <windows.h> //定义 球员 链表struct Startman {char name[15] ; // 球员姓名char team[15] ; // 所属球队int sumcore ; // 生涯累计得分int maxcore ; // 最高得分int count ; // 生涯参赛场次int number ; // 号码char jiaol[15] ; // 教练double avgitem ; // 平均分struct Startman* next;//链式存储};struct Startman *startmanList;//定义全局 球员 指针int startmanCount = 0;//球员 个数记录//定义 用户 链表struct User {char username[15] ; // 用户名char password[15] ; // 密码struct User* next;//链式存储};struct User *userList;//定义全局 用户 指针int userCount = 0;//用户 个数记录//球员 读入文件void readStartman ();//球员 写入文件void writeStartman ();//球员 添加记录void addStartman ();void addOneStartman (struct Startman *startman);//球员 删除记录void delStartman ();//球员 根据下标删除int delStartmanByIndex (int index);//球员 修改记录void modStartman ();//球员 查找记录void findStartman (int all);//球员 排序void sortStartman ();//交换void exchangeStartman (int i ,int j);//存在判断函数struct Startman* getOneStartman (const char *name,char *s);//用户 读入文件void readUser ();//用户 写入文件void writeUser ();//用户 添加记录void addUser ();void addOneUser (struct User *user);//用户 删除记录void delUser ();//用户 根据下标删除int delUserByIndex (int index);//用户 修改记录void modUser ();//用户 查找记录void findUser (int all);//用户 排序void sortUser ();//交换void exchangeUser (int i ,int j);//存在判断函数struct User* getOneUser (const char *name,char *s);void modUserInfo ();//菜单void login();void regist();struct User *loginUser = NULL;void menuUser ();int loginStatus = 0;//意义:0 未登录// 主函数int main(){//读取数据readStartman ();//读取球员readUser ();//读取用户while(1){printf("*---------------------------------------------*\n*------------1:登陆\n*------------2:注册\n*---------------------------------------------*\n请输入选择:"); int logout=0; //返回上一级标志int select =0;scanf("%d",&select);if(select!=2){login();}else{regist();}int choice;if(loginStatus == 1)while(logout==0){ menuUser ();scanf("%d",&choice);switch(choice){case 1 :addStartman ();//添加球员break;case 2 :findStartman (1);//查找球员delStartman ();//删除球员break;case 3 :findStartman (1);//查找球员modStartman ();//修改球员break;case 4 :findStartman (0);//查找球员break;case 5 :sortStartman ();//排序球员break;case 6 :findUser (0);//查找用户break;case 7 :sortUser ();//排序用户break;case 0:printf("\n\n\n\t\t\t感谢使用\n\n\n"); exit(0);case -1:printf("\n"); logout =1;loginStatus = 0;break;case -2:modUserInfo ();//修改个人信息break;default :getchar();printf("\n\n\n\t提示:没有这个选项!请重新输入!\n\n\n\n"); system("pause");break;}} }return 0;}void login(){int i;while(loginStatus==0){char username[20],password[20];printf("请输入账号:"); scanf("%s",username);printf("请输入密码:"); scanf("%s",password);// 用户 登录if(loginStatus==0){struct User *user = userList;while(user){if(strcmp(username,user ->username)==0){if(strcmp(password,user ->password)==0){loginUser = user;loginStatus = 1;break;}}user = user ->next;}}//判断登录情况if(loginStatus == 0){printf("\n用户名密码错误请重新登录!\n\n"); } else{printf("\n登录成功!\n\n"); ;}}}void regist(){int flag = 0;//注册状态 0 失败 ,1 成功while(flag ==0){printf("*---------------------------------------------*\n*------------0:返回 \n"); printf("*------------1:注册用户 \n"); printf("*---------------------------------------------*\n请输入选择:"); int select = 0;scanf("%d",&select);;if(select == 0){flag = 1;//返回} else{char username[20],password[20];printf("请输入账号:"); scanf("%s",username);;printf("请输入密码:"); scanf("%s",password);if( select == 1 ){if( getOneUser ("username",username)!=NULL) { //根据用户名查找printf("\n用户名已存在!\n\n"); }else{struct User *user = (struct User*)malloc(sizeof(struct User));strcpy( user ->username,username);strcpy( user ->password,password);user ->next = NULL;loginUser = user;addOneUser (user);loginStatus = 1;writeUser ();flag = 1;}}if(flag == 1)printf("注册成功\n\n"); elseprintf("注册失败!\n\n"); }}}//是否存在判断struct Startman *getOneStartman (const char *name,char *s){struct Startman *head = startmanList;while(head){if( strcmp(name,"name")==0 && strcmp(s, head->name )==0){return head;}head = head->next;}return NULL;}//球员 读入文件
void readStartman (){FILE *fp = NULL;if (NULL == (fp = fopen("Startman.txt", "r")))//读打开{//文件不存在,不读取return;}int i=0;//从文件读取数据startmanList = NULL;struct Startman *tail = startmanList;while (1)//读取{//给节点分配空间struct Startman *p=(struct Startman*)malloc(sizeof(struct Startman));//读取数据到pif(fscanf(fp, "%s%s%d%d%d%d%s%lf",p->name ,p->team ,&p->sumcore ,&p->maxcore ,&p->count ,&p->number ,p->jiaol ,&p->avgitem ) == EOF) {break;}p->next=NULL;//指针为空则赋值。if (startmanList == NULL){startmanList=p;tail=p;}else {tail->next=p;tail=p;}i++;}//记录总数startmanCount = i;fclose(fp);
}
//球员 写入文件
void writeStartman (){//打开文件FILE *fp = NULL;fp = fopen("Startman.txt", "w+");//定义指针struct Startman *p = startmanList;//写入while(p){fprintf(fp,"%s %s %d %d %d %d %s %lf\n",p->name ,p->team ,p->sumcore ,p->maxcore ,p->count ,p->number ,p->jiaol ,p->avgitem );p=p->next;}fclose(fp);
}
//球员 添加记录
void addStartman (){char selectYNFlag = 'y';while(selectYNFlag == 'y' || selectYNFlag == 'Y' ){printf("\n"); struct Startman *tempValue = (struct Startman*)malloc(sizeof(struct Startman)); //必须重新分配地址空间。printf("请输入球员姓名 :"); char name[15]; scanf("%s",name);strcpy(tempValue->name,name);struct Startman* onename = getOneStartman ("name",tempValue->name);if(onename !=NULL){//检索不为空printf("球员姓名已存在!\n"); break;}printf("请输入所属球队 :"); char team[15]; scanf("%s",team);strcpy(tempValue->team,team);printf("请输入生涯累计得分 :"); int sumcore; scanf("%d",&sumcore);tempValue->sumcore = sumcore ;printf("请输入最高得分 :"); int maxcore; scanf("%d",&maxcore);tempValue->maxcore = maxcore ;printf("请输入生涯参赛场次 :"); int count; scanf("%d",&count);tempValue->count = count ;printf("请输入号码 :"); int number; scanf("%d",&number);tempValue->number = number ;printf("请输入教练 :"); char jiaol[15]; scanf("%s",jiaol);strcpy(tempValue->jiaol,jiaol);double avgitem = sumcore/count*1.0 ; tempValue->avgitem = avgitem ;//TODO//加入链表tempValue->next = NULL;addOneStartman (tempValue);printf("\n是否继续录入?(y/n)"); getchar();scanf("%c",&selectYNFlag);}writeStartman ( );printf("\n*****************************\n"); printf("录入完成\n"); printf("*****************************\n"); }
void addOneStartman (struct Startman *temp){//采用头插法if(startmanList == NULL){startmanList = temp;}else{temp->next = startmanList;startmanList = temp;}startmanCount ++;
}
//球员 删除
void delStartman (){printf("请输入您要删除的 球员 序号(输入-1退出):"); int index;scanf("%d",&index);if(index >= 0){int res = delStartmanByIndex (index);if(res){printf("删除成功!\n\n"); writeStartman ();}else{printf("删除失败!\n\n"); }}
}
//球员 根据下标删除
int delStartmanByIndex (int index){if(index > startmanCount || index < 1){return 0;//删除失败 ,数量没那么多}//开始删除!struct Startman *p = (struct Startman*)malloc(sizeof(struct Startman));struct Startman *q = startmanList;p->next = startmanList;if(index == 1){startmanList = startmanList ->next;}else{int i;for(i = 0;i < index-1 ; i++){p = p->next;q = q->next;}p->next = q->next;}startmanCount = startmanCount - 1;return 1;
}
//球员 修改
void modStartman (){printf("请输入您要修改的球员 序号(输入-1退出):"); int indexOfMod = -1,i;scanf("%d",&indexOfMod);if(indexOfMod > 0 && indexOfMod <= startmanCount ){//开始修改struct Startman *temp = startmanList ;for( i = 0;i < indexOfMod-1;i++){temp=temp->next;}printf("请输入球员姓名 :"); char name[15];scanf("%s",name);if(strcmp(temp->name,name) != 0 && getOneStartman ("name",name)!=NULL){//检索不为空printf("球员姓名 已存在!\n"); return;}printf("请输入所属球队 :"); char team[15];scanf("%s",team);printf("请输入生涯累计得分 :"); int sumcore;scanf("%d",&sumcore);printf("请输入最高得分 :"); int maxcore;scanf("%d",&maxcore);printf("请输入生涯参赛场次 :"); int count;scanf("%d",&count);printf("请输入号码 :"); int number;scanf("%d",&number);printf("请输入教练 :"); char jiaol[15];scanf("%s",jiaol);printf("请输入平均分 :"); double avgitem;scanf("%lf",&avgitem);//输入完毕,赋值strcpy(temp-> name,name);strcpy(temp-> team,team);temp-> sumcore = sumcore ;temp-> maxcore = maxcore ;temp-> count = count ;temp-> number = number ;strcpy(temp-> jiaol,jiaol);temp-> avgitem = avgitem ;printf("修改成功!\n"); writeStartman ();}else{printf("输入错误!\n"); }
}
//球员 查找 如果all=1:查询全部 否则按条件查询
void findStartman (int all){int select = 0;char conCharArr[40];double conNum1,conNum2;while(1){printf("\n%-5s%-15s%-15s%-10s%-10s%-10s%-10s%-15s%-12s\n\n","序号" ,"球员姓名","所属球队","生涯累计得分","最高得分","生涯参赛场次","号码","教练","平均分" );int i=1,count = 0;if( startmanList ){//用于统计信息所用int sumcoreSum=0;struct Startman *t = startmanList;while(t){int delFlag = 0;if(select == 0|| select == 1 && strstr(t->name,conCharArr) //根据球员姓名,模糊查询|| select == 2 && strstr(t->team,conCharArr) //根据所属球队,模糊查询|| select == 3 && t->sumcore >= conNum1 && t->sumcore<=conNum2 //根据生涯累计得分 范围查询|| select == 4 && t->maxcore >= conNum1 && t->maxcore<=conNum2 //根据最高得分 范围查询|| select == 5 && t->number >= conNum1 && t->number<=conNum2 //根据号码 范围查询){printf("%-5d%-15s%-15s%-10d%-10d%-10d%-10d%-15s%-12lf \n\n",i,t->name,t->team,t->sumcore,t->maxcore,t->count,t->number,t->jiaol,t->avgitem);//用于统计信息所用sumcoreSum += t->sumcore;count++;}else{delFlag = 1;//删掉}t=t->next;if(delFlag){delStartmanByIndex (i--);}i++;}printf("共%d条结果\n",count); printf("-----------------------------------------------------------------------------------------------------\n"); printf("【生涯累计得分】平均:%.2lf\n" ,count!=0?sumcoreSum * 1.0 / count :0);printf("\n"); }else{printf("\n【无记录!】\n\n"); }//如果参数all为1,则表示列出所有就退出if(all == 1)break;//进入过滤。printf("【筛选器:你可以在以上结果的基础上,进行以下条件筛选:】\n"); printf("0:退出\n"); printf("1:按 球员姓名 筛选\n"); printf("2:按 所属球队 筛选\n"); printf("3:按 生涯累计得分 筛选\n"); printf("4:按 最高得分 筛选\n"); printf("5:按 号码 筛选\n"); printf("请输入选择:"); scanf("%d",&select);if(select>0){if(0 ||select==1 ||select==2 ){printf("请输入筛选条件:"); scanf("%s",conCharArr);}else if(0 ||select==3 ||select==4 ||select==5 ){printf("请输入筛选范围m,n,用空格隔开(m ≤X ≤n):"); scanf("%lf",&conNum1);scanf("%lf",&conNum2);}}else{break;}}readStartman();//从新读取数据。
}
//球员 排序
void sortStartman (){int select,i,j;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("请输入选择:"); scanf("%d",&select);struct Startman *list[100];for(i = 0;i< startmanCount;i++){list[i] = startmanList;startmanList = startmanList ->next;}for( i = startmanCount -1;i>0;i--){for( j = 0;j < i;j++){if( 0|| select == 1 && strcmp(list[j]->name , list[j+1]->name)>0|| select == 2 && strcmp(list[j]->team , list[j+1]->team)>0|| select == 3 && list[j]->sumcore - list[j+1]->sumcore > 0|| select == 4 && list[j]->maxcore - list[j+1]->maxcore > 0|| select == 5 && list[j]->count - list[j+1]->count > 0|| select == 6 && list[j]->number - list[j+1]->number > 0|| select == 7 && strcmp(list[j]->jiaol , list[j+1]->jiaol)>0|| select == 8 && list[j]->avgitem - list[j+1]->avgitem > 0){struct Startman *temp = (struct Startman*)malloc(sizeof(struct Startman));temp = list[j]; //交换位置list[j] = list[j+1];list[j+1] = temp;}}}for(i = 0;i< startmanCount -1;i++){list[i]->next = list[i+1];}list[ startmanCount -1 ]->next = NULL;startmanList = list[0];findStartman (1);writeStartman ();
}
void modUserInfo (){printf("\n====您的个人信息如下====\n"); printf("用户名:%s\n",loginUser ->username); printf("密码:%s\n",loginUser ->password); printf("==========================\n1,修改个人信息\n2,返回上一级\n请选择:"); int n;scanf("%d",&n);if (n == 1) {struct User *h = userList;while(h){if(strcmp(h->username,loginUser ->username)==0){printf("请输入密码 :"); scanf("%s",h->password);loginUser = h;writeUser ();printf("修改成功!\n"); break;}h=h->next;}}
}//是否存在判断struct User *getOneUser (const char *name,char *s){struct User *head = userList;while(head){if( strcmp(name,"username")==0 && strcmp(s, head->username )==0){return head;}head = head->next;}return NULL;}//用户 读入文件
void readUser (){FILE *fp = NULL;if (NULL == (fp = fopen("User.txt", "r")))//读打开{//文件不存在,不读取return;}int i=0;//从文件读取数据userList = NULL;struct User *tail = userList;while (1)//读取{//给节点分配空间struct User *p=(struct User*)malloc(sizeof(struct User));//读取数据到pif(fscanf(fp, "%s%s",p->username ,p->password ) == EOF) {break;}p->next=NULL;//指针为空则赋值。if (userList == NULL){userList=p;tail=p;}else {tail->next=p;tail=p;}i++;}//记录总数userCount = i;fclose(fp);
}
//用户 写入文件
void writeUser (){//打开文件FILE *fp = NULL;fp = fopen("User.txt", "w+");//定义指针struct User *p = userList;//写入while(p){fprintf(fp,"%s %s\n",p->username ,p->password );p=p->next;}fclose(fp);
}
//用户 添加记录
void addUser (){char selectYNFlag = 'y';while(selectYNFlag == 'y' || selectYNFlag == 'Y' ){printf("\n"); struct User *tempValue = (struct User*)malloc(sizeof(struct User)); //必须重新分配地址空间。printf("请输入用户名 :"); char username[15]; scanf("%s",username);strcpy(tempValue->username,username);struct User* oneusername = getOneUser ("username",tempValue->username);if(oneusername !=NULL){//检索不为空printf("用户名已存在!\n"); break;}printf("请输入密码 :"); char password[15]; scanf("%s",password);strcpy(tempValue->password,password);//TODO//加入链表tempValue->next = NULL;addOneUser (tempValue);printf("\n是否继续录入?(y/n)"); getchar();scanf("%c",&selectYNFlag);}writeUser ( );printf("\n*****************************\n"); printf("录入完成\n"); printf("*****************************\n"); }
void addOneUser (struct User *temp){//采用头插法if(userList == NULL){userList = temp;}else{temp->next = userList;userList = temp;}userCount ++;
}
//用户 删除
void delUser (){printf("请输入您要删除的 用户 序号(输入-1退出):"); int index;scanf("%d",&index);if(index >= 0){int res = delUserByIndex (index);if(res){printf("删除成功!\n\n"); writeUser ();}else{printf("删除失败!\n\n"); }}
}
//用户 根据下标删除
int delUserByIndex (int index){if(index > userCount || index < 1){return 0;//删除失败 ,数量没那么多}//开始删除!struct User *p = (struct User*)malloc(sizeof(struct User));struct User *q = userList;p->next = userList;if(index == 1){userList = userList ->next;}else{int i;for(i = 0;i < index-1 ; i++){p = p->next;q = q->next;}p->next = q->next;}userCount = userCount - 1;return 1;
}
//用户 修改
void modUser (){printf("请输入您要修改的用户 序号(输入-1退出):"); int indexOfMod = -1,i;scanf("%d",&indexOfMod);if(indexOfMod > 0 && indexOfMod <= userCount ){//开始修改struct User *temp = userList ;for( i = 0;i < indexOfMod-1;i++){temp=temp->next;}printf("请输入密码 :"); char password[15];scanf("%s",password);//输入完毕,赋值strcpy(temp-> password,password);printf("修改成功!\n"); writeUser ();}else{printf("输入错误!\n"); }
}
//用户 查找 如果all=1:查询全部 否则按条件查询
void findUser (int all){int select = 0;char conCharArr[40];double conNum1,conNum2;while(1){printf("\n%-5s%-15s%-15s\n\n","序号" ,"用户名","密码" );int i=1,count = 0;if( userList ){//用于统计信息所用struct User *t = userList;while(t){int delFlag = 0;if(select == 0|| select == 1 && strstr(t->username,conCharArr) //根据用户名,模糊查询){printf("%-5d%-15s%-15s \n\n",i,t->username,t->password);//用于统计信息所用count++;}else{delFlag = 1;//删掉}t=t->next;if(delFlag){delUserByIndex (i--);}i++;}printf("共%d条结果\n",count); printf("-----------------------------------------------------------------------------------------------------\n"); printf("\n"); }else{printf("\n【无记录!】\n\n"); }//如果参数all为1,则表示列出所有就退出if(all == 1)break;//进入过滤。printf("【筛选器:你可以在以上结果的基础上,进行以下条件筛选:】\n"); printf("0:退出\n"); printf("1:按 用户名 筛选\n"); printf("请输入选择:"); scanf("%d",&select);if(select>0){if(0 ||select==1 ){printf("请输入筛选条件:"); scanf("%s",conCharArr);}else if(0 ){printf("请输入筛选范围m,n,用空格隔开(m ≤X ≤n):"); scanf("%lf",&conNum1);scanf("%lf",&conNum2);}}else{break;}}readUser();//从新读取数据。
}
//用户 排序
void sortUser (){int select,i,j;printf("1:按 用户名 排序\n"); printf("2:按 密码 排序\n"); printf("请输入选择:"); scanf("%d",&select);struct User *list[100];for(i = 0;i< userCount;i++){list[i] = userList;userList = userList ->next;}for( i = userCount -1;i>0;i--){for( j = 0;j < i;j++){if( 0|| select == 1 && strcmp(list[j]->username , list[j+1]->username)>0|| select == 2 && strcmp(list[j]->password , list[j+1]->password)>0){struct User *temp = (struct User*)malloc(sizeof(struct User));temp = list[j]; //交换位置list[j] = list[j+1];list[j+1] = temp;}}}for(i = 0;i< userCount -1;i++){list[i]->next = list[i+1];}list[ userCount -1 ]->next = NULL;userList = list[0];findUser (1);writeUser ();
}void menuUser (){//菜单printf("*------------------主菜单---------------------*\n"); printf("*-------------1 :添加球员\n"); printf("*-------------2 :删除球员\n"); printf("*-------------3 :修改球员\n"); printf("*-------------4 :查找球员\n"); printf("*-------------5 :排序球员\n"); printf("*-------------6 :查找用户\n"); printf("*-------------7 :排序用户\n"); printf("*-------------0:退出\n"); printf("*------------(-1):登出\n"); printf("*------------(-2):我的\n"); printf("*---------------------------------------------*\n"); printf("请输入选择:"); }
链表:C++版本
#include <io.h>#include <iostream>#include <windows.h>using namespace std; //定义 球员 链表struct Startman {char name[15] ; // 球员姓名char team[15] ; // 所属球队int sumcore ; // 生涯累计得分int maxcore ; // 最高得分int count ; // 生涯参赛场次int number ; // 号码char jiaol[15] ; // 教练double avgitem ; // 平均分struct Startman* next;//链式存储};struct Startman *startmanList;//定义全局 球员 指针int startmanCount = 0;//球员 个数记录//定义 用户 链表struct User {char username[15] ; // 用户名char password[15] ; // 密码struct User* next;//链式存储};struct User *userList;//定义全局 用户 指针int userCount = 0;//用户 个数记录//球员 读入文件void readStartman ();//球员 写入文件void writeStartman ();//球员 添加记录void addStartman ();void addOneStartman (struct Startman *startman);//球员 删除记录void delStartman ();//球员 根据下标删除int delStartmanByIndex (int index);//球员 修改记录void modStartman ();//球员 查找记录void findStartman (int all);//球员 排序void sortStartman ();//交换void exchangeStartman (int i ,int j);//存在判断函数struct Startman* getOneStartman (const char *name,char *s);//用户 读入文件void readUser ();//用户 写入文件void writeUser ();//用户 添加记录void addUser ();void addOneUser (struct User *user);//用户 删除记录void delUser ();//用户 根据下标删除int delUserByIndex (int index);//用户 修改记录void modUser ();//用户 查找记录void findUser (int all);//用户 排序void sortUser ();//交换void exchangeUser (int i ,int j);//存在判断函数struct User* getOneUser (const char *name,char *s);void modUserInfo ();//菜单void login();void regist();struct User *loginUser = NULL;void menuUser ();int loginStatus = 0;//意义:0 未登录// 主函数int main(){//读取数据readStartman ();//读取球员readUser ();//读取用户while(1){cout<<"*---------------------------------------------*\n*------------1:登陆\n*------------2:注册\n*---------------------------------------------*\n请输入选择:";int logout=0; //返回上一级标志int select =0;cin>>select;if(select!=2){login();}else{regist();}int choice;if(loginStatus == 1)while(logout==0){ menuUser ();cin>>choice;switch(choice){case 1 :addStartman ();//添加球员break;case 2 :findStartman (1);//查找球员delStartman ();//删除球员break;case 3 :findStartman (1);//查找球员modStartman ();//修改球员break;case 4 :findStartman (0);//查找球员break;case 5 :sortStartman ();//排序球员break;case 6 :findUser (0);//查找用户break;case 7 :sortUser ();//排序用户break;case 0:cout<<"\n\n\n\t\t\t感谢使用\n\n\n";exit(0);case -1:cout<<"\n";logout =1;loginStatus = 0;break;case -2:modUserInfo ();//修改个人信息break;default :getchar();cout<<"\n\n\n\t提示:没有这个选项!请重新输入!\n\n\n\n";system("pause");break;}} }return 0;}void login(){int i;while(loginStatus==0){char username[20],password[20];cout<<"请输入账号:";cin>>username;cout<<"请输入密码:";cin>>password;// 用户 登录if(loginStatus==0){struct User *user = userList;while(user){if(strcmp(username,user ->username)==0){if(strcmp(password,user ->password)==0){loginUser = user;loginStatus = 1;break;}}user = user ->next;}}//判断登录情况if(loginStatus == 0){cout<<"\n用户名密码错误请重新登录!\n\n";} else{cout<<"\n登录成功!\n\n";;}}}void regist(){int flag = 0;//注册状态 0 失败 ,1 成功while(flag ==0){cout<<"*---------------------------------------------*\n*------------0:返回 \n";cout<<"*------------1:注册用户 \n";cout<<"*---------------------------------------------*\n请输入选择:";int select = 0;cin>>select;;if(select == 0){flag = 1;//返回} else{char username[20],password[20];cout<<"请输入账号:";cin>>username;;cout<<"请输入密码:";cin>>password;if( select == 1 ){if( getOneUser ("username",username)!=NULL) { //根据用户名查找cout<<"\n用户名已存在!\n\n";}else{struct User *user = (struct User*)malloc(sizeof(struct User));strcpy( user ->username,username);strcpy( user ->password,password);user ->next = NULL;loginUser = user;addOneUser (user);loginStatus = 1;writeUser ();flag = 1;}}if(flag == 1)cout<<"注册成功\n\n";elsecout<<"注册失败!\n\n";}}}//是否存在判断struct Startman *getOneStartman (const char *name,char *s){struct Startman *head = startmanList;while(head){if( strcmp(name,"name")==0 && strcmp(s, head->name )==0){return head;}head = head->next;}return NULL;}//球员 读入文件
void readStartman (){FILE *fp = NULL;if (NULL == (fp = fopen("Startman.txt", "r")))//读打开{//文件不存在,不读取return;}int i=0;//从文件读取数据startmanList = NULL;struct Startman *tail = startmanList;while (1)//读取{//给节点分配空间struct Startman *p=(struct Startman*)malloc(sizeof(struct Startman));//读取数据到pif(fscanf(fp, "%s%s%d%d%d%d%s%lf",p->name ,p->team ,&p->sumcore ,&p->maxcore ,&p->count ,&p->number ,p->jiaol ,&p->avgitem ) == EOF) {break;}p->next=NULL;//指针为空则赋值。if (startmanList == NULL){startmanList=p;tail=p;}else {tail->next=p;tail=p;}i++;}//记录总数startmanCount = i;fclose(fp);
}
//球员 写入文件
void writeStartman (){//打开文件FILE *fp = NULL;fp = fopen("Startman.txt", "w+");//定义指针struct Startman *p = startmanList;//写入while(p){fprintf(fp,"%s %s %d %d %d %d %s %lf\n",p->name ,p->team ,p->sumcore ,p->maxcore ,p->count ,p->number ,p->jiaol ,p->avgitem );p=p->next;}fclose(fp);
}
//球员 添加记录
void addStartman (){char selectYNFlag = 'y';while(selectYNFlag == 'y' || selectYNFlag == 'Y' ){cout<<"\n";struct Startman *tempValue = (struct Startman*)malloc(sizeof(struct Startman)); //必须重新分配地址空间。cout<<"请输入球员姓名 :";char name[15]; cin>>name;strcpy(tempValue->name,name);struct Startman* onename = getOneStartman ("name",tempValue->name);if(onename !=NULL){//检索不为空cout<<"球员姓名已存在!\n";break;}cout<<"请输入所属球队 :";char team[15]; cin>>team;strcpy(tempValue->team,team);cout<<"请输入生涯累计得分 :";int sumcore; cin>>sumcore;tempValue->sumcore = sumcore ;cout<<"请输入最高得分 :";int maxcore; cin>>maxcore;tempValue->maxcore = maxcore ;cout<<"请输入生涯参赛场次 :";int count; cin>>count;tempValue->count = count ;cout<<"请输入号码 :";int number; cin>>number;tempValue->number = number ;cout<<"请输入教练 :";char jiaol[15]; cin>>jiaol;strcpy(tempValue->jiaol,jiaol);double avgitem = sumcore/count*1.0 ; tempValue->avgitem = avgitem ;//TODO//加入链表tempValue->next = NULL;addOneStartman (tempValue);cout<<"\n是否继续录入?(y/n)";getchar();cin>>selectYNFlag;}writeStartman ( );cout<<"\n*****************************\n";cout<<"录入完成\n";cout<<"*****************************\n";}
void addOneStartman (struct Startman *temp){//采用头插法if(startmanList == NULL){startmanList = temp;}else{temp->next = startmanList;startmanList = temp;}startmanCount ++;
}
//球员 删除
void delStartman (){cout<<"请输入您要删除的 球员 序号(输入-1退出):";int index;cin>>index;if(index >= 0){int res = delStartmanByIndex (index);if(res){cout<<"删除成功!\n\n";writeStartman ();}else{cout<<"删除失败!\n\n";}}
}
//球员 根据下标删除
int delStartmanByIndex (int index){if(index > startmanCount || index < 1){return 0;//删除失败 ,数量没那么多}//开始删除!struct Startman *p = (struct Startman*)malloc(sizeof(struct Startman));struct Startman *q = startmanList;p->next = startmanList;if(index == 1){startmanList = startmanList ->next;}else{int i;for(i = 0;i < index-1 ; i++){p = p->next;q = q->next;}p->next = q->next;}startmanCount = startmanCount - 1;return 1;
}
//球员 修改
void modStartman (){cout<<"请输入您要修改的球员 序号(输入-1退出):";int indexOfMod = -1,i;cin>>indexOfMod;if(indexOfMod > 0 && indexOfMod <= startmanCount ){//开始修改struct Startman *temp = startmanList ;for( i = 0;i < indexOfMod-1;i++){temp=temp->next;}cout<<"请输入球员姓名 :";char name[15];cin>>name;if(strcmp(temp->name,name) != 0 && getOneStartman ("name",name)!=NULL){//检索不为空cout<<"球员姓名 已存在!\n";return;}cout<<"请输入所属球队 :";char team[15];cin>>team;cout<<"请输入生涯累计得分 :";int sumcore;cin>>sumcore;cout<<"请输入最高得分 :";int maxcore;cin>>maxcore;cout<<"请输入生涯参赛场次 :";int count;cin>>count;cout<<"请输入号码 :";int number;cin>>number;cout<<"请输入教练 :";char jiaol[15];cin>>jiaol;cout<<"请输入平均分 :";double avgitem;cin>>avgitem;//输入完毕,赋值strcpy(temp-> name,name);strcpy(temp-> team,team);temp-> sumcore = sumcore ;temp-> maxcore = maxcore ;temp-> count = count ;temp-> number = number ;strcpy(temp-> jiaol,jiaol);temp-> avgitem = avgitem ;cout<<"修改成功!\n";writeStartman ();}else{cout<<"输入错误!\n";}
}
//球员 查找 如果all=1:查询全部 否则按条件查询
void findStartman (int all){int select = 0;char conCharArr[40];double conNum1,conNum2;while(1){printf("\n%-5s%-15s%-15s%-10s%-10s%-10s%-10s%-15s%-12s\n\n","序号" ,"球员姓名","所属球队","生涯累计得分","最高得分","生涯参赛场次","号码","教练","平均分" );int i=1,count = 0;if( startmanList ){//用于统计信息所用int sumcoreSum=0;struct Startman *t = startmanList;while(t){int delFlag = 0;if(select == 0|| select == 1 && strstr(t->name,conCharArr) //根据球员姓名,模糊查询|| select == 2 && strstr(t->team,conCharArr) //根据所属球队,模糊查询|| select == 3 && t->sumcore >= conNum1 && t->sumcore<=conNum2 //根据生涯累计得分 范围查询|| select == 4 && t->maxcore >= conNum1 && t->maxcore<=conNum2 //根据最高得分 范围查询|| select == 5 && t->number >= conNum1 && t->number<=conNum2 //根据号码 范围查询){printf("%-5d%-15s%-15s%-10d%-10d%-10d%-10d%-15s%-12lf \n\n",i,t->name,t->team,t->sumcore,t->maxcore,t->count,t->number,t->jiaol,t->avgitem);//用于统计信息所用sumcoreSum += t->sumcore;count++;}else{delFlag = 1;//删掉}t=t->next;if(delFlag){delStartmanByIndex (i--);}i++;}cout<<"共" << count <<"条结果\n";cout<<"-----------------------------------------------------------------------------------------------------\n";cout<<"【生涯累计得分】" <<"平均:"<< (count!=0?sumcoreSum*1.0/count:0)<<"\n";cout<<"\n";}else{cout<<"\n【无记录!】\n\n";}//如果参数all为1,则表示列出所有就退出if(all == 1)break;//进入过滤。cout<<"【筛选器:你可以在以上结果的基础上,进行以下条件筛选:】\n";cout<<"0:退出\n";cout<<"1:按 球员姓名 筛选\n";cout<<"2:按 所属球队 筛选\n";cout<<"3:按 生涯累计得分 筛选\n";cout<<"4:按 最高得分 筛选\n";cout<<"5:按 号码 筛选\n";cout<<"请输入选择:";cin>>select;if(select>0){if(0 ||select==1 ||select==2 ){cout<<"请输入筛选条件:";cin>>conCharArr;}else if(0 ||select==3 ||select==4 ||select==5 ){cout<<"请输入筛选范围m,n,用空格隔开(m ≤X ≤n):";cin>>conNum1;cin>>conNum2;}}else{break;}}readStartman();//从新读取数据。
}
//球员 排序
void sortStartman (){int select,i,j;cout<<"1:按 球员姓名 排序\n";cout<<"2:按 所属球队 排序\n";cout<<"3:按 生涯累计得分 排序\n";cout<<"4:按 最高得分 排序\n";cout<<"5:按 生涯参赛场次 排序\n";cout<<"6:按 号码 排序\n";cout<<"7:按 教练 排序\n";cout<<"8:按 平均分 排序\n";cout<<"请输入选择:";cin>>select;struct Startman *list[100];for(i = 0;i< startmanCount;i++){list[i] = startmanList;startmanList = startmanList ->next;}for( i = startmanCount -1;i>0;i--){for( j = 0;j < i;j++){if( 0|| select == 1 && strcmp(list[j]->name , list[j+1]->name)>0|| select == 2 && strcmp(list[j]->team , list[j+1]->team)>0|| select == 3 && list[j]->sumcore - list[j+1]->sumcore > 0|| select == 4 && list[j]->maxcore - list[j+1]->maxcore > 0|| select == 5 && list[j]->count - list[j+1]->count > 0|| select == 6 && list[j]->number - list[j+1]->number > 0|| select == 7 && strcmp(list[j]->jiaol , list[j+1]->jiaol)>0|| select == 8 && list[j]->avgitem - list[j+1]->avgitem > 0){struct Startman *temp = (struct Startman*)malloc(sizeof(struct Startman));temp = list[j]; //交换位置list[j] = list[j+1];list[j+1] = temp;}}}for(i = 0;i< startmanCount -1;i++){list[i]->next = list[i+1];}list[ startmanCount -1 ]->next = NULL;startmanList = list[0];findStartman (1);writeStartman ();
}
void modUserInfo (){cout<<"\n====您的个人信息如下====\n";cout<<"用户名:" << loginUser ->username <<"\n";cout<<"密码:" << loginUser ->password <<"\n";cout<<"==========================\n1,修改个人信息\n2,返回上一级\n请选择:";int n;cin>>n;if (n == 1) {struct User *h = userList;while(h){if(strcmp(h->username,loginUser ->username)==0){cout<<"请输入密码 :";cin>>h->password;loginUser = h;writeUser ();cout<<"修改成功!\n";break;}h=h->next;}}
}//是否存在判断struct User *getOneUser (const char *name,char *s){struct User *head = userList;while(head){if( strcmp(name,"username")==0 && strcmp(s, head->username )==0){return head;}head = head->next;}return NULL;}//用户 读入文件
void readUser (){FILE *fp = NULL;if (NULL == (fp = fopen("User.txt", "r")))//读打开{//文件不存在,不读取return;}int i=0;//从文件读取数据userList = NULL;struct User *tail = userList;while (1)//读取{//给节点分配空间struct User *p=(struct User*)malloc(sizeof(struct User));//读取数据到pif(fscanf(fp, "%s%s",p->username ,p->password ) == EOF) {break;}p->next=NULL;//指针为空则赋值。if (userList == NULL){userList=p;tail=p;}else {tail->next=p;tail=p;}i++;}//记录总数userCount = i;fclose(fp);
}
//用户 写入文件
void writeUser (){//打开文件FILE *fp = NULL;fp = fopen("User.txt", "w+");//定义指针struct User *p = userList;//写入while(p){fprintf(fp,"%s %s\n",p->username ,p->password );p=p->next;}fclose(fp);
}
//用户 添加记录
void addUser (){char selectYNFlag = 'y';while(selectYNFlag == 'y' || selectYNFlag == 'Y' ){cout<<"\n";struct User *tempValue = (struct User*)malloc(sizeof(struct User)); //必须重新分配地址空间。cout<<"请输入用户名 :";char username[15]; cin>>username;strcpy(tempValue->username,username);struct User* oneusername = getOneUser ("username",tempValue->username);if(oneusername !=NULL){//检索不为空cout<<"用户名已存在!\n";break;}cout<<"请输入密码 :";char password[15]; cin>>password;strcpy(tempValue->password,password);//TODO//加入链表tempValue->next = NULL;addOneUser (tempValue);cout<<"\n是否继续录入?(y/n)";getchar();cin>>selectYNFlag;}writeUser ( );cout<<"\n*****************************\n";cout<<"录入完成\n";cout<<"*****************************\n";}
void addOneUser (struct User *temp){//采用头插法if(userList == NULL){userList = temp;}else{temp->next = userList;userList = temp;}userCount ++;
}
//用户 删除
void delUser (){cout<<"请输入您要删除的 用户 序号(输入-1退出):";int index;cin>>index;if(index >= 0){int res = delUserByIndex (index);if(res){cout<<"删除成功!\n\n";writeUser ();}else{cout<<"删除失败!\n\n";}}
}
//用户 根据下标删除
int delUserByIndex (int index){if(index > userCount || index < 1){return 0;//删除失败 ,数量没那么多}//开始删除!struct User *p = (struct User*)malloc(sizeof(struct User));struct User *q = userList;p->next = userList;if(index == 1){userList = userList ->next;}else{int i;for(i = 0;i < index-1 ; i++){p = p->next;q = q->next;}p->next = q->next;}userCount = userCount - 1;return 1;
}
//用户 修改
void modUser (){cout<<"请输入您要修改的用户 序号(输入-1退出):";int indexOfMod = -1,i;cin>>indexOfMod;if(indexOfMod > 0 && indexOfMod <= userCount ){//开始修改struct User *temp = userList ;for( i = 0;i < indexOfMod-1;i++){temp=temp->next;}cout<<"请输入密码 :";char password[15];cin>>password;//输入完毕,赋值strcpy(temp-> password,password);cout<<"修改成功!\n";writeUser ();}else{cout<<"输入错误!\n";}
}
//用户 查找 如果all=1:查询全部 否则按条件查询
void findUser (int all){int select = 0;char conCharArr[40];double conNum1,conNum2;while(1){printf("\n%-5s%-15s%-15s\n\n","序号" ,"用户名","密码" );int i=1,count = 0;if( userList ){//用于统计信息所用struct User *t = userList;while(t){int delFlag = 0;if(select == 0|| select == 1 && strstr(t->username,conCharArr) //根据用户名,模糊查询){printf("%-5d%-15s%-15s \n\n",i,t->username,t->password);//用于统计信息所用count++;}else{delFlag = 1;//删掉}t=t->next;if(delFlag){delUserByIndex (i--);}i++;}cout<<"共" << count <<"条结果\n";cout<<"-----------------------------------------------------------------------------------------------------\n";cout<<"\n";}else{cout<<"\n【无记录!】\n\n";}//如果参数all为1,则表示列出所有就退出if(all == 1)break;//进入过滤。cout<<"【筛选器:你可以在以上结果的基础上,进行以下条件筛选:】\n";cout<<"0:退出\n";cout<<"1:按 用户名 筛选\n";cout<<"请输入选择:";cin>>select;if(select>0){if(0 ||select==1 ){cout<<"请输入筛选条件:";cin>>conCharArr;}else if(0 ){cout<<"请输入筛选范围m,n,用空格隔开(m ≤X ≤n):";cin>>conNum1;cin>>conNum2;}}else{break;}}readUser();//从新读取数据。
}
//用户 排序
void sortUser (){int select,i,j;cout<<"1:按 用户名 排序\n";cout<<"2:按 密码 排序\n";cout<<"请输入选择:";cin>>select;struct User *list[100];for(i = 0;i< userCount;i++){list[i] = userList;userList = userList ->next;}for( i = userCount -1;i>0;i--){for( j = 0;j < i;j++){if( 0|| select == 1 && strcmp(list[j]->username , list[j+1]->username)>0|| select == 2 && strcmp(list[j]->password , list[j+1]->password)>0){struct User *temp = (struct User*)malloc(sizeof(struct User));temp = list[j]; //交换位置list[j] = list[j+1];list[j+1] = temp;}}}for(i = 0;i< userCount -1;i++){list[i]->next = list[i+1];}list[ userCount -1 ]->next = NULL;userList = list[0];findUser (1);writeUser ();
}void menuUser (){//菜单cout<<"*------------------主菜单---------------------*\n";cout<<"*-------------1 :添加球员\n";cout<<"*-------------2 :删除球员\n";cout<<"*-------------3 :修改球员\n";cout<<"*-------------4 :查找球员\n";cout<<"*-------------5 :排序球员\n";cout<<"*-------------6 :查找用户\n";cout<<"*-------------7 :排序用户\n";cout<<"*-------------0:退出\n";cout<<"*------------(-1):登出\n";cout<<"*------------(-2):我的\n";cout<<"*---------------------------------------------*\n";cout<<"请输入选择:";}
C++面向对象
#include <iostream>#include <vector>#include <fstream>#include <string.h>using namespace std; int compare(int a,int b);
int compare(const char *a,const char *b);class Startman //定义 球员 类
{
public:static vector< Startman*> dataList;char name[15] ; // 球员姓名char team[15] ; // 所属球队int sumcore ; // 生涯累计得分int maxcore ; // 最高得分int count ; // 生涯参赛场次int number ; // 号码char jiaol[15] ; // 教练double avgitem ; // 平均分static void read();//读文件static void write();//写文件static void add();//添加static void del();//删除static void mod();//修改static void find(int all);//查找static void sort();//排序static Startman* getOne(string name, string s);//存在判断函数};
vector< Startman*> Startman::dataList;//必须类外初始化,用于存储球员
class User //定义 用户 类
{
public:static vector< User*> dataList;char username[15] ; // 用户名char password[15] ; // 密码static void read();//读文件static void write();//写文件static void add();//添加static void del();//删除static void mod();//修改static void find(int all);//查找static void sort();//排序static User* getOne(string name, string s);//存在判断函数static void modInfo();};
vector< User*> User::dataList;//必须类外初始化,用于存储用户//定义菜单
void login();
void regist();User *loginUser = NULL;void menuUser ();int loginStatus = 0;//意义 如:0 未登录 1 管理员 2 用户// 主函数int main(){//读取数据Startman::read ();//读取球员User::read ();//读取用户while(1){cout<<"*---------------------------------------------*\n*------------1:登陆\n*------------2:注册\n*---------------------------------------------*\n请输入选择:";int logout=0; //返回上一级标志int select =0;cin>>select;if(select!=2){login();}else{regist();}int choice;if(loginStatus == 1)while(logout==0){ menuUser ();cin>>choice;switch(choice){case 1 :Startman::add ();//添加球员break;case 2 :Startman::find (1);//查找球员Startman::del ();//删除球员break;case 3 :Startman::find (1);//查找球员Startman::mod ();//修改球员break;case 4 :Startman::find (0);//查找球员break;case 5 :Startman::sort ();//排序球员break;case 6 :User::find (0);//查找用户break;case 7 :User::sort ();//排序用户break;case 0:cout<<"\n\n\n\t\t\t感谢使用\n\n\n";exit(0);case -1:cout<<"\n";logout =1;loginStatus = 0;break;case -2:User::modInfo();//修改个人信息break;default :getchar();cout<<"\n\n\n\t提示:没有这个选项!请重新输入!\n\n\n\n";system("pause");break;}} }return 0;}void login(){int i;while(loginStatus==0){char username[20],password[20];cout<<"请输入账号:";cin>>username;cout<<"请输入密码:";cin>>password;// 用户 登录if(loginStatus==0){User *user = new User;for(int i = 0 ;i < User::dataList.size();i++){if(strcmp(username,User::dataList[i]->username)==0){if(strcmp(password,User::dataList[i]->password)==0){loginUser = User::dataList[i];loginStatus = 1;break;}}}}//判断登录情况if(loginStatus == 0){cout<<"\n用户名密码错误请重新登录!\n\n";} else{cout<<"\n登录成功!\n\n";;}}}void regist(){int flag = 0;//注册状态 0 失败 ,1 成功while(flag ==0){cout<<"*---------------------------------------------*\n*------------0:返回 \n";cout<<"*------------1:注册用户 \n";cout<<"*---------------------------------------------*\n请输入选择:";int select = 0;cin>>select;;if(select == 0){flag = 1;//返回} else{char username[20],password[20];cout<<"请输入账号:";cin>>username;;cout<<"请输入密码:";cin>>password;if( select == 1 ){if( User::getOne ("username",username)!=NULL) { //根据用户名查找cout<<"\n用户名已存在!\n\n";}else{User *temp = new User;strcpy( temp->username,username);strcpy( temp->password,password);loginUser = temp;User::dataList.push_back(temp);loginStatus = 1;User::write ();flag = 1;}}if(flag == 1)cout<<"注册成功\n\n";elsecout<<"注册失败!\n\n";}}}//是否存在判断
Startman* Startman::getOne(string name, string s) {for (int i = 0; i < dataList.size();i++) {if( strcmp(name.c_str(),"name")==0 && strcmp(s.c_str(), dataList[i]->name )==0){return dataList[i];}}return NULL;
}
//读取文件内的球员
void Startman::read() {FILE *fp = NULL;if (NULL == (fp = fopen("Startman.txt", "r")))//读打开{//文件不存在,不读取return;}//从文件读取数据dataList.clear();while (1)//读取{//新建球员对象Startman *t = new Startman;//读取数据到pif(fscanf(fp, "%s%s%d%d%d%d%s%lf",t->name ,t->team ,&t->sumcore ,&t->maxcore ,&t->count ,&t->number ,t->jiaol ,&t->avgitem ) == EOF) {break;}dataList.push_back(t);//将内容加入vector}fclose(fp);
}
//球员 写入文件
void Startman::write() {//打开文件FILE *fp = NULL;fp = fopen("Startman.txt", "w+");//写入for (int i = 0; i < dataList.size(); i++) {Startman *t = dataList.at(i);fprintf(fp,"%s %s %d %d %d %d %s %lf\n",t->name ,t->team ,t->sumcore ,t->maxcore ,t->count ,t->number ,t->jiaol ,t->avgitem );}fclose(fp);
}
//球员 添加记录
void Startman::add() {char selectYNFlag = 'y';while(selectYNFlag == 'y' || selectYNFlag == 'Y' ){cout<<"\n";Startman *tempValue = new Startman (); //必须重新分配地址空间。cout<<"请输入球员姓名 :";char name[15]; cin>>name ;strcpy(tempValue->name,name);Startman* onename = getOne("name",tempValue->name);if(onename!=NULL){//检索不为空cout<<("球员姓名已存在!\n");break;}cout<<"请输入所属球队 :";char team[15]; cin>>team ;strcpy(tempValue->team,team);cout<<"请输入生涯累计得分 :";int sumcore; cin>>sumcore ;tempValue->sumcore = sumcore ;cout<<"请输入最高得分 :";int maxcore; cin>>maxcore ;tempValue->maxcore = maxcore ;cout<<"请输入生涯参赛场次 :";int count; cin>>count ;tempValue->count = count ;cout<<"请输入号码 :";int number; cin>>number ;tempValue->number = number ;cout<<"请输入教练 :";char jiaol[15]; cin>>jiaol ;strcpy(tempValue->jiaol,jiaol);double avgitem = sumcore/count*1.0 ; tempValue->avgitem = avgitem ;//TODO,//加入记录dataList.push_back(tempValue);cout<<"\n是否继续录入?(y/n)";getchar();cin>>selectYNFlag;}//写入文件write();cout<<"\n*****************************\n";cout<<"录入结束\n";cout<<"*****************************\n";
}
//球员 删除
void Startman::del() {cout<<"请输入您要删除的 球员 序号(输入-1退出):";char c;cin >> c;int index = c - '0';if (index >= 0 && index < dataList.size()) {dataList.erase(dataList.begin()+index);write();cout << "删除成功!\n\n";}else if(index>0){cout << "请输入正确序号!\n\n";}
}//球员 修改
void Startman::mod() {cout<<"请输入您要修改的球员 序号(输入-1退出):";char c;cin >> c;int indexOfMod = c - '0';if(indexOfMod >= 0 && indexOfMod < dataList.size() ){//开始修改Startman *temp = dataList.at(indexOfMod);cout<<"请输入球员姓名 :";char name[15];cin>> name ;if(compare(temp->name,name) != 0 && getOne("name",name)!=NULL){//检索不为空cout<<("球员姓名 已存在!\n");return;}cout<<"请输入所属球队 :";char team[15];cin>> team ;cout<<"请输入生涯累计得分 :";int sumcore;cin>> sumcore ;cout<<"请输入最高得分 :";int maxcore;cin>> maxcore ;cout<<"请输入生涯参赛场次 :";int count;cin>> count ;cout<<"请输入号码 :";int number;cin>> number ;cout<<"请输入教练 :";char jiaol[15];cin>> jiaol ;cout<<"请输入平均分 :";double avgitem;cin>> avgitem ;//输入完毕,赋值strcpy(temp-> name,name);strcpy(temp-> team,team);temp-> sumcore = sumcore ;temp-> maxcore = maxcore ;temp-> count = count ;temp-> number = number ;strcpy(temp-> jiaol,jiaol);temp-> avgitem = avgitem ;cout<<"修改成功!\n";write();}else{cout<<"输入错误!\n";}
}
//球员 查找 如果all=1:查询全部 否则按条件查询
void Startman :: find(int all){int select = 0;char conCharArr[40];double conNum1,conNum2;//复制一个容器dataList2,查询的操作再dataList2里面进行vector<Startman*> dataList2 = dataList;while(1){printf("\n%-5s%-15s%-15s%-10s%-10s%-10s%-10s%-15s%-12s\n\n","序号" ,"球员姓名","所属球队","生涯累计得分","最高得分","生涯参赛场次","号码","教练","平均分" );int count = 0;//用于统计信息所用int sumcoreSum=0;for(int i = 0;i < dataList2.size();i++){Startman* t = dataList2.at(i);if(select == 0|| select == 1 && strstr(t->name,conCharArr) //根据球员姓名,模糊查询|| select == 2 && strstr(t->team,conCharArr) //根据所属球队,模糊查询|| select == 3 && t->sumcore>= conNum1 && t->sumcore<=conNum2 //根据生涯累计得分 范围查询|| select == 4 && t->maxcore>= conNum1 && t->maxcore<=conNum2 //根据最高得分 范围查询|| select == 5 && t->number>= conNum1 && t->number<=conNum2 //根据号码 范围查询){printf("%-5d%-15s%-15s%-10d%-10d%-10d%-10d%-15s%-12lf \n\n",i,t->name,t->team,t->sumcore,t->maxcore,t->count,t->number,t->jiaol,t->avgitem);//用于统计信息所用sumcoreSum += t->sumcore;count++;}else {dataList2.erase(dataList2.begin()+i);i--;}}cout<<"共"<< count <<"条结果\n";cout<<("-----------------------------------------------------------------------------------------------------\n");cout<<"【生涯累计得分】" <<"平均:"<< (count!=0?sumcoreSum*1.0/count:0)<<"\n";cout<<"\n";//如果参数all为1,则表示列出所有就退出if(all == 1)break;//进入过滤。cout<<"【筛选器:你可以在以上结果的基础上,进行以下条件筛选】\n";cout<<"0:退出\n";cout<<"1:按 球员姓名 筛选\n";cout<<"2:按 所属球队 筛选\n";cout<<"3:按 生涯累计得分 筛选\n";cout<<"4:按 最高得分 筛选\n";cout<<"5:按 号码 筛选\n";cout<<"请输入选择:";cin>>select;if(select>0){if(0 ||select==1 ||select==2 ){cout<<"请输入筛选条件:";cin>>conCharArr;}else if(0 ||select==3 ||select==4 ||select==5 ){cout<<"请输入筛选范围m,n,用空格隔开(m ≤X ≤n):";cin>>conNum1;cin>>conNum2;}}else{break;}}
}
//球员 排序
void Startman::sort(){int select,i,j;cout<<"1:按 球员姓名 排序\n";cout<<"2:按 所属球队 排序\n";cout<<"3:按 生涯累计得分 排序\n";cout<<"4:按 最高得分 排序\n";cout<<"5:按 生涯参赛场次 排序\n";cout<<"6:按 号码 排序\n";cout<<"7:按 教练 排序\n";cout<<"8:按 平均分 排序\n";cout<<"请输入选择:";cin>>select;for (i = dataList.size() - 1; i > 0; i--) {for( j = 0;j < i;j++){if( 0|| select == 1 && compare(dataList[j]->name , dataList[j+1]->name )>0|| select == 2 && compare(dataList[j]->team , dataList[j+1]->team )>0|| select == 3 && compare(dataList[j]->sumcore , dataList[j+1]->sumcore )>0|| select == 4 && compare(dataList[j]->maxcore , dataList[j+1]->maxcore )>0|| select == 5 && compare(dataList[j]->count , dataList[j+1]->count )>0|| select == 6 && compare(dataList[j]->number , dataList[j+1]->number )>0|| select == 7 && compare(dataList[j]->jiaol , dataList[j+1]->jiaol )>0|| select == 8 && compare(dataList[j]->avgitem , dataList[j+1]->avgitem )>0){swap(dataList[j], dataList[j + 1]);}}}find(1);//排序后打印write();
}
void User::modInfo(){cout << "\n====您的个人信息如下====\n";cout << "用户名:" << loginUser ->username << endl;cout << "密码:" << loginUser ->password << endl;cout << "==========================\n1,修改个人信息\n2,返回上一级\n请选择:";char n;cin >> n;if (n == '1') {cout << "请输入密码:";cin>>loginUser ->password;for (int i = 0; i < User::dataList.size(); i++) {if (strcmp(User::dataList[i]->username, loginUser ->username) == 0) {User::dataList[i] = loginUser;break;}}User::write();cout << "修改成功!\n";}
}
//是否存在判断
User* User::getOne(string name, string s) {for (int i = 0; i < dataList.size();i++) {if( strcmp(name.c_str(),"username")==0 && strcmp(s.c_str(), dataList[i]->username )==0){return dataList[i];}}return NULL;
}
//读取文件内的用户
void User::read() {FILE *fp = NULL;if (NULL == (fp = fopen("User.txt", "r")))//读打开{//文件不存在,不读取return;}//从文件读取数据dataList.clear();while (1)//读取{//新建用户对象User *t = new User;//读取数据到pif(fscanf(fp, "%s%s",t->username ,t->password ) == EOF) {break;}dataList.push_back(t);//将内容加入vector}fclose(fp);
}
//用户 写入文件
void User::write() {//打开文件FILE *fp = NULL;fp = fopen("User.txt", "w+");//写入for (int i = 0; i < dataList.size(); i++) {User *t = dataList.at(i);fprintf(fp,"%s %s\n",t->username ,t->password );}fclose(fp);
}
//用户 添加记录
void User::add() {char selectYNFlag = 'y';while(selectYNFlag == 'y' || selectYNFlag == 'Y' ){cout<<"\n";User *tempValue = new User (); //必须重新分配地址空间。cout<<"请输入用户名 :";char username[15]; cin>>username ;strcpy(tempValue->username,username);User* oneusername = getOne("username",tempValue->username);if(oneusername!=NULL){//检索不为空cout<<("用户名已存在!\n");break;}cout<<"请输入密码 :";char password[15]; cin>>password ;strcpy(tempValue->password,password);//TODO,//加入记录dataList.push_back(tempValue);cout<<"\n是否继续录入?(y/n)";getchar();cin>>selectYNFlag;}//写入文件write();cout<<"\n*****************************\n";cout<<"录入结束\n";cout<<"*****************************\n";
}
//用户 删除
void User::del() {cout<<"请输入您要删除的 用户 序号(输入-1退出):";char c;cin >> c;int index = c - '0';if (index >= 0 && index < dataList.size()) {dataList.erase(dataList.begin()+index);write();cout << "删除成功!\n\n";}else if(index>0){cout << "请输入正确序号!\n\n";}
}//用户 修改
void User::mod() {cout<<"请输入您要修改的用户 序号(输入-1退出):";char c;cin >> c;int indexOfMod = c - '0';if(indexOfMod >= 0 && indexOfMod < dataList.size() ){//开始修改User *temp = dataList.at(indexOfMod);cout<<"请输入密码 :";char password[15];cin>> password ;//输入完毕,赋值strcpy(temp-> password,password);cout<<"修改成功!\n";write();}else{cout<<"输入错误!\n";}
}
//用户 查找 如果all=1:查询全部 否则按条件查询
void User :: find(int all){int select = 0;char conCharArr[40];double conNum1,conNum2;//复制一个容器dataList2,查询的操作再dataList2里面进行vector<User*> dataList2 = dataList;while(1){printf("\n%-5s%-15s%-15s\n\n","序号" ,"用户名","密码" );int count = 0;//用于统计信息所用for(int i = 0;i < dataList2.size();i++){User* t = dataList2.at(i);if(select == 0|| select == 1 && strstr(t->username,conCharArr) //根据用户名,模糊查询){printf("%-5d%-15s%-15s \n\n",i,t->username,t->password);//用于统计信息所用count++;}else {dataList2.erase(dataList2.begin()+i);i--;}}cout<<"共"<< count <<"条结果\n";cout<<("-----------------------------------------------------------------------------------------------------\n");cout<<"\n";//如果参数all为1,则表示列出所有就退出if(all == 1)break;//进入过滤。cout<<"【筛选器:你可以在以上结果的基础上,进行以下条件筛选】\n";cout<<"0:退出\n";cout<<"1:按 用户名 筛选\n";cout<<"请输入选择:";cin>>select;if(select>0){if(0 ||select==1 ){cout<<"请输入筛选条件:";cin>>conCharArr;}else if(0 ){cout<<"请输入筛选范围m,n,用空格隔开(m ≤X ≤n):";cin>>conNum1;cin>>conNum2;}}else{break;}}
}
//用户 排序
void User::sort(){int select,i,j;cout<<"1:按 用户名 排序\n";cout<<"2:按 密码 排序\n";cout<<"请输入选择:";cin>>select;for (i = dataList.size() - 1; i > 0; i--) {for( j = 0;j < i;j++){if( 0|| select == 1 && compare(dataList[j]->username , dataList[j+1]->username )>0|| select == 2 && compare(dataList[j]->password , dataList[j+1]->password )>0){swap(dataList[j], dataList[j + 1]);}}}find(1);//排序后打印write();
}void menuUser (){//菜单cout<<"*------------------主菜单---------------------*\n";cout<<"*-------------1 :添加球员\n";cout<<"*-------------2 :删除球员\n";cout<<"*-------------3 :修改球员\n";cout<<"*-------------4 :查找球员\n";cout<<"*-------------5 :排序球员\n";cout<<"*-------------6 :查找用户\n";cout<<"*-------------7 :排序用户\n";cout<<"*-------------0:退出\n";cout<<"*------------(-1):登出\n";cout<<"*------------(-2):我的\n";cout<<"*---------------------------------------------*\n";cout<<"请输入选择:";}//对比函数
int compare(int a,int b){return a-b;
}
int compare(const char *a,const char *b){return strcmp(a,b);
}
系统部分截图
cout<<"*------------------主菜单---------------------*\n";
cout<<"*-------------1 :添加球员\n";
cout<<"*-------------2 :删除球员\n";
cout<<"*-------------3 :修改球员\n";
cout<<"*-------------4 :查找球员\n";
cout<<"*-------------5 :排序球员\n";
cout<<"*-------------6 :查找用户\n";
cout<<"*-------------7 :排序用户\n";
cout<<"*-------------0:退出\n";
cout<<"*------------(-1):登出\n";
cout<<"*------------(-2):我的\n";
cout<<"*---------------------------------------------*\n";
cout<<"请输入选择:";
这篇关于C/C++NBA球星数据的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!