Address book management system

Time:2021-1-26

//Clear screen center function
#include
#include
#include
#include
#define N 10
Int t = 0, a = 0, q = 1, m; / / T is the number of people deleted, a is the serial number
int flag=0;
struct Person{
Char number [20]; / / student number
Char name [20]; / / name
Char mail [20]; / / email
Char address [20]; / / address
Char Tel [15]; / / contact number
}student[N];
int main()
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
void first(void);
void input(int );
void show(int );
void del(int );
void search(int );
void update(int );
void add(int );
void screen(int );
int i;
if(q==1)
{
q=q-1;
first();
}
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY |COMMON_LVB_GRID_HORIZONTAL| FOREGROUND_RED|FOREGROUND_BLUE);
printf(“\t\t\t******************************************************************\n”);
Printf (“welcome to the address book management system” * “;
printf(“\t\t\t*******Welcome to use the student status management system********\n”);
printf(“\t\t\t******************************************************************\n”);
do
{
SetConsoleTextAttribute(handle, COMMON_LVB_GRID_HORIZONTAL|FOREGROUND_BLUE);
Printf (“- main menu ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^;
printf(“\t\t\t\t**********************************************\t\t\t\t\t\t\t\n”);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“\t\t\t\t******\t\t”);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
Printf (“0;
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“\t\t******\t\t\t\t\t\t\t\n”);
printf(“\t\t\t\t******\t\t”);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
Printf (“1;
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“\t\t******\t\t\t\t\t\t\t\n”);
printf(“\t\t\t\t******\t\t”);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
Printf (“2. Delete address book”);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“\t\t******\t\t\t\t\t\t\t\n”);
printf(“\t\t\t\t******\t\t”);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
Printf (“3;
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“\t\t******\t\t\t\t\t\t\t\n”);
printf(“\t\t\t\t******\t\t”); 
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
Printf (“4;
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“\t\t******\t\t\t\t\t\t\t\n”);
printf(“\t\t\t\t******\t\t”);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
Printf (“5. Add address book”)
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“\t\t******\t\t\t\t\t\t\t\n”);
printf(“\t\t\t\t******\t\t”);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
Printf (“6;
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“\t\t******\t\t\t\t\t\t\t\n”);
printf(“\t\t\t\t******\t\t”);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
Printf (“7;
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“\t\t******\t\t\t\t\t\t\t\n”);
SetConsoleTextAttribute(handle,COMMON_LVB_UNDERSCORE| FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“\t\t\t\t******\t\t”);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
Printf (“please enter options 0-7”);
SetConsoleTextAttribute(handle, COMMON_LVB_UNDERSCORE|FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“\t\t******\t\t\t\t\t\t\t\n”);
SetConsoleTextAttribute(handle, COMMON_LVB_UNDERSCORE|FOREGROUND_INTENSITY | FOREGROUND_BLUE);
printf(“\t\t\t\t***********************************************\n”);
SetConsoleTextAttribute(handle,FOREGROUND_GREEN| FOREGROUND_RED );
Scanf (% d “, & I); / / accept user selection
switch(i)
{
case 0: input(a);a++;
break;
case 1: show(a);
break;
case 2: del(a);
break;
case 3: search(a);
break;
case 4: update(a);
break;
case 5: add(a);a++;
break;
case 6: screen(a);
break; 
case 7: {
Printf (“thank you for using!!”!!! “);exit (0);}

Default: printf (“wrong choice! Please re-select ‘; break;
}
}
while(i!=7);
return 0;
}

