当前位置:网站首页>将通讯录功能设置为数据库维护,增加用户名和密码
将通讯录功能设置为数据库维护,增加用户名和密码
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;
}
运行结果及报错内容
无
我的解答思路和尝试过的方法
不知道数据库维护功能的加密办法,密码用字符串,动态链表的修改
我想要达到的结果
边栏推荐
猜你喜欢
Modeling competition - optical transport network modeling and value evaluation
Machine learning
POI 替换docx中的文字和图片
2022 CISP-PTE(一)文件包含
DMU software syntax highlighting VIM setting -- Learning Notes 6
Centos7.9 install MySQL 5.7 and set startup
Redis cache penetration, cache breakdown, cache avalanche
云服务器配置ftp、企业官网、数据库等方法
Classical cryptosystem -- substitution and replacement
2022 le fichier CISP - Pte (i) contient:
随机推荐
可扩展哈希
Overview of database schema in tidb
The interviewer of a large front-line factory asked: do you really understand e-commerce order development?
日期 数据库日期 字符串 之间互相转换
0.0.0.0:x的含义
路由器和交换机的区别
2018年数学建模竞赛-高温作业专用服装设计
快速实现Thread Mesh组网详解
Ora-00909: invalid number of parameters, caused by concat
thrift
Fast realization of Bluetooth communication between MCU and mobile phone
winow10安装Nexus nexus-3.20.1-01
快速实现蓝牙iBeacn功能详解
From 5 seconds to 1 second, the system flies
获取地址url中的query参数指定参数方法
Modeling competition - optical transport network modeling and value evaluation
Scala advanced_ Member access modifier
[openairinterface5g] rrcsetupcomplete for RRC NR resolution
Get the query parameter in the address URL specify the parameter method
Date database date strings are converted to and from each other