Question

write a ContactBook in C++ ContactBook that holds 10 names with that names corresponding contact (last...

write a ContactBook in C++

  1. ContactBook that holds 10 names with that names corresponding contact (last name and first name of the owner).
  2. Ask the user to input up to 10 Contacts (It may be less. The user should have the ability to stop inputting Contacts whenever he wishes).

3.This class will store a list of Contacts in a stack allocated array of default capacity 10.

4.You must be able to add new contacts to a list, delete old contacts, update existing contacts, search for a contact, and display the entire contact list. All of these will be implemented as member functions. In addition you will have functions that will give you size of the list, get particular contact at a particular index location and any other necessary functions.

5.Write a driver program that will be a menu driven application. The program will create a single ContactBook which is empty in the main program. A menu will have the following options: 1) Add New Contact 2) Delete Old Contact 3) Display Contact Info (contact is identified by last name and first name) 4) Update Contact Info (contact is identified by last name and first name) 5) Display Entire Contact List 6)exit

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

kindly upvote.

#include<bits/stdc++.h>
#include<iostream>
#include<string.h>
  
using namespace std;
  
#define MAXCONTACTS 10

int TOP;

struct stack_contact
{
int phoneNum; //to store phone number
char firstName[100]; //to store contacts first name
char lastName[100]; //to store contacts last name
};
stack_contact CONTACTS[MAXCONTACTS];


//stack initialization
void initialisestackcontact(){
TOP=-1;
}
// check if stack is empty or not
int isContactStackEmpty()
{
if(TOP==-1)
return 1;
else
return 0;
}

//check if stack is full or not
int isContactStackFull()
{
if(TOP==MAXCONTACTS-1)
return 1;
else
return 0;
}

void push(int phNum,char tempfirstName[],char templastName[])
{
if(isContactStackFull())
{
cout<<"Contact list is FULL.please delete some and add agin"<<endl;
return;
}
++TOP;
CONTACTS[TOP].phoneNum=phNum;
  
strcpy(CONTACTS[TOP].firstName,tempfirstName);
strcpy(CONTACTS[TOP].lastName,templastName);
cout<<phNum<<" has been inserted."<<endl;
}

void displayAllContacts()
{
int i;
if(isContactStackEmpty())
{
cout<<"contact list is EMPTY."<<endl;
return;
}
for(i=TOP;i>=0;i--){
cout<<CONTACTS[i].phoneNum<<","<<CONTACTS[i].firstName<<","<<CONTACTS[i].lastName << endl;
}
cout<<endl;
}

//DeleteContact - to remove item
void DeleteContact()
{
int temp;
if(isContactStackEmpty())
{
cout<<"contacts list is EMPTY."<<endl;
return;
}

temp=CONTACTS[TOP].phoneNum;
TOP--;
cout<<temp<<" contact has been deleted."<<endl;   
}
void print_contact(stack_contact e)
{
cout<<e.phoneNum<<" "<<e.firstName<<" "<<e.lastName;
}

