Current location - Education and Training Encyclopedia - Graduation thesis - Writing the Student Address Book Management System with C++
Writing the Student Address Book Management System with C++
# include & ltstdio.h & gt

# include & ltstdlib.h & gt

# include & ltstring.h & gt

# Define the format "%s\t\t%s\t\t%s\t%d\t%s\n"

int count = 0;

Structural address

{

char Name[2 1];

int Age

char Sex[6];

char class num[ 1 1];

char phon num[ 12];

};

int enter face();

Int Add (address book []);

Int Modify (address book []);

Int Delent (address book []);

Int Insert (address book []);

Int Find (address book []);

Int Show (address book []);

Int FindName (address book []);

Int FindClassNum (address book []);

Int DelName (address book []);

Int DelClassNum (address book []);

Intfindhonnum (address book []);

Int Readtxt (address book []);

Int Writetxt (address book []);

Int Search (address book [], char str 1[], int n);

Int FSearch (address book [], char str2[], int n);

Inttaxi (address book []);

int Exit();

////////////////////////////////////////////////////////////////////

void main()

{

Address book [100];

Int selection;

char or = ' m

printf(" \ n ");

printf(" \ n ");

printf(" \ n ");

printf(" \ n ");

printf(" \ n ");

printf(" \ n ");

printf(" \ n ");

printf(" \ \ \ \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" n ");

printf(" \ n ");

printf(! ! ! Welcome to the class address book system! ! ! \ n ");

printf(" \ n ");

printf(! ! ! Press any key to enter the system! ! ! \ n ");

printf(" \ n ");

printf(! ! ! Administrator: * * * *! ! ! \ n ");

printf(" \ n ");

printf("//////////////////////////////////////////////////\ n ");

System ("suspended");

System ("CLS");

Readtxt (book);

while(or=='m ')

{

choice = enter face();

Switch (selection)

{

Case 1: add (book);

Break;

Case 2: Revision (book);

Break;

Case 3: Drenthe (book);

Break;

Case 4: Insert (book);

Break;

Case 5: find (book);

Break;

Case 6: Show (book);

Break;

Case 7: exit ();

Break;

Default value: printf (! idspninfopath)。 ! ! Input error! ! ! \ n ");

exit();

Break;

}

}

}

int Enterface()

{

int choice = 0;

printf(" * * * * * * * * * * * * * * * * * \ n ");

Printf(" 1。 add \ n ");

Printf(" 2。 Modify \ n ");

Printf(" 3。 Delete \ n ");

Printf(" 4。 insert \ n ");

Printf(" 5。 Find \ n ");

Printf(" 6。 display \ n ");

Printf(" 7。 Exit \ n ");

printf(" * * * * * * * * * * * * * * * * * \ n ");

Printf ("Please enter your choice:");

Scanf("%d ",& select);

Regression selection;

}

Int Add (address book [])

{

char or = ' Y

while('Y'==or)

{

Printf ("Please enter your name:");

Scanf("%s ",& book [number]. Name);

flag 1:

Printf ("Please enter phone number:");

Scanf("%s ",& book [number]. phon num);

for(int I = 0; I < count; i++)

{

if(strcmp(book[count])。 PhonNum, book [i] PhonNum)==0)

{

printf(! ! ! This number already exists! ! ! \ n ");

goto flag 1;

}

}

Sign 2:

Printf ("Please enter your student number:");

Scanf("%s ",& book [number]. class num);

for(I = 0; I < count; i++)

{

if(strcmp(book[count])。 ClassNum,book[i]。 ClassNum)==0)

{

printf(! ! ! Student ID already exists! ! ! \ n ");

Go to flag2.

}

}

Printf ("Please enter age:");

Scanf("%d ",& book [number]. Age);

Printf ("Please enter gender:");

Scanf("%s ",& book [number]. Sex);

getchar();

count++;

Printf ("Do you want to continue adding ('y' to add, and other keys will return to the main interface):");

Scanf("%c ",&or);

if('Y '! = or)

{

System ("CLS");

Break;

}

}

Taxi (book);

Writetxt (book);

//printf(" sdfsdfsdf \ n ");

Returns 0;

}

Int modification (address book [])

{

char str[ 1 1];

int flag = 0;

int ksd = 0;

Printf ("Student ID entered last year:");

scanf("%s ",& ampstr);

for(int I = 0; I < count; i++)

{

if(strcmp(str,book[i])。 ClassNum)==0)

{

If (ksd==0)

{

Printf(" Name \ t phone \ t \ t \ t student id \ tsex \ tage \ n ");

ksd = 1;

}

printf("%8s\t%8s\t%s\t%s\t%d\n ",book[i]。 Name, book [me]. Peak number,

Book [me]. ClassNum,book[i]。 Sex, books [me]. Age);

//str[flag _ num++]= I;

flag = 1;

//I-;

Break;

}

}

If (flag ==0)

{

printf(! ! ! There is no such record! ! ! \ n ");

Returns 0;

}

Printf ("Please enter your name:");

Scanf("%s ",& Book [me]. Name);

Flag 0:

Printf ("Please enter phone number:");

Scanf("%s ",& Book [me]. phon num);

for(int j = 0; J< counting; j++)

{

If (j==i)

Continue;

If(strcmp (book [i]). PhonNum, book [j]. PhonNum)==0)

{

printf(! ! ! This number already exists! ! ! \ n ");

Go to flag0.

}

}

Sign 3:

Printf ("Please enter your student number:");

Scanf("%s ",& Book [me]. class num);

for(j = 0; J< counting; j++)

{

If (j==i)

Continue;

If(strcmp (book [i]). ClassNum,book[j]。 ClassNum)==0)

{

printf(! ! ! Student ID already exists! ! ! \ n ");

Go to flag3

}

}

Printf ("Please enter age:");

Scanf("%d ",& Book [me]. Age);

Printf ("Please enter gender:");

Scanf("%s ",& Book [me]. Sex);

getchar();

Printf ("Modify! \ n ");

Writetxt (book);

System ("suspended");

//printf(" modify \ n ");

Returns 0;

}

Int Delent (address book [])

{

//printf(" delent \ n ");

int choice = 0;

printf(" = = = = = = = = = = = = = = = = = \ n ");

Printf(" 1。 Delete by name \ n ");

Printf(" 2。 Delete by student number \ n ");

printf(" = = = = = = = = = = = = = = = = = \ n ");

Scanf("%d ",& select);

Switch (selection)

{

Case 1: DelName (book);

Break;

Case 2: DelClassNum (book);

Break;

Default value:

Break;

}

Returns 0;

}

Int Insert (address book [])

{

To add (a book);

//printf(" insert \ n ");

Returns 0;

}

Int Find (address book [])

{

int choice = 0;

printf(" = = = = = = = = = = = = = = = = = \ n ");

Printf(" 1。 Search by name \ n ");

Printf(" 2。 Search by student number \ n ");

Printf(" 3。 Phone lookup \ n ");

printf(" = = = = = = = = = = = = = = = = = \ n ");

Scanf("%d ",& select);

Switch (selection)

{

Case1:find name (book);

Break;

Case 2: FindClassNum (book);

Break;

Case 3: FindPhonNum (book);

Break;

Default value:

Break;

}

//printf(" find \ n ");

Returns 0;

}

Int FindName (address book [])

{

char aname[30];

Printf ("Please enter the name you want to find:");

scanf("%s ",& ampaname);

FSearch(book,aname,3);

Returns 0;

}

Int FindClassNum (address book [])

{

char anum[20];

Printf ("Please enter the student number you are looking for:");

scanf("%s ",& ampanum);

FSearch(book,anum,2);

Returns 0;

}

Intfindhonnum (address book [])

{

char aphonnum〔20〕;

Printf ("Please enter the student number you are looking for:");

Scanf("%s ",& aphonia);

FSearch(book,aphonnum, 1);

Returns 0;

}

Int Show (address book [])

{

Int or = 0;

if(count==0)

{

printf(! ! ! There is no record! ! ! \ n ");

System ("suspended");

System ("CLS");

}

other

{

Printf(" Name \ t phone \ t \ t \ t student id \ tsex \ tage \ n ");

for(int I = 0; I < count; i++)

printf("%8s\t%8s\t%s\t%s\t%d\n ",book[i]。 Name, book [me]. Peak number,

Book [me]. ClassNum,book[i]。 Sex, books [me]. Age);

System ("suspended");

}

Printf ("Sort? \n-= 1。 Sorting =-= 2. Return to main interface =-\ n ");

Scanf("%d ",&or);

If( 1 = = or)

Taxi (book);

Returns 0;

}

Int DelName (address book [])

{

char aname[20];

Printf ("Please enter the name to delete:");

scanf("%s ",& ampaname);

Search (book, aname, 2);

Returns 0;

}

Int DelClassNum (address book [])

{

char anum[20];

Printf ("Please enter the student number to be deleted:");

scanf("%s ",& ampanum);

Search (book, anum,1);

Returns 0;

}

Int Readtxt (address book [])

{

FILE * FP 1;

FP 1 = fopen(" photo numbers . txt "," r ");

if(fp 1 == NULL)

{

Printf ("Wrong! \ n ");

System ("suspended");

}

And (! feof(fp 1))

{

If (! fscanf(fp 1," %s\t\t%s\t\t%s\t%d\t%s ",book[count]。 Names, books [numbers]. Peak number,

Books [numbers]. ClassNum & amp; Books [numbers]. Age, books [number]. Sex))

Printf ("Reading error!" );

count++;

}

count-;

fclose(FP 1);

Returns 0;

}

Int Writetxt (address book [])

{

FILE * fp

fp=fopen("photonumbers.txt "," w ");

for(int I = 0; I < count; i++)

{

fprintf(fp,FORMAT,book[i])。 Name, book [me]. Peak number,

Book [me]. ClassNum,book[i]。 Age, book [me]. Sex);

}

fclose(FP);

Returns 0;

}

Int Search (address book [], char str 1[], int n)

{

int flag = 0;

int str[5];

int flag _ num = 0;

int j;

int gf

int ksd = 0;

for(int I = 0; I < count; i++)

{

If (n== 1)

{

if(strcmp(str 1,book[i])。 ClassNum)==0)

flag = 2;

}

else if(n==2)

{

if(strcmp(str 1,book[i])。 Name)==0)

flag = 2;

}

if(flag==2)

{

If (ksd==0)

{

Printf(" Name \ t phone \ t \ t \ t student id \ tsex \ tage \ n ");

ksd = 1;

}

printf("%8s\t%8s\t%s\t%s\t%d\n ",book[i]。 Name, book [me]. Peak number,

Book [me]. ClassNum,book[i]。 Sex, books [me]. Age);

str[flag _ num++]= I;

flag = 1;

}

}

If (flag ==0)

{

printf(! ! ! There is no record! ! ! \ n ");

System ("suspended");

System ("CLS");

}

if(flag== 1)

{

Printf("-= 1。 Confirm deletion =-\t-=2. cancel =-\ n ");

scanf("%d ",& ampj);

if( 1==j)

{

gf = 1;

for(int m = str[0]; M< Count-Flag _ Quantity; m++)

{

for(int j = gf- 1; J < flag _ number; j++)

{

if((m+gf)==str[j])

gf++;

}

Strcpy (book [m]. Name, book [m+gf]. Name);

Book [m] Age = book [m+gf]. Age;

Strcpy (book [m].ClassNum, book[m+gf]. class num);

Strcpy (book [m].PhonNum, book[m+gf]. phon num);

Strcpy (book [m]. Sex, book [m+gf]. Sex);

}

Count = Count-Flag _ Quantity;

Writetxt (book);

}

else if(2==j)

{

printf(! ! ! Operation cancelled! ! ! \ n ");

}

System ("suspended");

}

Returns 0;

}

Int FSearch (address book [], character str2[], int n)

{

int flag = 0;

int ksd = 0;

for(int I = 0; I < count; i++)

{

If (n== 1)

{

if(strcmp(str2,book[i])。 PhonNum)==0)

flag = 2;

}

else if(3==n)

{

if(strcmp(str2,book[i])。 Name)==0)

flag = 2;

}

else if(2==n)

{

if(strcmp(str2,book[i])。 ClassNum)==0)

flag = 2;

}

if(flag==2)

{

if(0==ksd)

{

Printf(" Name \ t phone \ t \ t \ t student id \ tsex \ tage \ n ");

ksd = 1;

}

printf("%8s\t%8s\t%s\t%s\t%d\n ",book[i]。 Name, book [me]. Peak number,

Book [me]. ClassNum,book[i]。 Sex, books [me]. Age);

flag = 1;

}

}

if( 1==flag)

System ("suspended");

else if(flag==0)

{

printf(! ! ! There is no such record! ! ! \ n ");

System ("suspended");

System ("CLS");

}

Returns 0;

}

Inttaxi (address book [])

{

/* for(int I = 0; I < count; i++)

{

for(int j = 0; j & ltcount- 1-I; j++)

{

If(strcmp (book [j].ClassNum, book[j+ 1]). ClassNum)>0)

{

Address bk;

Strcpy (black. Name, book [j]. Name);

bk。 Age = book [j]. Age;

Strcpy (black. ClassNum,book[j]。 class num);

Strcpy (black. PhonNum, book [j]. phon num);

Strcpy (black. Sex, books [j]. Sex);

Strcpy (book [j]. Name, book [j+ 1]. Name);

Book [j] Age = book [j+ 1]. Age;

Strcpy (book [j].ClassNum, book[j+ 1]. class num);

Strcpy (book [j].PhonNum, book[j+ 1]. phon num);

Strcpy (book [j]. Sex, book [j+ 1]. Sex);

Strcpy (book [j+ 1]. Name, bk. Name);

Book [j+ 1]. Age =bk. Age;

Strcpy (book [j+ 1]. ClassNum shoal. class num);

Strcpy (book [j+ 1]. Funham shoal. phon num);

Strcpy (book [j+ 1]. Sex, bk. Sex);

}

}

}

printf(! ! ! Operation successful! ! ! \ n ");

System ("suspended");

System ("CLS");

Writetxt (book); */

Returns 0;

}

int Exit()

{

Exit (1);

Returns 0;

}

This is a program I wrote before. There is a written document with some virtual contact information. If necessary, I will send you the whole project and leave an email ... O(∩_∩)O~