//0. Write a function to input student number, name, personal email, address and contact number.
void input(int a)
{
int i;
Printf (“input student number: n”);
Scanf (% s “, student [a]. Number); / / enter student number to query
for(i=0;i{
if(strcmp(student[i].number,student[a].number)==0)
{
Printf (“this student number exists in the address book, please do not enter it repeatedly!”;
main();
}
}
Printf (“enter name: n”);
scanf(“%s”,student[a].name);
Printf (“input personal e-mail address: n”);
scanf(“%s”,student[a].mail);
Printf (“input address: n”);
scanf(“%s”,student[a].address);
Printf (“enter contact number: n”);
scanf(“%s”,student[a].tel);
Printf (“entered successfully!”!!! \n”);
Printf (“the system returns to the main menu in 3 seconds… \ n”);
sleep(3);
system(“cls”);
}

//1. Write a function to display the information of all personnel.
void show(int a)
{
system(“cls”);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
int i;
if(a-T == 0)
{SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
Printf (“- no display object in the address book”;
Printf (“will automatically jump back to the main menu in 10 seconds…”;
sleep(5);
system(“cls”);
main();
}
else
{
SetConsoleTextAttribute(handle, FOREGROUND_RED| FOREGROUND_GREEN);
Printf (“- student number, name, personal e-mail, address, telephone number, etc.);
SetConsoleTextAttribute(handle,FOREGROUND_GREEN);
for(i=0;iprintf(“%13s %13s %13s %26s %13s\n”,student[i].number,student[i].name,student[i].mail,student[i].address,student[i].tel);
}
}

//2. Write a function to find the person information to be deleted by entering the name or student number, and then delete it,
//Echo the current address book information.
void del(int a)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
int i,j,o,u;
char s[20],x[20],c[20];
if(a-T==0)
{
Printf (“the address book is empty and cannot be operated!”;
Printf (“the system will return to the main menu by default after 10 seconds……”;
sleep(5);
system(“cls”);
main();
}
else
{
Printf (“press * to select one key to delete all, press any key to delete the selected student (s):”;
scanf(“%s”,s);
if(strcmp(s,”*”) == 0 )
{
Printf (“press * to continue, one key to delete all, press any key to return to the main menu: \;
scanf(“%s”,c);
if(strcmp(c,”*”) == 0 )
{
for(u=0,o=a;u{
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
strcpy(student[u].name,student[o].name);
strcpy(student[u].number,student[o].number);
strcpy(student[u].mail,student[o].mail);
strcpy(student[u].address,student[o].address);
strcpy(student[u].tel,student[o].tel);
}
T=a;
SetConsoleTextAttribute(handle,FOREGROUND_GREEN);
Printf (“operation succeeded!!! \ n”);
sleep(2);
}
else
main(); 
}
else
{
char x[20];
Printf (“please enter the name or student number of the student you want to delete”:;
scanf(“%s”,x);
for(i=0;i{
if((strcmp(x,student[i].name)==0)||(strcmp(x,student[i].number)==0))
{
for(j=i;j{
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
strcpy(student[j].name,student[j+1].name);
strcpy(student[j].number,student[j+1].number);
strcpy(student[j].mail,student[j+1].mail);
strcpy(student[j].address,student[j+1].address);
strcpy(student[j].tel,student[j+1].tel);
}
T++;
break;
}
}
system(“cls”);
Printf (“operation succeeded!!! \ n”);
}
}
}

//3. Write a function to find students’ information by inputting their names or student numbers.
void search(int a)
{
int i;
char x[20],s[20],b[20];
if(a-T== 0 )
{
Printf (“the address book is empty and cannot be queried;”;
Printf (“after 10 seconds, the system will return to the main menu by default”);
sleep(3);
system(“cls”);
main();

else
{
Printf (“please enter the name or student number you want to inquire about):”;
scanf(“%s”,x);
for(i=0;i{
if((strcmp(x,student[i].name)==0)||(strcmp(x,student[i].number)==0))
{
Printf (“student No.:% s, student [i]. Number)”;
Printf (“Name: s, student [i]. Name”);
Printf (“personal e-mail address: S / N”, student [i]. Mail) “;
Printf (“address: S / N”, student [i]. Address) “;
Printf (“contact number: S / N”, student [i]. TEL) “;
Printf (“press the * key to return to the main menu, and press any key to continue the query:;
scanf(“%s”,s);
if((strcmp(s,”*”)==0))
{system(“cls”);break;}
else
search(a);
}
else if(i == a-T-i)
{
Printf (“did not query this contact!! \n”);
Printf (“press any key to re query the input, and enter * to return to the main menu:;
scanf(“%s”,b);
if(strcmp(b,”*”) == 0)
{
system(“cls”);
main();
}
else 
search (a);
}
}
}
}
//4. Write a function to find the personnel information to be modified by entering the name or student number, and then carry out the information processing in turn
//Modification.
void update(int a)
{
int i,j;
char x[20],s[20];
Printf (“please enter the name or student number of the student you want to modify”:;
if(a== 0 )
{
Printf (“no one in the address book, can’t operate it!”;
Printf (“the system will automatically return to the main menu in 1 second…”;
sleep(5);
system(“cls”);
main();
}
else
{
scanf(“%s”,x);
for(i=0;i{
if((strcmp(x,student[i].name)==0)||(strcmp(x,student[i].number)==0))
{
for(j=i;j{
Printf (“please enter the information of the person you want to modify”:;
Printf (“please enter the first name):”;
scanf(“%s”,student[j].name);
Printf (“please enter your email address as follows:;
scanf(“%s”,student[j].mail);
Printf (“please enter the address: ‘);
scanf(“%s”,student[j].address);
Printf (“please enter phone number::)
scanf(“%s”,student[j].tel);
break;
}
Printf (“modified successfully! \n”);
Printf (“continue to modify, press any key to return to the main menu and enter *: \ n”);
scanf(“%s”,s);
if(strcmp(s,”*”) == 0)
{
system(“cls”);
main();
}
else
{
system(“cls”);
update(a);
}
}
else
{
Printf (“there is no person in this list”);
Printf (“please re-enter: ‘);
update (a);
}
main();
}
}
}

//5. Write a function to add personnel information.
void add(int a) 
{
int z,i;
char s[20];
Printf (“please enter the information of the person you want to add”:
if(a-T==0)
{
Printf (“no contact, please add the first person’s information now”);
Printf (“the added student number is::);
scanf(“%s”,student[0].number);
Printf (“added name is::);
scanf(“%s”,student[0].name);
Printf (“added address is::);
scanf(“%s”,student[0].address);
Printf (“the added mailbox is::);
scanf(“%s”,student[0].mail);
Printf (“the added phone number is::);
scanf(“%s”,student[0].tel);
Printf (“press any key to continue input, enter * to return to the main menu;”;
scanf(“%s”,s);
if(strcmp(s,”*”) == 0)
{
Printf (“will return to the main menu in 10 seconds… \ n”);
sleep(3);
system(“cls”);
}
else//
add(a);
}
else 
{
Printf (“if the ordinal number is 0 to% D, insert the ordinal number of the person to::” n “, a)”;
scanf(“%d”,&z);
for(i=a-1;i>=z;i–)
{
strcpy(student[i+1].address,student[i].address);
strcpy(student[i+1].mail,student[i].mail);
strcpy(student[i+1].name,student[i].name);
strcpy(student[i+1].number,student[i].number);
strcpy(student[i+1].tel,student[i].tel);
}
Printf (“the added student number is::);
scanf(“%s”,student[z].number);
Printf (“added name is::);
scanf(“%s”,student[z].name);
Printf (“added address is::);
scanf(“%s”,student[z].address);
Printf (“the added mailbox is::);
scanf(“%s”,student[z].mail);
Printf (“the added phone number is::);
scanf(“%s”,student[z].tel);
}
system(“cls”);
}

//Screening people from the same place or name
void screen(int a)
{
void screena(int a);
void screenb(int a);
int n,i;
char s[20];
if(a==0)
{
Printf (“there is no information in the address book, so it cannot be filtered!”;
Printf (“the system will automatically return to the main menu in 3 seconds…”;
sleep(3);
system(“cls”);
main();
}
else
{
Printf (“please select by region or by name”);
Printf (“district screening is 0, name screening is 1 / N”);
scanf(“%d”,&n);
if(n==0)
screena (a);
else
screenb (a);
}
}
Void screen (int a) / / region screening
{
int n=0,i,flag=0;
char s[20],x[20];
Printf (“please enter the address of the query):”;
scanf(“%s”,s);
for(i=0;i{
if(strcmp(s,student[i].address) == 0)
{
Printf (“student No.:% s, student [i]. Number)”;
Printf (“Name: s, student [i]. Name”);
Printf (“personal e-mail address: S / N”, student [i]. Mail) “;
Printf (“address: S / N”, student [i]. Address) “;
Printf (“contact number: S / N”, student [i]. TEL) “;
printf(“\n”);
flag=1;n++;continue;
}
}
if(flag==1)
{
Printf (“there are% d people under this address in total”, n) “;
main();
}
else
{
Printf (“this address is empty”);
Printf (“please press any key to re-enter the address or press the * key to return to the main menu:;
scanf(“%s”,x);
if(strcmp(x,”*”) == 0)
{
sleep(1);system(“cls”);
main();
}
else
screena (a);
}
}

Void screenb (int a) / / name filtering
{
char s[20];
Printf (“you do not have this operation permission, please contact the administrator……”;
Printf (“please select an operation: press any key to return to the previous operation, enter * key to return to the main menu;”;
scanf(“%s”,s);
if(strcmp(s,”*”)==0)
{
Printf (“return to main menu in 3 seconds…”;
sleep(3);
system(“cls”);
main();
}
else
{
printf(“\n”);
screen (a);
}
}

void first(void)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
int n=0;
printf(“\n\n\n\n”);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“\t\t**********************************************************************************\n”);
printf(“\t\t**********************************************************************************\n”);
printf(“\t\t** **\n”);
printf(“\t\t** **\n”);
printf(“\t\t**”);
SetConsoleTextAttribute(handle,FOREGROUND_RED|FOREGROUND_GREEN);
Printf (“welcome to the address book management system”);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(“**\n”);
printf(“\t\t** “);
SetConsoleTextAttribute(handle,FOREGROUND_RED|FOREGROUND_GREEN);
printf(“\tWelcome to use the student status management system”);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(” **\n”);
printf(“\t\t** **\n”);
printf(“\t\t** “);
SetConsoleTextAttribute(handle,FOREGROUND_RED|FOREGROUND_GREEN);
Printf (“producer: xxx xxx xxx xxx xxx xxx xxx”);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf(” **\n”);
printf(“\t\t** **\n”);
printf(“\t\t** **\n”);
printf(“\t\t**********************************************************************************\n”);
printf(“\t\t**********************************************************************************\n”);
sleep(5);
system(“cls”);
}