c ++ realize address book management system (console version)
This program is suitable for beginners c ++, for c ++ basics, related to the variable structure is defined using the definition of an array using pointer definitions used and so on.
Run after the results are as follows:
Code:
#include <the iostream> #include < String > the using namespace STD; #define MAX 1000 // define a maximum capacity of 1000 contacts @ contact structure struct Person { string name; int sex; int age; string address; }; // contacts structure struct Business Card { struct person p[MAX]; int size; }; // operation menu void showMenu is () { cout << " ********* contact management system ********** " << endl; cout << " ********* 1. Add contact ********** " << endl; cout << " ********* 2. Delete Contact ********** " << endl; cout << " ********* 3. Modify Contact ********** " << endl; cout << " ********* 4. Query Contact ********** " << endl; COUT << " *************************************** 5. The display contacts ********** " << endl; COUT << " *************************************** 6. The Clear Phonebook ********** " << endl; cout << " ********* 0. Exit contacts ********** " << endl; } // package query whether there is contact int ISEXIST (CON * Contact, String name) { for ( int I = 0 ; I <con-> size; I ++ ) { IF (con-> P [I] .name == name ) { return I; } } return -1; } // add the contact function void the addPerson (Contact * CON) { // incoming pointer array IF (con-> == size MAX) { cout << " address book is full " << endl; } else { cout << " Enter your name " ; String name; cin >> name; cout << " Enter the age " ; int Age; cin >> age; cout << " Input 1 Gender: Female 2: Male " ; int Sex; cin >> sex; COUT << " input address " ; String address; cin >> address; con->p[con->size].name = name; con->p[con->size].age = age; con->p[con->size].sex = sex; con->p[con->size].address = address; con->size++; } cout << " added successfully " << endl; system("pause"); } // delete a contact function void deletecon (Business Card * CON) { String name; cout << " Enter the name you want to delete " ; cin >> name; int res = isExist(con,name); if (res != -1) { for (int i = res; i < con->size; i++) { con->p[res] = con->p[res + 1]; } cout << " deleted successfully " << endl; con->size--; } else { cout << " no such person " << endl; } system("pause"); } // Edit contact function void the updateContact (Contact * CON) { String name; cout << " Enter the name of the contact you want to modify the query " << endl; cin >> name; int res = isExist(con, name); if (res != -1) { cout << "姓名:" << con->p[res].name << "年龄:" << con->p[res].age << "性别:" << (con->p[res].sex == 1 ? "女" : "男") << "地址:" << con->p[res].address << endl; cout << " Enter the name modification " ; String nametemp; cin >> nametemp; con->p[res].name = nametemp; cout << " Enter amend Age " << endl; int Age; cin >> age; con->p[res].age = age; cout << " Enter Modify 1 Gender: Female 2: male " << endl; int Sex; cin >> sex; con->p[res].sex = sex; COUT << " modified input address " << endl; String address; cin >> address; con->p[res].address = address; cout << " modified successfully " << endl; } else { cout << " no such person " << endl; } system("pause"); } // query the contact function void Search (* Business Card CON) { String name; cout << " Enter the name query " << endl; cin >> name; int res = isExist(con, name); if (res != -1) { cout << "姓名:" << con->p[res].name << "年龄:" << con->p[res].age << "性别:" <<(con->p[res].sex==1?"女":"男")<<endl; } else { cout << " no such person " << endl; } system("pause"); } // clear the contact function void clearContact (Business Card * CON) { con->size = 0; cout << " has been cleared Address Book " << endl; system("pause"); } // display a contact function void showContact (Contact * CON) { IF (con-> size == 0 ) { cout << " No Contact " << endl; } else { for (int i = 0; i < con->size; i++) { cout <<"姓名:"<< con->p[i].name <<"年龄:"<< con->p[i].age <<"地址:"<< con->p[i].address <<"性别:"<<(con->p[i].sex==1?"女":"男") << endl; } } system("pause"); } // exit the system function int ExitApp () { exit(0); } /** Address book management system main program * / Int main () { contact con; con.size = 0; while (true) { system("cls");//清屏 showMenu(); cout << " Enter your choice " ; int the SELECT ; cin >> select; switch (select) { case 1: addPerson(&con); break; case 2: deletecon(&con); break; case 3: updateContact(&con); break; case 4: search(&con); break; case 5: showContact(&con); break; case 6: clearContact(&con); break; case 0://退出 exitapp(); break; } } }
Get the source public concern No. java One reply Contacts.