Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program in C++ in netbeans that simulates a simple contact manager appl

ID: 3882411 • Letter: C

Question

Create a program in C++ in netbeans that simulates a simple contact manager application given the following requirements:

1. The program is to store individual names and associated telephone numbers in parallel arrays.

2. The program should input from the user 10 people’s names and their telephone numbers and add the data to the parallel arrays.

3. When data input is finished, the program should sort both data arrays in ascending order based on telephone numbers maintaining the associations between names and telephone numbers.

4. The program will print the list of users and their telephone numbers after sorting.

5. After printing the list, the program will ask for a name to search for.

6. The user will then enter a name.

7. The program will then search for the name and print the name and the associated telephone number for that person.

8. If the person is not in the array, the program will print that the user cannot be found.

Modify the program you created above, to create a searchable telephone, by doing the following: The code for the input portion of the program is to be in a function by itself. This function will add individuals and their telephone numbers to the appropriate arrays. The code that sorts the arrays will be in a separate function. The function should take a parameter that indicates whether to sort ascending or descending. The code for printing the data from the arrays will be in a separate function. The code for searching for an individual in the arrays is to be in a separate function. The program should give the user the following menu options: Input data Sort data Ascending Sort data Descending Print all data Search for an individual in the data. End program The program will call the appropriate function based on user choice and the program will return to the menu afterwards (i.e. a perpetual loop). The program will only end when the user chooses End Program.

Explanation / Answer

#include<fstream>

#include<conio.h>

#include<string.h>

#include<iomanip>

#include<iostream>

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<<" ";

}

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("contactBook.dat",ios::out|ios::app);

cont.create_contact();

fp.write((char*)&cont,sizeof(contact));

fp.close();

cout<<endl<<endl<<"Contact Has Been Sucessfully Created...";

getchar();

}

void show_all_contacts()

{

system("cls");

cout<<" ================================ LIST OF CONTACTS ================================ ";

fp.open("contactBook.dat",ios::in);

while(fp.read((char*)&cont,sizeof(contact)))

{

cont.show_contact();

cout<<endl<<"================================================= "<<endl;

}

fp.close();

}

void display_contact(int num)

{

bool found;

int ch;

found=false;

fp.open("contactBook.dat",ios::in);

while(fp.read((char*)&cont,sizeof(contact)))

{

if(cont.getPhone()==num)

{

system("cls");

cont.show_contact();

found=true;

}

}

fp.close();

if(found == false){

cout<<" No record found...";}

getchar();

}

void edit_contact()

{

int num;

bool found=false;

system("cls");

cout<<"..::Edit contact =============================== ..::Enter the number of contact to edit:";

cin>>num;

fp.open("contactBook.dat",ios::in|ios::out);

while(fp.read((char*)&cont,sizeof(contact)) && found==false)

{

if(cont.getPhone()==num)

{

cont.show_contact();

cout<<" Please 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<<" Contact Successfully Updated...";

found=true;

}

}

fp.close();

if(found==false)

cout<<endl<<endl<<"Contact Not Found...";

}

void delete_contact()

{

int num;

system("cls");

cout<<endl<<endl<<"Please Enter The contact #: ";

cin>>num;

fp.open("contactBook.dat",ios::in|ios::out);

fstream fp2;

fp2.open("Temp.dat",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("contactBook.dat");

rename("Temp.dat","contactBook.dat");

cout<<endl<<endl<<" Contact Deleted...";

}

int main(int argc, char *argv[])

{

system("cls");

system("color 03");

cout<<" * *";

cout<<" ** **";

cout<<" *** ***";

cout<<" **** ****";

cout<<" ***** *****";

cout<<" ****** ******";

cout<<" ******* *******";

cout<<" ******* *******";

cout<<" ****** ******";

cout<<" ***** *****";

cout<<" **** ****";

cout<<" *** ***";

cout<<" ** **";

cout<<" * *";

for(;;)

{

int ch;

cout<<" **** Welcome to Contact Management System ****";

cout<<" MAIN MENU ===================== [1] Add a new Contact [2] List all Contacts [3] Search for contact [4] Edit a Contact [5] Delete a Contact [0] Exit ================= ";

cout<<"Enter the choice:";

cin>>ch;

switch(ch)

{

case 0: cout<<" Thank you for using CMS...";

exit(0);

break;

break;

break;

case 1:save_contact();

break;

case 2:show_all_contacts();

break;

case 3:

int num;

system("cls");

cout<<" Phone: ";

cin>>num;

display_contact(num);

break;

case 4:edit_contact();

break;

case 5:delete_contact();

break;

default:

break;

}

  

  

  

int opt;

cout<<" ..::Enter the Choice: [1] Main Menu [0] Exit ";

cin>>opt;

switch (opt)

{

case 1:

system("cls");

continue;

case 0:

exit(0);

}

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote