Your program must do the following: The list can take as many contacts as input
ID: 3827048 • Letter: Y
Question
Your program must do the following: The list can take as many contacts as input as user wants, a. For each contact, information such as full name. Phone number, email address, mailing address, birthday can be saved in the list b. The input for the program must be coming from the keyboard The program must show a Menu that runs until the user chooses to exit, and be able to allow the user to do the following tasks to the list: a. Add a New Contact to the list b. Search and Retrieve and Print on to the Screen a Contact from the list c. Delete a Contact from the list Make sure, your program: Uses modularity (with relevant methods) Very well commented Properly indented works correctlyExplanation / Answer
Sample code:
#include<iostream>
#include<stdlib.h>
using namespace std;
string *full_name;
int *phone_number;
string *email_addr;
string *mailing_addr;
string *bdate;
int main()
{
int size, i, ch;int count=0;string username;
do{
cout<<"1.Add contact"<<endl<<"2.Search contact"<<endl<<"3.Delete contact"<<endl;
cin>>ch;
switch(ch) {
case 1:
cout<<"How many elements for the array ? ";
cin>>size;
full_name = new string[size]; // dynamically allocate rollno array
phone_number = new int[size]; // dynamically allocate marks array
email_addr = new string[size]; // dynamically allocate rollno array
mailing_addr = new string[size]; // dynamically allocate rollno array
bdate = new string[size]; // dynamically allocate rollno array
if((!full_name) || (!phone_number) || (!email_addr) || (!mailing_addr) || (!bdate))
{
cout<<"Out of Memory..!!..Aborting..!! ";
cout<<"Press any key to exit..";
exit(1);
}
// read values in the array elements
for(i=0; i<size; i++)
{
cout<<"Enter name, phone number, email address, mailing address and birth date "<<(i+1)<<" ";
cin>>full_name[i]>>phone_number[i]>>email_addr[i]>>mailing_addr[i]>>bdate[i];
}
// now display the array contents
for(i=0; i<size; i++)
{
cout<<full_name[i]<<" "<<phone_number[i]<<" "<<email_addr[i]<<" "<<mailing_addr[i]<<" "<<bdate[i];
}
break;
case 2:
cout<<"Enter contact name to search ";
cin>>username;
for(i=0; i<size; i++)
{
if(full_name[i] == username){
cout<<" Name Phone Email Mailing Email Birth Date";
cout<<full_name[i]<<" "<<phone_number[i]<<" "<<email_addr[i]<<" "<<mailing_addr[i]<<" "<<bdate[i];
count++;
}
}
if(count==0)
{
cout<<"Contact not found..!!";
}
break;
case 3:
cout<<"Enter contact name to delete ";
cin>>username;
for(i=0; i<size; i++)
{
if(full_name[i] == username){
for(int j=i; j<(size-1); j++){
full_name[j] = full_name[j+1];
phone_number[j] = phone_number[j+1];
email_addr[j] = email_addr[j+1];
mailing_addr[j] = mailing_addr[j+1];
bdate[j] = bdate[j+1];
}
count++;
break;
}
}
if(count==0)
{
cout<<"Contact not found..!!";
}
else
{
cout<<"Contact deleted successfully..!! ";
cout<<"New contact list is : ";
cout<<" Name Phone Email Mailing Email Birth Date";
for(i=0; i<(size-1); i++)
{
cout<<full_name[i]<<" "<<phone_number[i]<<" "<<email_addr[i]<<" "<<mailing_addr[i]<<" "<<bdate[i];
}
}
break;
}
}while(ch>=1 && ch<=3);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.