void searchContact(char tempfirstName[],char templastName[])
{
for(int i=TOP;i>=0;i--)
{
if((strcmp(CONTACTS[i].firstName,tempfirstName) == 0) &&
(strcmp(CONTACTS[i].lastName,templastName)==0))
{
cout << "contact matched and found" << endl;
print_contact(CONTACTS[i]);
}
}

}
void updateContact(char tempfirstName[],char templastName[])
{
char first[100],last[100];

   int phone;
for(int i=TOP;i>=0;i--)
{
if((strcmp(CONTACTS[i].firstName,tempfirstName) == 0) &&
(strcmp(CONTACTS[i].lastName,templastName)==0))
{
cout << "contact matched and found" << endl;
cout << "enter first , last name and phone to be updated to?" << endl;
cin >> first >> last >> phone;
strcpy(CONTACTS[i].firstName,first);
strcpy(CONTACTS[i].lastName,last);

  CONTACTS[i].phoneNum=phone;
cout<<CONTACTS[i].firstName<<" has been updated."<<endl;
}
}

}
int main()
{
int phoneNumber;
char firstName[100];
char lastName[100];
char reqFirstName[100];
char reqLastName[100];

initialisestackcontact();

char ch;

do{
int a;
cout<<"Chosse \n1.add contact\n"<<"2.delete contact\n"<<"3.display all contacts\n"
<<"4.display particular contacts\n" <<"5.update particular contacts\n";
cout<<"Please enter your choice: ";
cin>>a;
switch(a)
{
case 1:
cout<<"Enter a phone Number: ";
cin>>phoneNumber;
cout<<"Enter First Name:";
cin>>firstName;
cout<<"Enter Last Name:";
cin>>lastName;
push(phoneNumber,firstName,lastName);
break;

case 2:
DeleteContact();
break;

case 3:
displayAllContacts();
break;
  
case 4:
cout <<"enter last name to be serached:";
cin>>reqLastName;
cout<<"enter first name to be searched:";
cin>>reqFirstName;
searchContact(reqFirstName,reqLastName);
break;
  
case 5:
cout <<"enter last name to be updated:";
cin>>reqLastName;
cout<<"enter first name to be updated:";
cin>>reqFirstName;
updateContact(reqFirstName,reqLastName);
break;

default :
cout<<"An Invalid Choice!!!\n";


}
cout<<"Do you want to continue ? ";
cin>>ch;
}while(ch=='Y'||ch=='y');
return 0;
}

output:

kindly upvote.

Thanks,

Chandana

Add a comment
Know the answer?
Add Answer to:
write a ContactBook in C++ ContactBook that holds 10 names with that names corresponding contact (last...
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
  • Please help!! (C++ PROGRAM) You will design an online contact list to keep track of names...

    Please help!! (C++ PROGRAM) You will design an online contact list to keep track of names and phone numbers. ยท         a. Define a class contactList that can store a name and up to 3 phone numbers (use an array for the phone numbers). Use constructors to automatically initialize the member variables. b.Add the following operations to your program: i. Add a new contact. Ask the user to enter the name and up to 3 phone numbers. ii. Delete a contact...

  • Problem: Contact Information Sometimes we need a program that have all the contact information like name,...

    Problem: Contact Information Sometimes we need a program that have all the contact information like name, last name, telephone, direction and something we need to know about that person (notes). Write a program in java language with GUI, classes, arrays, files and inheritance that make this possible. In the first layer, the user should see all the contacts and three buttons (add, delete, edit). *Add button: If the user click the button add, a new layer should appear and should...

  • C++ In this assignment, you will write a class that implements a contact book entry. For...

    C++ In this assignment, you will write a class that implements a contact book entry. For example, my iPhone (and pretty much any smartphone) has a contacts list app that allows you to store information about your friends, colleagues, and businesses. In later assignments, you will have to implement this type of app (as a command line program, of course.) For now, you will just have to implement the building blocks for this app, namely, the Contact class. Your Contact...

  • In C Write a function that asks for the user's first, middle, and last names. The...

    In C Write a function that asks for the user's first, middle, and last names. The names will be entered by the user on a single line and will be stored in three different C-strings. The program should then store, in a fourth array, the name arranged in the following manner: the last name followed by a comma and a space, followed by the first name and a space, followed by the middle name. For example, if the user entered...

  • Assignment Write a menu-driven C++ program to manage a class roster of student names that can...

    Assignment Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students...

  • Write a menu-driven C++ program to manage a class roster of student names that can grow...

    Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students Q...

  • Write a Java program that creates and manipulates a directory of names, telephone numbers. The following...

    Write a Java program that creates and manipulates a directory of names, telephone numbers. The following information will be stored for each person in the directory: - Name (Last, First) - Home telephone number You should keep the entire collection ordered by key value (the combination of last and first names). Your program should be able to perform the following basic functions: - Search and display the contents of a particular entry - Display the entire directory - Delete an...

  • a. Define the struct node that can store a name and up to 3 phone numbers...

    a. Define the struct node that can store a name and up to 3 phone numbers (use an array for the phone numbers). The node struct will also store the address to the next node. b. Define a class contactList that will define a variable to keep track of the number of contacts in the list, a pointer to the first and last node of the list. c. Add the following methods to the class: i. Add a new contact....

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

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