Question

Phonebook Management System C++ Phonebook management system project in C++ is a simple console application built without grap

project: c++ code with output
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:-

#include<fstream>
#include<string.h>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
class contact
{
   long ph;
   char name[20],add[20],email[30];
   public:
   void create_contact()
   {
       cout<<"Phone: ";
       cin>>ph;
       cout<<"Name: ";
       cin.ignore();
       cin>>name;
       cout<<"Address: ";
       cin.ignore();
       cin>>add;
       cout<<"Email address: ";
       cin.ignore();
       cin>>email;
       cout<<"\n";
   }
   void show_contact()
   {
       cout<<endl<<"Phone #: "<<ph;
       cout<<endl<<"Name: "<<name;
       cout<<endl<<"Address: "<<add;
       cout<<endl<<"Email Address : "<<email;
   }
   long getPhone()
   {
       return ph;
   }
   char* getName()
   {
       return name;
   }
   char* getAddress()
   {
       return add;
   }
   char* getEmail()
   {
       return email;
   }
};
fstream fp;
contact cont;
void save_contact()
{
   fp.open("phoneBook.txt",ios::out|ios::app);
   cont.create_contact();
   fp.write((char*)&cont,sizeof(contact));
   fp.close();
   cout<<endl<<endl<<"Phonebook Has Been Sucessfully Created...";
   getchar();
}
void display_contact(int num)
{
   bool found;
   int ch;
   found=false;
   fp.open("phoneBook.txt",ios::in);
   while(fp.read((char*)&cont,sizeof(contact)))
   {
       if(cont.getPhone()==num)
       {
           cont.show_contact();
           found=true;
       }
   }
   fp.close();
   if(found == false){
   cout<<"\n\nNo record found...";}
   getchar();
}
void show_all_contacts()
{
   cout<<"\n\t\t================================\n\t\t\tLIST OF CONTACTS\n\t   \t================================\n";
   fp.open("phoneBook.txt",ios::in);
   while(fp.read((char*)&cont,sizeof(contact)))
   {
       cont.show_contact();
       cout<<endl<<"=================================================\n"<<endl;
   }
   fp.close();
}
void modify_contact()
{
   int num;
   bool found=false;
   cout<<"Modify contact\n===============================\n\n\t..::Enter the number of contact to modify:";
   cin>>num;
   fp.open("phoneBook.txt",ios::in|ios::out);
   while(fp.read((char*)&cont,sizeof(contact)) && found==false)
   {
       if(cont.getPhone()==num)
       {
           cont.show_contact();
           cout<<"\nPlease Enter The New Details of Contact: "<<endl;
           cont.create_contact();
           int pos=-1*sizeof(cont);
           fp.seekp(pos,ios::cur);
           fp.write((char*)&cont,sizeof(cont));
           cout<<endl<<endl<<"\t Phonebook Successfully Updated...";
           found=true;
       }
   }
   fp.close();
   if(found==false)
   cout<<endl<<endl<<"Contact Not Found...";     
}
void delete_contact()
{
   int num;
   cout<<endl<<endl<<"Please Enter The contact #: ";
   cin>>num;  
   fp.open("phoneBook.txt",ios::in|ios::out);
   fstream fp2;
   fp2.open("Temp.txt",ios::out);
   fp.seekg(0,ios::beg);
   while(fp.read((char*)&cont,sizeof(contact)))
   {
       if(cont.getPhone()!=num)
       {
           fp2.write((char*)&cont,sizeof(contact));
       }
   }
   fp2.close();
   fp.close();
   remove("phoneBook.txt");
   rename("Temp.txt","phoneBook.txt");
   cout<<endl<<endl<<"\tContact Deleted...";
}
int main(int argc, char *argv[])
{
   for(;;)
   {  
       int ch;
       cout<<"\n\t **** Welcome to Phonebook Management System ****";
       cout<<"\n\n\n\t\t\tMAIN MENU\n\t\t=====================\n\t\t[1] Add Phone Record\n\t\t[2] Search Phone Records\n\t\t[3] Show Phone Records\n\t\t[4] Modify Phone Record\n\t\t[5] Delete Phone Record\n\t\t[0] Exit\n\t\t=================\n\t\t";
       cout<<"Enter the choice:";
       cin>>ch;
       switch(ch)
       {
           case 0:
               cout<<"\n\n\t\tThank you for using Phonebook Management System...";
               break;
           case 1:
               save_contact();
               break;
           case 2:
               int num;
               cout<<"\n\n\tPhone: ";
               cin>>num;
               display_contact(num);
               break;
           case 3:
               show_all_contacts();
               break;
           case 4:modify_contact();
               break;
           case 5:delete_contact();
               break;
           default:
               break;
       }
       int opt;
       cout<<"\n\n\n..::Enter the Choice:\n\n\t[1] Main Menu\t\t[0] Exit\n";
       cin>>opt;
       switch(opt)
       {
            case 1:
               continue;
       
           case 0:
               exit(10);
        }
   }
   return 0;
}

Output:-

C:\Users\Siva Kumar\Desktop\1.exe **** Welcome to Phonebook Management System **** MAIN MENU [1] Add Phone Record [2] Search

