Introduction:
The phonebook is a very simple C++ (oop) mini-project that can help you understand the basic concepts of functions, file handling, and data structure. This program will teach you how to add, list, change or edit, search and remove data from/to a file. Adding new records, listing them, editing and updating them, looking for saved contacts, and removing phonebook records are simple Functions that make up the main menu of this Phonebook program.
Personal information, such as name, gender, phone number, e-mail, and address, is requested when you add a record to your phonebook. These records can then be updated, entered, searched, and deleted. I’ve used a lot of functions in this mini-project. These functions are easy to understand since their name means just their respective operations.
Aim of the project:
Create a “Contact Phonebook” framework using C programming. This software is very useful nowadays to store full information under a single contact number. The software also has options for removing and changing the contact number entered.
Advantages & Disadvantages of phonebook Management System
It is simple for the user to store complete information (e.g. e-mail ID, address) about his or her contact. It’s simple for the user to simply check his appropriate contact number by entering the contact name. Often it’s hard to store more contacts (i.e over 150). It is also difficult to store contacts with two or more contact numbers.
Designing modules of phonebook Management System
The software architecture consists of the following modules: Preprocessor commands, Functions, Variables, Statements & Expressions.
Module -1: (Header files)
- #include<stdio.h>
- #include<conio.h>
- #include<iostream>
- #include<fstream.h>
Module-2:(declaring functions):
This function displays the user to select his choice of operations.
Module-3(main function):
A function declared in a class named phone book in a program.
Module -4(adding menu):
This module is used for inputting menu details.
Module-5(list record):
This part is to show up the saved contacts list.
Module -6 (searching ra ecord) :
This method requires the user to assign a name to the contact number of the contact being checked.
Module-7 (Deleting a record) :
This choice deletes a person’s added contact information.
Module-8 (Modifying a record) :
This choice is used to update or alter the information of the record.
Example for Implementation:
The home screen that the program will show after running i-e:
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 |
#include<iostream> #include<fstream> #include<conio.h> #include<stdio.h> using namespace std; int menu(); int AddNum(); int Show_Records(); int SearchWithSerialNumber(); int Record_Deletion(); int Update_Record(); class PhoneBook { int srno; char n[28]; char m[17]; char e[40]; char g[30]; public: int getSrNo() {return srno;} int storeData() { cout<<"\n.......CREATE NEW PHONE RECORD.........\n"; cout<<"Enter Serial Number : "; cin>>srno; cin.ignore(); cout<<"Enter Record Name : "; cin>>getline(n,28); cout<<"Enter Mobile Number : "; cin>>getline(m,17); cout<<"Enter E-Mail I. D. : "; cin>>getline(e,40); cout<<"Enter Record Group : "; cin>>getline(g,30); cout<<endl; } int showData() { cout<<"\n...............PHONE BOOK RECORD...............\n"; cout<<"Sr. No. : "<<srno<<endl; cout<<"Name : "<<n<<endl; cout<<"Mobile No. : "<<m<<endl; cout<<"Email ID : "<<e<<endl; cout<<"Group : "<<g<<endl; } }x; int NumberSum() { ofstream fout; fout.open("PhonBook.dat",ios::out|ios::binary|ios::app); x.storeData(); fout.write((char*)&x,sizeof(x)); fout.close(); cout<<"\nRecord Saved to File......\n"; } int Show_Records() { ifstream fin; fin.open("PhonBook.dat",ios::out|ios::binary|ios::app); while(fin.read((char*)&x,sizeof(x))) { x.showData(); } fin.close(); cout<<"\nReading of Data File Completed......\n"; } int SearchWithSerialNumber() { ifstream fin; int n, flag=0; fin.open("PhonBook.dat",ios::out|ios::binary|ios::app); cout<<"Enter Serial Number of Record To Display: "; cin>>n; while(fin.read((char*)&x,sizeof(x))) { if(n==x.getSrNo()) { x.showData(); flag++; cout<<"\n\n.....Record Found and Displayed......\n"; } } fin.close(); if(flag==0) cout<<"\nThe Record of Serial Number "<<n<<" is not in file....\n"; cout<<"\nReading of Data File Completed......\n"; } int
Record_Deletion() { ifstream fin; ofstream fout; int n, flag=0; fin.open("PhonBook.dat",ios::out|ios::binary|ios::app); fout.open("temp.dat",ios::out|ios::binary); cout<<"Enter Serial Number of Record To Delete : "; cin>>n; while(fin.read((char*)&x,sizeof(x))) { if(n==x.getSrNo()) { cout<<"\nThe Following record is deleted....\n"; x.showData(); flag++; } else { fout.write((char*)&x,sizeof(x)); } } fin.close(); fout.close(); if(flag==0) { cout<<"\nThe Record of Serial Number "<<n<<" is not in file....\n"; cout<<"\nReading of Data File Completed......\n"; remove("PhonBook.dat"); rename("temp.dat","PhonBook.dat"); } int Update_Record() { fstream fio; int n, flag=0,pos; fio.open("PhonBook.dat",ios::out|ios::binary|ios::in); cout<<"Enter Serial Number of Record To Modify : "; cin>>n; while(fio.read((char*)&x,sizeof(x))) { pos=fio.tellg(); if(n==x.getSrNo()) { cout<<"\nThe Following record will be modified....\n"; x.showData(); flag++; cout<<"\nRe-Enter the New Details.....\n"; x.storeData(); fio.seekg(pos-sizeof(x)); fio.write((char*)&x,sizeof(x)); cout<<"\n....Data Modified Successfully....\n"; } } fio.close(); if(flag==0) cout<<"\nThe Record of Serial Number "<<n<<" is not in file....\n"; cout<<"\nReading of Data File Completed......\n"; } void menu() { int ch; do { //clrscr(); cout<<"............................................\n"; cout<<" PHONE BOOK MANAGEMENT\n"; cout<<"............................................\n\n"; cout<<"::::::::::::::: PROGRAM MENU :::::::::::::::\n"; cout<<"0. Exit\n"; cout<<"1. Save New Phone Record\n"; cout<<"2. Display All Saved Records\n"; cout<<"3. Search Specific Record\n"; cout<<"4. Delete Specific Record\n"; cout<<"5. Modify Existing Record\n"; cout<<"Enter Your Choice "; cin>>ch; //clrscr(); switch(ch) { case 1: NumberSum(); break; case 2: Show_Records(); break; case 3: SearchWithSerialNumber(); break; case 4: Record_Deletion(); break; case 5: Update_Record(); break; } getch(); } while(ch); } int main() { menu(); return 0; } |