当前位置:网站首页>将通讯录功能设置为数据库维护,增加用户名和密码
将通讯录功能设置为数据库维护,增加用户名和密码
2022-06-27 06:37:00 【CSDN问答】
问题遇到的现象和发生背景
将查询和排序改为动态链表
在主菜单界面中,将通讯录录入、删除、修改、添加功能合并为数据库维护功能,当选择此选项时,要求用户输入用户名和密码,如果设置数据库维护人员2人,则在程序中可相应设置2个用户名和密码,只有正确时,才进入下一级维护
问题相关代码,请勿粘贴截图
#include
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
typedef struct _TEL_INFO
{
int no;//编号
char name[20];//姓名
char tel_num[20];//电话号
char phone_num[20];//手机号
int code;//邮编
char add[20];//地址
char rela_ship[20];//关系
}TEL,*PTEL;
int menu()
{
int chioce;
system("cls");
printf("1:录入联系人\n");
printf("2:删除联系人\n");
printf("3:修改联系人\n");
printf("4:显示联系人\n");
printf("5:查询联系人\n");
printf("6:排序手机号\n");
printf("0:退出\n");
printf("请输入选择:");
scanf("%d",&chioce);
while(chioce<0||chioce>6)
{
printf("请重新选择:");
scanf("%d",&chioce);
}
return chioce;
}
void Print_TEL(PTEL TEL,int n)
{
int i;
for(i=0;i<n;i++)
{
printf("%10d",TEL[i].no);
printf("%10s",TEL[i].name);
printf("%20s",TEL[i].tel_num);
printf("%20s",TEL[i].phone_num);
printf("%10d",TEL[i].code);
printf("%20s",TEL[i].add);
printf("%20s\n",TEL[i].rela_ship);
}
}
int Delete_Tel(PTEL tel,int n)
{
int i,num,j;
char temp[20];
system("cls");
printf("请输入要删除的编号:");
scanf("%d",&num);
for(i=0;i<n;i++){ if(tel[i].no==num) { break; }}if(i==n){ printf("无该编号信息!\n"); system("pause"); return n;}Print_TEL(&tel[i],1);printf("确认删除?(Y/N):");
scanf("%s",temp);
if(!strcmp(temp,"Y")||!strcmp(temp,"y"))
{
for(j=i;j<n;j++)
{
tel[j]=tel[j+1];
}
printf("删除成功!\n");
system("pause");
return n-1;
}
else
{
printf("已取消删除!\n");
system("pause");
return n;
}
}
int Add_Tel(PTEL tel,int n)
{
int i,flag=0;
system("cls");
printf("请输入联系人编号:");
scanf("%d",&tel[n].no);
for(i=0;i<n;i++)
{
if(tel[i].no==tel[n].no)
{
flag=1;
break;
}
}
if(flag)
{
printf("已存在该编号!\n");
system("pause");
return n;
}
printf("请输入联系人姓名:");
scanf("%s",tel[n].name);
printf("请输入联系人电话:");
scanf("%s",tel[n].tel_num);
printf("请输入联系人手机:");
scanf("%s",tel[n].phone_num);
printf("请输入联系人邮编:");
scanf("%d",&tel[n].code);
printf("请输入联系人地址:");
scanf("%s",tel[n].add);
printf("请输入联系人关系:");
scanf("%s",tel[n].rela_ship);
printf("录入成功!\n");system("pause");return n+1;}
void Sort_And_Print(PTEL tel,int n)
{
int i,j;
TEL temp;
system("cls");
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(strcmp(tel[i].phone_num,tel[j].phone_num)>0)
{
temp = tel[i];
tel[i]=tel[j];
tel[j]=temp;
}
}
}
Print_TEL(tel,n);
system("pause");
}
void Sreach_Tel(PTEL tel,int n)
{
int i,num;
system("cls");
printf("请输入要查询的编号:");
scanf("%d",&num);
for(i=0;i<n;i++){ if(tel[i].no==num) { break; }}if(i==n){ printf("无该编号信息!\n"); system("pause"); return ;}Print_TEL(&tel[i],1);system("pause");}
void Save_File(TEL tel[],int n)
{
int i;
FILE* fp=fopen("tel.txt","w+");
if(fp==NULL)
{
return ;
}
for(i=0;i<n;i++)
{
fwrite(&tel[i],sizeof(TEL),1,fp);
}
fclose(fp);
}
int Open_File(TEL tel[])
{
int i=0;
FILE* fp=fopen("tel.txt","r+");
if(fp==NULL)
{
return 0;
}
while(fread(&tel[i],sizeof(TEL),1,fp))
{
i++;
}
return i;
}
void Modify_Tel_Menu(TEL tel[],int n)
{
int i,num,chioce;
system("cls");
printf("请输入要修改的编号:");
scanf("%d",&num);
for(i=0;i<n;i++){ if(tel[i].no==num) { break; }}if(i==n){ printf("无该编号信息!\n"); system("pause"); return ;}do{ system("cls"); Print_TEL(&tel[i],1); printf("1:修改姓名\n"); printf("2:修改电话\n"); printf("3:修改手机\n"); printf("4:修改邮编\n"); printf("5:修改地址\n"); printf("6:修改关系\n"); printf("0:返回主菜单\n"); printf("请输入选择:"); scanf("%d",&chioce); while(chioce<0||chioce>6) { printf("请重新选择:"); scanf("%d",&chioce); } switch(chioce) { case 1: printf("请输入新姓名:"); scanf("%s",tel[i].name); printf("修改成功!\n"); system("pause"); break; case 2: printf("请输入新电话:"); scanf("%s",tel[i].tel_num); printf("修改成功!\n"); system("pause"); break; case 3: printf("请输入新手机:"); scanf("%s",tel[i].phone_num); printf("修改成功!\n"); system("pause"); break; case 4: printf("请输入新邮编:"); scanf("%d",&tel[i].code); printf("修改成功!\n"); system("pause"); break; case 5: printf("请输入新地址:"); scanf("%s",tel[i].add); printf("修改成功!\n"); system("pause"); break; case 6: printf("请输入新关系:"); scanf("%s",tel[i].rela_ship); printf("修改成功!\n"); system("pause"); break; }}while(chioce!=0);}
int main(int argc,char* argv[])
{
int chioce;//记录选择
TEL tel[100];//保存职工信息
int NUM=0;//记录职工数量
NUM=Open_File(tel);
system("mode con: cols=120 lines=30");
do
{
chioce=menu();
switch(chioce)
{
case 1:
NUM=Add_Tel(tel,NUM);
Save_File(tel,NUM);
break;
case 2:
NUM=Delete_Tel(tel,NUM);
Save_File(tel,NUM);
break;
case 3:
Modify_Tel_Menu(tel,NUM);
Save_File(tel,NUM);
break;
case 4:
system("cls");
Print_TEL(tel,NUM);
system("pause");
break;
case 5:
Sreach_Tel(tel,NUM);
break;
case 6:
Sort_And_Print(tel,NUM);
break;
}
}while(chioce!=0);
return 0;}
运行结果及报错内容
无
我的解答思路和尝试过的方法
不知道数据库维护功能的加密办法,密码用字符串,动态链表的修改
我想要达到的结果
边栏推荐
猜你喜欢