All the options are works fine in the provided code please ckeck and comment if you have any issues regarding this or for any modifications or doubts.

Please UPVOTE thank you...!!!

Add a comment
Know the answer?
Add Answer to:
project: c++ code with output Phonebook Management System C++ Phonebook management system project in C++ is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ write a simple menu program that displays a menu for the user in an...

    In C++ write a simple menu program that displays a menu for the user in an object-oriented technique. The menu should keep showing up until the user chooses to quit. Also, there is a sub-menu inside a menu. The user should get at least a line displayed after he or she chooses that particular option meaning if the user presses 1 for the read actors from the file. The output can look like "reading actors from a file" and then...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • write a program in C++ for the development of the library management system. The C++ program...

    write a program in C++ for the development of the library management system. The C++ program will allow the system administrator to add staff, students, delete the user's accounts, modify user details, add and modify book details. The administrator will have total control over the user account. The system will capture the student details such as registration number, phone number class code, and passwords, amongst other essential information. The librarian will search the books through the database using the ISBN,...

  • Serendipity Engineering, Inc. Software Development Project Program Specifications: Serendipity Engineering, Inc. is a small engineering company...

    Serendipity Engineering, Inc. Software Development Project Program Specifications: Serendipity Engineering, Inc. is a small engineering company located in a commercial park. The project manager wants you to develop a customer software package that will allow the company enter the customer information in the computer to keep a customer database. The software will perform the following tasks using menus: Enter Customer Information Display Customer Information Search Customer Information Organize (Sort) Customer Information Add, Delete, Modify, and Look Up Customer Records Save...

  • Programming

    Project Information: Develop a complete working application in C++ as a part of your DSA semester project. This may be an individual effort or a group contribution as per your personal preferences. In case of a group project, the maximum group size is to be two students only. Please ensure that your application should be a modular programming based solution to a problem employing the maximum concepts of data structure and algorithms (like stack, queues, link lists, and trees). You can take ‘help’ (and not copy+paste) from the Internet and other resources as long as you clearly understand and refer them in your program. Properly comment your program and use good programming practices (proper indenting, meaningful variable and function names, comments etc.)  Project Detail: Design and develop an application to automate a Library Management System. The detail of the application is as below: Your application should have a proper login. Functionality to Add, Delete, Search and Modify records of the books. A detail file (txt or binary) that includes the record of the books along with all the attributes like name of the book, author of the book, domain of the book (e.g computer science, sociology), publishing date. A function that computes how many books are in the library. A function that computes how many books of specific domain has been chosen by the applicant.  Application code must be divided as separate (.h, .cpp) files. Project Deliverable: All source code files. A project report comprising: Acknowledgement Problem Statement Objectives Salient features of your application Detail of each module of your application. A proper and understandable UML diagram of your application. Conclusion Note: Report should be properly formatted and it is mandatory to use English without grammatical mistakes.

  • Language: C++ PLEASE INCLUDE SCREENSHOT OF OUTPUT In this assignment, you will consider the problem of organizing a collection of computer user-ids and passwords. Each time a user logs in to the syste...

    Language: C++ PLEASE INCLUDE SCREENSHOT OF OUTPUT In this assignment, you will consider the problem of organizing a collection of computer user-ids and passwords. Each time a user logs in to the system by entering his or her user-id and a secret password, the system must check the validity of this user-id and password to verify that this is a legitimate user. Because this validation must be done many times each day, it is necessary to structure this information in...

  • Identify and list all the User defined Functions to be used in the system #include <stdio.h>...

    Identify and list all the User defined Functions to be used in the system #include <stdio.h> ///for input output functions like printf, scanf #include <stdlib.h> #include <conio.h> #include <windows.h> ///for windows related functions (not important) #include <string.h> ///string operations /** List of Global Variable */ COORD coord = {0,0}; /// top-left corner of window /** function : gotoxy @param input: x and y coordinates @param output: moves the cursor in specified position of console */ void gotoxy(int x,int y) {...

  • C++ project we need to create a class for Book and Warehouse using Book.h and Warehouse.h header ...

    C++ project we need to create a class for Book and Warehouse using Book.h and Warehouse.h header files given. Then make a main program using Book and Warehouse to read data from book.dat and have functions to list and find book by isbn Objectives: Class Association and operator overloading This project is a continuation from Project 1. The program should accept the same input data file and support the same list and find operations. You will change the implementation of...

  • Write a program in C++: Using classes, design an online address book to keep track of the names f...

    Write a program in C++: Using classes, design an online address book to keep track of the names first and last, addresses, phone numbers, and dates of birth. The menu driven program should perform the following operations: Load the data into the address book from a file Write the data in the address book to a file Search for a person by last name or phone number (one function to do both) Add a new entry to the address book...

  • Hello all, I have a c++/unix (bash) question. I am struggling on starting this assignment. If...

    Hello all, I have a c++/unix (bash) question. I am struggling on starting this assignment. If you could start the assignment and tell me how to do the rest it would be greatly appreciated! (Quick thumbs up answer response if thorough and correct) Maintain automobile records in a database Write a shell script to create, view and modify a simple database that contains automobile records. The shell script has to be done in Bourne shell syntax (bash as a matter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT