1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
// Function prototypes
void addPhoneContacts();
void viewPhoneContacts();
void searchPhoneContact();
void editPhoneContact();
void deletePhoneContact();
int main(){ //Main Function
system("cls");
bool run=true;
do{
int Option; //Main menu
cout << "----------------------Phone Book-----------------------------" << endl;
cout << "\n";
cout << "What do you need to perform here?" << endl;
cout << "1.) Add Phone Contact" << endl;
cout << "2.) Edit Phone Contact" << endl;
cout << "3.) Delete Phone Contact" << endl;
cout << "4.) View All Phone Contacts" << endl;
cout << "5.) Search Phone DB" << endl;
cout << "6.) Exit" << endl << endl;
cout << "Select an option: ";
cin >> Option;
cin.ignore();
switch (Option){
case 1:
addPhoneContacts();
break;
case 2:
editPhoneContact();
break;
case 3:
deletePhoneContact();
break;
case 4:
viewPhoneContacts();
break;
case 5:
searchPhoneContact();
break;
case 6:
run = false;
break;
default:
cout << "Select between options 1 to 6" <<endl;
int main();
}
} while(run);
cout << "Program got Terminated";
}
void addPhoneContacts(){ //Function is for adding the phone contacts.
system ("cls");
string Firstname, Lastname, Address, Contact, list, name, Firstname2, Lastname2, Address2, Contact2;
double counter, number;
cout << "----------------------Phone DB-----------------------------" << endl << endl;
cout << "Enter 'quit' at First name to quit" << endl << endl;
cout << "Enter First Name: ";
getline(cin, Firstname);
if (Firstname == "quit")
main();
cout << "Enter Last Name: ";
getline(cin, Lastname);
cout << "Enter Address: ";
getline(cin, Address);
cout << "Enter Contact Number: ";
getline(cin, Contact);
ifstream asd("PhoneDB.txt");
while(asd >> counter >> Firstname2 >> Lastname2 >> Address2 >> Contact2){
if (counter == 500){
cout << "Invalid as the Max number of contacts has been reached already (500).";
main ();
}
else number = counter;
}
ofstream adb("PhoneDB.txt", ios::app);
number = number + 1;
adb << number << " " << Firstname << " " << Lastname
<< " " << Address << " " << Contact << endl;
system("pause");
system("cls");
}
void viewPhoneContacts(){ //Show all the entries stored in the data base.
system("cls");
double counter;
string Firstname, Lastname, Address, Contact;
ifstream phonedb("PhoneDB.txt");
cout << "Entry #" << setw(17) << "First Name" << setw(23)<< "Last Name" << setw(23) <<"Address"<< setw(29)<<"Contact"<< endl << endl;
while (phonedb >> counter >> Firstname >> Lastname >> Address >> Contact){
cout << setw(3)<< counter << setw(18)<< Firstname << setw(25) << Lastname << setw(25) << Address << setw(30) << Contact << endl;
}
cout << endl;
system ("pause");
system ("cls");
}
void searchPhoneContact(){ //Allow to specific the entry here.
system("cls");
int choice;
double counter, number;
string Firstname, Lastname, Address, Contact, Firstname2, Lastname2, Address2, Contact2;
cout << "----------------------Phone DB-----------------------------" << endl << endl;
cout << "---Search Phone DB---" << endl;
cout << "1.) First name" << endl;
cout << "2.) Last name" << endl;
cout << "3.) Address" << endl;
cout << "4.) Contact " << endl;
cout << "Enter Choice: ";
cin >> choice;
switch (choice){
case 1:
cout << "Enter First Name: ";
cin >> Firstname;
cout << endl;
break;
case 2:
cout << "Enter Last Name: ";
cin >> Lastname;
cout << endl;
break;
case 3:
cout << "Enter Address: ";
cin >> Address;
cout << endl;
break;
case 4:
cout << "Enter Contact: ";
cin >> Contact;
cout << endl;
break;
default:
cout << "Please Enter choice from 1 to 4";
searchPhoneContact();
}
ifstream search("PhoneDB.txt");
if (choice==1){
while (search >> counter >> Firstname2 >> Lastname2>> Address2 >> Contact2){
if(Firstname == Firstname2){
cout << counter << " " << Firstname2 << " " << Lastname2 << " " << Address2 << " " << Contact2 << endl << endl;
}
}
}
if (choice==2){
while (search >> counter >> Firstname2 >> Lastname2>> Address2 >> Contact2){
if(Lastname == Lastname2){
cout << counter << " " << Firstname2 << " " << Lastname2 << " " << Address2 << " " << Contact2 << endl << endl;
}
}
}
if (choice==3){
while (search >> counter >> Firstname2 >> Lastname2>> Address2 >> Contact2){
if(Address == Address2){
cout << counter << " " << Firstname2 << " " << Lastname2 << " " << Address2 << " " << Contact2 << endl <<endl;
}
}
}
if (choice==4){
while (search >> counter >> Firstname2 >> Lastname2>> Address2 >> Contact2){
if(Contact == Contact2){
cout << counter << " " << Firstname2 << " " << Lastname2 << " " << Address2 << " " << Contact2 << endl << endl;
}
}
}
system ("pause");
system ("cls");
}
| |