Active learning

面试官:用分库分表如何做到永不迁移数据和避免热点问题?

thrift

2022 CISP-PTE(一)文件包含

Yolov6's fast and accurate target detection framework is open source
[email protected][2389:1: columnNameTypeOrConstraint : ( ( tableConstraint ) | ( columnNameT"/>NoViableAltException([email protected][2389:1: columnNameTypeOrConstraint : ( ( tableConstraint ) | ( columnNameT

Scala函数柯里化(Currying)

快速实现蓝牙iBeacn功能详解

Configuring FTP, enterprise official website, database and other methods for ECS

内存屏障今生之Store Buffer, Invalid Queue
随机推荐
路由器和交换机的区别
【LeetCode】Day90-二叉搜索树中第K小的元素
Classical cryptosystem -- substitution and replacement
研究生数学建模竞赛-无人机在抢险救灾中的优化应用
The number of query results of maxcompute SQL is limited to 1W
[QT dot] realize the watchdog function to detect whether the external program is running
Spark sql 常用时间函数
The risk of multithreading -- thread safety
The song of cactus -- throwing stones to ask the way (1)
Thesis reading skills
Inter thread wait and wake-up mechanism, singleton mode, blocking queue, timer
SQL injection bypass (I)
TiDB与 MySQL 兼容性对比
YOLOv6又快又准的目标检测框架 已开源
Scala之偏函数Partial Function
HTAP in depth exploration Guide
Spark SQL common time functions
[graduation season] graduation is the new beginning of your life journey. Are you ready
TiDB的事务概览
ORA-00909: 参数个数无效,concat引起