当前位置:网站首页>Set the address book function to database maintenance, and add user name and password
Set the address book function to database maintenance, and add user name and password
2022-06-27 07:40:00 【CSDN Q & A】
The phenomenon and background of the problem
Change query and sorting to dynamic linked list
In the main menu interface , Enter the address book 、 Delete 、 modify 、 Add functions and merge them into database maintenance functions , When this option is selected , Ask the user to enter the user name and password , If you set the database maintenance personnel 2 people , Can be set in the program accordingly 2 User name and password , Only when it's right , Before entering the next level of maintenance
Problem related code , Do not paste screenshots
#include
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
typedef struct _TEL_INFO
{
int no;// Number
char name[20];// full name
char tel_num[20];// Phone number
char phone_num[20];// cell-phone number
int code;// Zip code
char add[20];// Address
char rela_ship[20];// Relationship
}TEL,*PTEL;
int menu()
{
int chioce;
system("cls");
printf("1: Enter contact \n");
printf("2: Delete Contact \n");
printf("3: Modify contact \n");
printf("4: Show contacts \n");
printf("5: Query contact \n");
printf("6: Sort phone numbers \n");
printf("0: sign out \n");
printf(" Please enter the selection :");
scanf("%d",&chioce);
while(chioce<0||chioce>6)
{
printf(" Please reselect :");
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(" Please enter the number to delete :");
scanf("%d",&num);
for(i=0;i<n;i++){ if(tel[i].no==num) { break; }}if(i==n){ printf(" No such number information !\n"); system("pause"); return n;}Print_TEL(&tel[i],1);printf(" confirm deletion ?(Y/N):");
scanf("%s",temp);
if(!strcmp(temp,"Y")||!strcmp(temp,"y"))
{
for(j=i;j<n;j++)
{
tel[j]=tel[j+1];
}
printf(" Delete successful !\n");
system("pause");
return n-1;
}
else
{
printf(" Delete cancelled !\n");
system("pause");
return n;
}
}
int Add_Tel(PTEL tel,int n)
{
int i,flag=0;
system("cls");
printf(" Please enter the contact number :");
scanf("%d",&tel[n].no);
for(i=0;i<n;i++)
{
if(tel[i].no==tel[n].no)
{
flag=1;
break;
}
}
if(flag)
{
printf(" The number already exists !\n");
system("pause");
return n;
}
printf(" Please enter the contact name :");
scanf("%s",tel[n].name);
printf(" Please enter the contact number :");
scanf("%s",tel[n].tel_num);
printf(" Please enter the contact phone :");
scanf("%s",tel[n].phone_num);
printf(" Please enter the contact postal code :");
scanf("%d",&tel[n].code);
printf(" Please enter contact address :");
scanf("%s",tel[n].add);
printf(" Please enter the contact relationship :");
scanf("%s",tel[n].rela_ship);
printf(" Input succeeded !\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(" Please enter the number to query :");
scanf("%d",&num);
for(i=0;i<n;i++){ if(tel[i].no==num) { break; }}if(i==n){ printf(" No such number information !\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(" Please enter the number to be modified :");
scanf("%d",&num);
for(i=0;i<n;i++){ if(tel[i].no==num) { break; }}if(i==n){ printf(" No such number information !\n"); system("pause"); return ;}do{ system("cls"); Print_TEL(&tel[i],1); printf("1: Change the name \n"); printf("2: Change the phone number \n"); printf("3: Modify your phone \n"); printf("4: Modify zip code \n"); printf("5: Change address \n"); printf("6: Modify the relationship \n"); printf("0: Back to main menu \n"); printf(" Please enter the selection :"); scanf("%d",&chioce); while(chioce<0||chioce>6) { printf(" Please reselect :"); scanf("%d",&chioce); } switch(chioce) { case 1: printf(" Please enter a new name :"); scanf("%s",tel[i].name); printf(" Modification successful !\n"); system("pause"); break; case 2: printf(" Please enter a new phone number :"); scanf("%s",tel[i].tel_num); printf(" Modification successful !\n"); system("pause"); break; case 3: printf(" Please enter a new phone :"); scanf("%s",tel[i].phone_num); printf(" Modification successful !\n"); system("pause"); break; case 4: printf(" Please enter a new zip code :"); scanf("%d",&tel[i].code); printf(" Modification successful !\n"); system("pause"); break; case 5: printf(" Please enter a new address :"); scanf("%s",tel[i].add); printf(" Modification successful !\n"); system("pause"); break; case 6: printf(" Please enter a new relationship :"); scanf("%s",tel[i].rela_ship); printf(" Modification successful !\n"); system("pause"); break; }}while(chioce!=0);}
int main(int argc,char* argv[])
{
int chioce;// Record selection
TEL tel[100];// Save employee information
int NUM=0;// Record the number of employees
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;}
Operation results and error reporting contents
nothing
My solution ideas and tried methods
Do not know the encryption method of database maintenance function , Password string , Modification of dynamic linked list
What I want to achieve
边栏推荐
- 语音信号处理-概念(二):幅度谱(短时傅里叶变换谱/STFT spectrum)、梅尔谱(Mel spectrum)【语音的深度学习主要用幅度谱、梅尔谱】【用librosa或torchaudio提取】
- R 中的 RNA-Seq 数据分析 - 调查数据中的差异表达基因!
- 磁选机是什么?
- yarn create vite 报错 ‘D:\Program‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件
- 游戏六边形地图的实现
- How torch. gather works
- guava 教程收集一些案例慢慢写 google工具类
- JS to determine whether the result is qualified, the range is 0-100, otherwise re-enter
- One person manages 1000 servers? This automatic operation and maintenance tool must be mastered
- 【软件工程】山东大学软件工程复习提纲
猜你喜欢

js来打印1-100间的质数并求总个数优化版
![log4j:WARN No such property [zipPermission] in org. apache. log4j. RollingFileAppender.](/img/2c/425993cef31dd4c786f9cc5ff081ef.png)
log4j:WARN No such property [zipPermission] in org. apache. log4j. RollingFileAppender.

Rust Async: smol源码分析-Executor篇

JS print 99 multiplication table

js中输入三个值,并且由小到大输出

2. QT components used in the project

File 与 MultipartFile概述

File and multipartfile overview

Cookie encryption 6

js中判断成绩是否合格,范围在0-100,否则重新输入
随机推荐
How torch. gather works
1-4 decimal representation and conversion
js来打印1-100间的质数并求总个数优化版
程序人生 - 程序员三十五岁瓶颈你怎么看?
Jupiter notebook file directory
延时队列`DelayQueue`
正斜杠反斜杠的由来
hutool对称加密
PostgreSQL encounters permission denied in Windows system
2、项目使用的QT组件
JS performance reward and punishment examples
碎煤机crusher
JDBC事务提交事例
What is a magnetic separator?
Installation and functions of uview
Stream常用操作以及原理探索
[Software Engineering] software engineering review outline of Shandong University
什么是浮选机?
What is the difference between volatile and synchronized?
在线文本数字识别列表求和工具