C + + Course Design (address book program)

preface I'm only a general sophomore. I come ...
preface

I'm only a general sophomore. I come here to write my opinions. I hope you can give me some advice. We sincerely invite people with lofty ideals from all over the world to join our code learning group exchange: 8713 Five 2155 (whether you can use C/C + + or Java, Python or PHP... If you are interested, we welcome you to join us, but please fill in the group information carefully. At present, most of the students in the group are college students, so please don't go far. We hope that the visionary seniors can provide suggestions and directions for the young people who are about to enter the society.)

text

Design a practical small address book program, with add, query and delete functions. It is composed of name, native place, telephone number 1, telephone number 2 and e-mail address. The name can be mixed with characters and numbers. The phone number can consist of characters and numbers. (save with file)

Implementation function:

(1) The system works in menu mode

(2) Information entry function

(3) Information browsing function

(Four) Information query function

(5) Information modification function

(Six) System exit function

design sketch

Code

Set up the structure to install basic information, then call each class library.

/*We sincerely invite people with lofty ideals from all over the world to join our code learning group exchange: 871352155*/ #include<iostream> #include<stdio.h> #include<string> #include<windows.h> const int MAX = 1e3; using namespace std; struct person { string m_name; string m_sex; string m_phone; string m_phone2; string m_add; }; struct Addressbooks { struct person personArray[MAX]; int m_size; };

The main menu looks a bit fancy, but it's not as fancy as the class management class.

void showMenu() { char menu[] = { "Welcome to our address book system!!!\n Welcome to Manor 871352155\n" }; int i; for(i = 0; menu[i] != '\0'; i++) { Sleep(30); printf("%c", menu[i]); } printf("★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆\n"); printf("☆********************************************************************★\n"); printf("★ Address book management system ☆\n"); printf("☆ ★\n"); printf("★ 1.Add a Contact 4.find contact ☆\n"); printf("☆ ★\n"); printf("★ 2.Show contacts 5.Modify contact ☆\n"); printf("☆ ★\n"); printf("★ 3.Delete Contact 6.Empty contacts ☆\n"); printf("☆********************************************************************★\n"); printf("★ 7.Exit address book ☆\n"); printf("☆ ------------------------------------------- ★\n"); printf("☆********************************************************************★\n"); printf("★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆\n"); }

Here is the input part. The address book is judged by the while statement and stored in the structure (to be honest, I don't think it's different from the database)

void addperson(Addressbooks *abs) { if(abs->m_size==MAX) { cout<<"The address book is full and cannot be added"<<endl; return; } string name; cout<<"Please enter contact name"<<endl; getchar(); cin>>name; abs->personArray[abs->m_size].m_name=name; string sex; cout<<"Please enter your native place"<<endl; cin>>sex; abs->personArray[abs->m_size].m_sex=sex; cout<<"Please enter the contact number"<<endl; string number; while(true) { cin>>number; if(number.length()==11) { abs->personArray[abs->m_size].m_phone=number; break; } cout<<"Illegal input, please re-enter"<<endl; } cout<<"Please enter contact phone 2"<<endl; string number2; while(true) { cin>>number2; if(number2.length()==11) { abs->personArray[abs->m_size].m_phone2=number2; break; } cout<<"Illegal input, please re-enter"<<endl; } cout<<"Please enter email"<<endl; string addre; while(true) { cin>>addre; if(addre.length()>0) { abs->personArray[abs->m_size].m_add=addre; break; } cout<<"Illegal input, please re-enter"<<endl; } cout<<"Add this contact successfully"<<endl; abs->m_size++; system("pause"); system("CLS"); }

Display the contact part, that is, simply take out all data from the structure and output cout

void showperson(Addressbooks *abs) //Show all contacts { if(abs->m_size==0) { cout<<"Address book is empty"<<endl; system("pause"); system("CLS"); return; } for(int i=0;i<abs->m_size;i++) { cout<<"List of correspondents"<<endl<<endl; printf(">>>%d No. correspondent:\n",i+1); cout<<"full name:-> "<<abs->personArray[i].m_name<<"\t"; cout<<"Native place:-> "<<abs->personArray[i].m_sex<<"\t"; cout<<"Telephone:-> "<<abs->personArray[i].m_phone<<"\t"; cout<<"Phone 2:-> "<<abs->personArray[i].m_phone2<<"\t"; cout<<"mail box:-> "<<abs->personArray[i].m_add<<endl; } system("pause"); system("CLS"); }

lookup

void findperson(Addressbooks *abs) //find contact { if(abs->m_size==0) { cout<<"Address book is empty, illegal operation!"<<endl<<endl; system("pause"); system("CLS"); return; } cout<<"Please enter the name of the contact you want to find:"<<endl; string name; while(true) { cin>>name; if(isfind(abs,name)==-1) { cout<<"The contact does not exist,Please re-enter"<<endl<<endl; } else if(isexist(abs,name)!=-1) { cout<<"Found the contact: "<<endl<<endl; int mid=isfind(abs,name); cout<<"full name:-> "<<abs->personArray[mid].m_name<<endl; cout<<"Native place:-> "<<abs->personArray[mid].m_sex<<endl; cout<<"Telephone:-> "<<abs->personArray[mid].m_phone<<endl; cout<<"Telephone:-> "<<abs->personArray[mid].m_phone2<<endl; cout<<"mail box:-> "<<abs->personArray[mid].m_add<<endl<<endl; break; } } cout<<"Find successful"<<endl; system("pause"); system("CLS"); }

Main function

int main() { Addressbooks abs; abs.m_size=0; int select =0; //Create a user selected variable while(true) { showMenu(); cin>>select; switch(select) { case 1: //Add a Contact addperson(&abs); break; case 2: //Show contacts showperson(&abs); break; case 3: //Delete Contact deleteperson(&abs); break; case 4: //find contact findperson(&abs); break; case 5: //Modify contact changeperson(&abs); break; case 6: //Empty contacts clearperson(&abs); break; case 7: //Exit address book cout<<"Welcome to use this address book again later"<<endl; system("pause"); return 0; break; } } system("pause"); return 0; }

14 June 2020, 05:06 | Views: 4444

Add new comment

For adding a comment, please log in
or create account

0 comments