Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<cstring>
- #include<cstdlib>
- #include<cmath>
- #include <cstddef>
- using std::string;
- using std::getline;
- using namespace std;
- string name[101] = { "" };
- string email[101] = { "" };
- string tele[101] = { "" };
- void addressbook()
- {
- int i;
- name[1] = { "Lawrence Cheung" };
- cout << "Name is : " << name[1] << endl;
- email[1] = { "enccl@eie.polyu.edu.hk" };
- cout << "Email is : " << email[1] << endl;
- tele[1] = { "27666131" };
- cout << "Telephone number is : " << tele[1];
- name[2] = { "Helen Wong" };
- cout << "Name is : " << name[2] << endl;
- email[2] = { "helenwong@yahoo.com.hk" };
- cout << "Email is : " << email[2] << endl;
- tele[2] = { "94665888" };
- cout << "Telephone number is : " << tele[2];
- name[3] = { "Simon Sui" };
- cout << "Name is : " << name[3] << endl;
- email[3] = { "ss123@gmail.com" };
- cout << "Email is : " << email[3] << endl;
- tele[3] = { "64441234" };
- cout << "Telephone number is : " << tele[3];
- name[4] = { "Mary Ho" };
- cout << "Name is : " << name[4] << endl;
- email[4] = { "ho.mary10@netvigator.com" };
- cout << "Email is : " << email[4] << endl;
- tele[4] = { "21111112" };
- cout << "Telephone number is : " << tele[4];
- for (i = 5;i < 102;i++)
- {
- name[i] = { "" };
- email[i] = { "" };
- tele[i] = { "" };
- }
- cout << "Initialization is completed ." << endl;
- }
- void cpersoninfo()
- {
- int max;
- int ii;
- int count = 1;
- size_t pos = 0, pos1 = 0;
- cout << "Please enter the total number of records to be created";
- cin >> max;
- if (max > 0 || max<11)
- {
- for (int ii = count;ii <= max + count;ii++)
- {
- cout << "Full name : ";
- cin >> name[ii];
- size_t found = name[ii].find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQSTUVWXYZ ");
- while (found != std::string::npos)
- {
- cout << "Invalid input!Please enter again!" << endl;
- cin >> name[ii];
- size_t found = name[ii].find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQSTUVWXYZ ");
- }
- cout << "Email address : ";
- cin >> email[ii];
- pos = email[ii].find('@', 0);
- while (pos == string::npos || pos == 0 || pos + 1 == email[ii].length())
- {
- cout << "Invalid input!Please enter again!" << endl;
- cin >> email[ii];
- }
- cout << "8-digit telephone number : ";
- cin >> tele[ii];
- size_t found1 = tele[ii].find_first_not_of("0123456789 ");
- pos1 = tele[ii].find('0', 0);
- while (found1 != std::string::npos || tele[ii].length != 8 || pos1 == 0)
- {
- cout << "Invalid input!Please enter again!" << endl;
- cin >> tele[ii];
- }
- }
- count = count + ii;
- ii = 0;
- }
- else
- {
- while (max < 0 || max>10)
- {
- cout << "The input is invalid . It must be an integer not greater than 10 .";
- cout << "Please enter the total number of records to be created";
- cin >> max;
- }
- }
- }
- void lpersoninfo()
- {
- int q = 0;
- int findname = 0;
- int findemail = 0;
- int findtele = 0;
- string kk = "a";
- string NAME = "";
- string EMAIL = "";
- string TELE = "";
- while (kk == "a" || kk == "A" || kk == "b" || kk == "B" || kk == "c" || kk == "C")
- {
- cout << endl << endl << "***********SUB-MENU***********" << endl;
- cout << "a. Search record by name " << endl;
- cout << "b. Search record by email address " << endl;
- cout << "c. Search record by telephone number" << endl;
- cout << "d. Return to main menu" << endl << endl;
- cout << "Please enter your chioce < a, b, c or d to return> : ";
- getline(cin, kk);
- size_t found2 = kk.find_first_not_of("abcdABCD ");
- while (found2 != std::string::npos || kk.length != 1)
- {
- cout << "Invalid input!Please enter again!" << endl;
- cin >> kk;
- }
- if (kk == "a" || kk == "A")
- {
- cout << "Please enter a name to search" << endl;
- cin >> NAME;
- for (q = 0;q <= 101;q++)
- {
- if (NAME == name[q])
- {
- cout << "A record is found!" << endl;
- cout << "Email address is : " << email[q] << endl;
- cout << "Telephone number is : " << tele[q] << endl;
- findname = 1;
- break;
- }
- }
- if (findname == 0)
- {
- cout << "Sorry, no record is found !" << endl;
- }
- findname = 0;
- q = 0;
- }
- if (kk == "b" || kk == "B")
- {
- cout << "Please enter an email to search" << endl;
- cin >> EMAIL;
- for (q = 0;q <= 101;q++)
- {
- if (EMAIL == email[q])
- {
- cout << "A record is found!" << endl;
- cout << "Full name is : " << name[q] << endl;
- cout << "Telephone number is : " << tele[q] << endl;
- findemail = 1;
- break;
- }
- }
- if (findemail == 0)
- {
- cout << "Sorry, no record is found !" << endl;
- }
- findemail = 0;
- q = 0;
- }
- if (kk == "c" || kk == "C")
- {
- cout << "Please enter a telephone number to search" << endl;
- cin >> TELE;
- for (q = 0;q <= 101;q++)
- {
- if (TELE == tele[q])
- {
- cout << "A record is found!" << endl;
- cout << "Full name is : " << name[q] << endl;
- cout << "Email address is : " << email[q] << endl;
- findtele = 1;
- break;
- }
- }
- if (findtele == 0)
- {
- cout << "Sorry, no record is found !" << endl;
- }
- findtele = 0;
- q = 0;
- }
- if (kk == "d" || kk == "D")
- {
- break;
- }
- }
- }
- void lapersoninfo()
- {
- int q = 0;
- for (q = 0;q <= 101;q++)
- {
- if (name[q] != "")
- {
- cout << "Full name is : " << name[q] << endl;
- cout << "Email address is : " << email[q] << endl;
- cout << "Telephone number is : " << tele[q] << endl;
- }
- }
- }
- int main()
- {
- int k;
- cout << endl << endl << "***********MAIN MENU***********" << endl;
- cout << "1. Initialize the address book" << endl;
- cout << "2. Create person contact information" << endl;
- cout << "3. Lookup person contact inforamtion" << endl;
- cout << "4. Look all person contact inforamtion" << endl;
- cout << "5. Quit " << endl;
- cout << endl << "Please enter your chioce <1, 2, 3, 4 or 5 to exit :" << endl;
- cin >> k;
- while (k > 5 || k < 0)
- {
- cout << "Invalid input!Please enter again!";
- cout << endl << endl << "***********MAIN MENU***********" << endl;
- cout << "1. Initialize the address book" << endl;
- cout << "2. Create person contact information" << endl;
- cout << "3. Lookup person contact inforamtion" << endl;
- cout << "4. Look all person contact inforamtion" << endl;
- cout << "5. Quit " << endl;
- cout << endl << "Please enter your chioce <1, 2, 3, 4 or 5 to exit :" << endl;
- cin >> k;
- }
- while (k > 0 || k < 6)
- {
- if (k == 1)
- {
- addressbook();
- cout << endl << endl << "***********MAIN MENU***********" << endl;
- cout << "1. Initialize the address book" << endl;
- cout << "2. Create person contact information" << endl;
- cout << "3. Lookup person contact inforamtion" << endl;
- cout << "4. Look all person contact inforamtion" << endl;
- cout << "5. Quit " << endl;
- cout << endl << "Please enter your chioce <1, 2, 3, 4 or 5 to exit :" << endl;
- cin >> k;
- }
- if (k == 2)
- {
- cpersoninfo();
- }
- if (k == 3)
- {
- lpersoninfo();
- cout << endl << endl << "***********MAIN MENU***********" << endl;
- cout << "1. Initialize the address book" << endl;
- cout << "2. Create person contact information" << endl;
- cout << "3. Lookup person contact inforamtion" << endl;
- cout << "4. Look all person contact inforamtion" << endl;
- cout << "5. Quit " << endl;
- cout << endl << "Please enter your chioce <1, 2, 3, 4 or 5 to exit :" << endl;
- cin >> k;
- }
- if (k == 4)
- {
- lapersoninfo();
- cout << endl << endl << "***********MAIN MENU***********" << endl;
- cout << "1. Initialize the address book" << endl;
- cout << "2. Create person contact information" << endl;
- cout << "3. Lookup person contact inforamtion" << endl;
- cout << "4. Look all person contact inforamtion" << endl;
- cout << "5. Quit " << endl;
- cout << endl << "Please enter your chioce <1, 2, 3, 4 or 5 to exit :" << endl;
- cin >> k;
- }
- if (k == 5)
- {
- cout << "Goodbye";
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement