Telephone Directory In C++ Project With Source Code
The Telephone Directory In C++ Project is developed in C++ programming language, This Project Report On Telephone Directory In C++ is based on the concept of recording contact details. and There’s a login system for this project.
A Telephone Directory In C++ is an account-based system to view, add, modify, or delete from a telephone record based on names and the corresponding phone numbers. It is a very effective and simple understanding of beginners.
Watch the video here to see the full running Telephone Directory in C++ Project with Source Code.
This Telephone Directory Code In C++ also includes a downloadable Telephone Directory Project In C++ Source Code for free, just find the downloadable source code below and click to start downloading.
To start creating a Telephone Directory In C++ Project, make sure that you have code blocks or any platform of C/C++ language installed in your computer.
Steps on how to create a Telephone Directory In C++ Project With Source Code
Telephone Directory In C++ Project With Source Code
- Step 1: Create a new project.
First open the code blocks IDE and click “create a new project“.
- Step 2: Choose console application.
Second click the “console application” and after that click “next“.
- Step 3: Choose C++ language.
Third choose “C++ language” and click “next“.
- Step 4: Name Your Project.
Fourth name the project you’ve created and click “next” after that click “finish“.
- Step 5: The actual code.
You are free to copy the given source code below or download the downloadable source code given.
The Code Given Below Is For Sign In/Sign Up Module
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 |
int SignIn() { string uname, password, struname, strpassword, line; ghi: fstream file1("Accounts.dir"); int flag=0, nextLoc=0; system("cls"); cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; cout << "Please Enter Your Username: "; cin >> struname; if (struname=="Admin") { return 2; } if (struname=="admin") { return 3; } while (! file1.eof() ) { getline (file1,line); nextLoc=line.find(" "); uname=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); password=line; if(uname==struname) { flag=1; break; } } file1.close(); if(flag==1) { def: strpassword=getpword(); if(strpassword==password) { cout << "Sign-In Succesful."; } else { cout << "\nWrong Password! "; goto def; } } else { cout << "\n\nYour Username was not Found in our Database.\nPlease Sign-Up or Enter correct Username"; cout << "\nPress <1> To Sign-Up OR\n <2> To Sign-In Again\n"; int choice1; cin >> choice1; if(choice1==1) { return 1; } else { goto ghi; } } return 0; } void SignUp() { string uname, struname, line, Password; int flag; system("cls"); cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; fstream file1("Accounts.dir",ios::in|ios::out|ios::app); cout << "Please Enter an Username: "; cv: cin >> struname; flag = check(struname); if(flag==1) { goto cv; } cout << "Please Enter a Password: "; cin >> Password; file1 << "\n" << struname << " " << Password; cout << "\nAccount Created Successfully\n\n"; system("pause"); return; } |
In this module which is the module for sign in and sign up.
The Code Given Below Is For Getting Details Module
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 |
void GetDetails() { string fname, lname, tnumber; char choice = 'y'; fstream myfile("Directory.dir",ios::app); while(choice=='Y'||choice=='y') { system("cls"); cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; cout << "Enter First Name : "; cin >> fname; myfile << fname << " "; cout << "\nEnter Last Name : "; cin >> lname; myfile << lname << " "; cout << "\nEnter Phone Number : "; cin >> tnumber; myfile << tnumber << "\n"; cout << "\nDo you want to enter more? (y/n)"; cin >> choice; cout << "\n"; } myfile.close(); } |
In this module which is the getting details module of the system.
The Code Given Below Is For Search And Display Module
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 |
void SearchAndDisplay() { string line; string fName,lName,tNumber, strFName, strLName; char choice; int flag=0; int nextLoc=0; system("color F0"); system("cls"); do{ cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; flag=0; ifstream myfile ("Directory.dir"); if (myfile.is_open()) { cout<<endl<<"Enter First Name: "; cin>>strFName; cout<<"Enter Last Name: "; cin>>strLName; while (! myfile.eof() ) { getline (myfile,line); nextLoc=line.find(" "); fName=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); nextLoc=line.find(" "); lName=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); tNumber = line; if(fName==strFName && lName==strLName) { cout<<"\nFound!!"<<endl; cout<<endl<<"First Name: "<<fName<<"\n"<<"Last Name: "<<lName<<"\n"<<"Telephone Number: "<<tNumber<<endl ; flag=1; break; } } } else { cout << "Unable to open file"<<endl; exit(0); } if(flag==0) { cout<<"Not Found...Sorry."<<endl; } cout << "\nDo you want to enter more?(y/n) "; cin >> choice; system("cls"); }while(choice=='y'); return; } |
In this module which is the search and display module of the system.
The Code Given Below Is For The Delete Module
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 |
void Delete() { system("cls"); string line, fName, lName, strLName, strFName, tNumber; int nextLoc=0,flag=0; cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; cout << "Please enter the first name of record you want to delete: "; cin>>strFName; cout << "\nPlease enter the last name of record you want to delete: "; cin>>strLName; ifstream myfile; ofstream temp; myfile.open("Directory.dir"); temp.open("temp.dir"); while (!myfile.eof()) { getline (myfile,line); nextLoc=line.find(" "); fName=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); nextLoc=line.find(" "); lName=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); tNumber = line; if(!(fName==strFName && lName==strLName)) temp << fName <<" "<< lName <<" "<< tNumber<< endl; else flag++; } if(flag==0) { cout<<"\nRecord not found!!\n\n"; goto afg; } cout << "The record with the name " << strFName <<" "<<strLName<< " has been deleted " << endl; myfile.close(); temp.close(); remove("Directory.dir"); rename("temp.dir", "Directory.dir"); afg: return; } |
In this module which is the delete module of the system.
The Code Given Below Is For The Modify Module
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 |
void mod() { system("cls"); system("color F0"); string line, fName, lName, strLName, strFName, tNumber; int nextLoc=0,flag=0; cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; afgh: cout << "Please enter the first name of record you want to modify: "; cin>>strFName; cout << "\nPlease enter the last name of record you want to modify: "; cin>>strLName; ifstream myfile; ofstream temp; myfile.open("Directory.dir"); temp.open("temp1.dir"); while (!myfile.eof()) { getline (myfile,line); nextLoc=line.find(" "); fName=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); nextLoc=line.find(" "); lName=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); tNumber = line; if(!(fName==strFName && lName==strLName)) temp << fName <<" "<< lName <<" "<< tNumber<< endl; else flag++; } if(flag==0) { cout<<"\nRecord not found!! Try Again.\n\n"; goto afgh; } myfile.close(); temp.close(); remove("Directory.dir"); rename("temp1.dir", "Directory.dir"); string fname2, lname2, tnumber2; fstream myfile2("Directory.dir",ios::app); cout << "\n\nEnter New First Name : "; cin >> fname2; myfile2 << fname2 << " "; cout << "\nEnter New Last Name : "; cin >> lname2; myfile2 << lname2 << " "; cout << "\nEnter New Phone Number : "; cin >> tnumber2; myfile2 << tnumber2; myfile2.close(); return; } |
In this module which you can modify the record of the system.
Complete Source Code
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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
#include <iostream> #include <fstream> #include <string> #include <iomanip> #include <conio.h> #include <cwchar> #include <windows.h> #define _WIN32_WINNT 0x0601 using namespace std; class directory { int PhNo; char fname[50], lname [50]; public: string getpword() { char ch; string pass=""; cout << "Please Enter the Password: "; oo: ch=getch(); if(ch==8) { goto oo; } while(ch!=13) { if(ch==8) { if(pass.size()==0) { goto ps; } pass.erase(pass.size()-1); cout << "\b \b"; ps: goto pp; } pass.push_back(ch); cout << "*"; pp: ch=getch(); } return pass; } int check(string a) { int flag=0; string b; fstream f1("Accounts.dir",ios::in); while(f1) { f1 >> b; if(b==a) { flag = 1; break; } } f1.close(); if(flag==1) { cout << "\nSorry! Username already exists. \nPlease try another: "; return 1; } return 0; } int SignIn() { string uname, password, struname, strpassword, line; ghi: fstream file1("Accounts.dir"); int flag=0, nextLoc=0; system("cls"); cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; cout << "Please Enter Your Username: "; cin >> struname; if (struname=="Admin") { return 2; } if (struname=="admin") { return 3; } while (! file1.eof() ) { getline (file1,line); nextLoc=line.find(" "); uname=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); password=line; if(uname==struname) { flag=1; break; } } file1.close(); if(flag==1) { def: strpassword=getpword(); if(strpassword==password) { cout << "Sign-In Succesful."; } else { cout << "\nWrong Password! "; goto def; } } else { cout << "\n\nYour Username was not Found in our Database.\nPlease Sign-Up or Enter correct Username"; cout << "\nPress <1> To Sign-Up OR\n <2> To Sign-In Again\n"; int choice1; cin >> choice1; if(choice1==1) { return 1; } else { goto ghi; } } return 0; } void SignUp() { string uname, struname, line, Password; int flag; system("cls"); cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; fstream file1("Accounts.dir",ios::in|ios::out|ios::app); cout << "Please Enter an Username: "; cv: cin >> struname; flag = check(struname); if(flag==1) { goto cv; } cout << "Please Enter a Password: "; cin >> Password; file1 << "\n" << struname << " " << Password; cout << "\nAccount Created Successfully\n\n"; system("pause"); return; } void GetDetails() { string fname, lname, tnumber; char choice = 'y'; fstream myfile("Directory.dir",ios::app); while(choice=='Y'||choice=='y') { system("cls"); cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; cout << "Enter First Name : "; cin >> fname; myfile << fname << " "; cout << "\nEnter Last Name : "; cin >> lname; myfile << lname << " "; cout << "\nEnter Phone Number : "; cin >> tnumber; myfile << tnumber << "\n"; cout << "\nDo you want to enter more? (y/n)"; cin >> choice; cout << "\n"; } myfile.close(); } void SearchAndDisplay() { string line; string fName,lName,tNumber, strFName, strLName; char choice; int flag=0; int nextLoc=0; system("color F0"); system("cls"); do{ cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; flag=0; ifstream myfile ("Directory.dir"); if (myfile.is_open()) { cout<<endl<<"Enter First Name: "; cin>>strFName; cout<<"Enter Last Name: "; cin>>strLName; while (! myfile.eof() ) { getline (myfile,line); nextLoc=line.find(" "); fName=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); nextLoc=line.find(" "); lName=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); tNumber = line; if(fName==strFName && lName==strLName) { cout<<"\nFound!!"<<endl; cout<<endl<<"First Name: "<<fName<<"\n"<<"Last Name: "<<lName<<"\n"<<"Telephone Number: "<<tNumber<<endl ; flag=1; break; } } } else { cout << "Unable to open file"<<endl; exit(0); } if(flag==0) { cout<<"Not Found...Sorry."<<endl; } cout << "\nDo you want to enter more?(y/n) "; cin >> choice; system("cls"); }while(choice=='y'); return; } void Delete() { system("cls"); string line, fName, lName, strLName, strFName, tNumber; int nextLoc=0,flag=0; cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; cout << "Please enter the first name of record you want to delete: "; cin>>strFName; cout << "\nPlease enter the last name of record you want to delete: "; cin>>strLName; ifstream myfile; ofstream temp; myfile.open("Directory.dir"); temp.open("temp.dir"); while (!myfile.eof()) { getline (myfile,line); nextLoc=line.find(" "); fName=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); nextLoc=line.find(" "); lName=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); tNumber = line; if(!(fName==strFName && lName==strLName)) temp << fName <<" "<< lName <<" "<< tNumber<< endl; else flag++; } if(flag==0) { cout<<"\nRecord not found!!\n\n"; goto afg; } cout << "The record with the name " << strFName <<" "<<strLName<< " has been deleted " << endl; myfile.close(); temp.close(); remove("Directory.dir"); rename("temp.dir", "Directory.dir"); afg: return; } void mod() { system("cls"); system("color F0"); string line, fName, lName, strLName, strFName, tNumber; int nextLoc=0,flag=0; cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; afgh: cout << "Please enter the first name of record you want to modify: "; cin>>strFName; cout << "\nPlease enter the last name of record you want to modify: "; cin>>strLName; ifstream myfile; ofstream temp; myfile.open("Directory.dir"); temp.open("temp1.dir"); while (!myfile.eof()) { getline (myfile,line); nextLoc=line.find(" "); fName=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); nextLoc=line.find(" "); lName=line.substr(0,nextLoc); line = line.substr(nextLoc+1,line.length()); tNumber = line; if(!(fName==strFName && lName==strLName)) temp << fName <<" "<< lName <<" "<< tNumber<< endl; else flag++; } if(flag==0) { cout<<"\nRecord not found!! Try Again.\n\n"; goto afgh; } myfile.close(); temp.close(); remove("Directory.dir"); rename("temp1.dir", "Directory.dir"); string fname2, lname2, tnumber2; fstream myfile2("Directory.dir",ios::app); cout << "\n\nEnter New First Name : "; cin >> fname2; myfile2 << fname2 << " "; cout << "\nEnter New Last Name : "; cin >> lname2; myfile2 << lname2 << " "; cout << "\nEnter New Phone Number : "; cin >> tnumber2; myfile2 << tnumber2; myfile2.close(); return; } }; int main() { directory d; int choice, choice3, returnedValue; char choice2='y', choice4='y'; string pword; dkj: system("cls"); cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; cout << "Please Sign-In or Sign-Up to Continue\n\n\t1. Sign-In to an Existing Account\n\t2. Create a new Account\n\t3. Exit\n"; cout << "\nPlease Enter your choice: "; cin >> choice3; if(choice3==1) { returnedValue=d.SignIn(); if(returnedValue==1) { d.SignUp(); } else if(returnedValue==2) { yz: pword=d.getpword(); if(pword=="Root") { system("cls"); cout << "Admin Signed In\n"; system("pause"); goto mno; } else { cout << "\nPassword Incorrect! Please Enter Again: "; goto yz; } } else if(returnedValue==3) { vwx: pword=d.getpword(); if(pword=="root") { system("cls"); cout << "Admin Signed In\n"; system("pause"); goto mno; } else { cout << "\nPassword Incorrect. Please Enter Again: "; goto vwx; } } } else if(choice3==2) { jkl: d.SignUp(); } else { exit(0); } while(choice2=='Y'||choice2=='y') { system("color F0"); system("cls"); cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; cout <<"Do you want to \n\n\t1.View Existing Directories \n\t2.Enter New Directories\n\t3.Delete Existing Directories\n\t4.Modify Existing Directories\n\t5.Log Out\n\t6.Log Out and Exit\n"; cout<<"\nPlease enter your choice: "; abc: cin >> choice; switch (choice) { case 1: d.SearchAndDisplay(); break; case 2: d.GetDetails(); break; case 3: d.Delete();break; case 4: d.mod();break; case 5: cout<<"\nLogged out successfully!\n"; system("pause"); goto dkj; case 6: exit(0); break; default: cout << "\nWrong Input! Try Again... "; goto abc; } } goto stu; mno: system("color F0"); system("cls"); cout << "\n\n\t\t-----------TELEPHONE DIRECTORY-------------\n\n"; cout << "Do you want to \n\n\t1.Enter New Directories\n\t2.View Existing Directories\n\t3.Delete Existing Directories\n\t4.Modify Existing Directories\n\t5.Log Out\n\t6.Log Out and Exit\n"; cout<<"\nPlease enter your choice: "; pqr: cin >> choice; lok: switch (choice) { case 1: d.GetDetails(); break; case 2: d.SearchAndDisplay(); break; case 3: d.Delete();break; case 4: d.mod();break; case 5: cout<<"\nLogged out successfully!\n"; system("pause"); goto dkj; case 6: exit(0); default: cout << "\nWrong Input! Try Again... "; goto pqr; } cout << "Do you want to continue? (y/n) : "; choice4=getch(); if(choice4=='Y'||choice4=='y') { goto lok; } else goto mno; stu: exit(0); } |
Run Quick Virus Scan for secure Download
Run Quick Scan for secure DownloadDownloadable Source Code
Summary
The whole project is designed in ‘C++’ language and different variables and strings have been used for the development of this project. This mini project is easy to operate and understand by the users.
This simple project can enhance the knowledge of the beginners or the students to develop their skills in programming, also this project is easy to understand the module and their variables.
Related Articles
- Number System Conversion Project in C with Source Code
- Prison Management System Project in C with Source Code
- Department Store Management System Project in C with Source Code
- Best C Projects with Source Code for Beginners Free Download 2020
- Bank Management System in C with Source Code
- School Billing System in C with Source Code
- Hotel Management System Project In C With Source Code
- Employee Management System In C With Source Code
- Mini Project for Phonebook in C with Source Code
- Calendar In C Programming With Source Code
- Student Record System in C with Source Code
- Library Management System In C With Source Code
- Simple Hospital Management System In C With Source Code
Inquiries
If you have any questions or suggestions about Telephone Directory In C++ Project , please feel free to leave a comment below.