Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this c program please convert into c++ program using array at queues. Please show the output of this program thank you. #include #include //size

"In this c program please convert into c++ program using array at queues. Please show the output of this program thank you."

#include

#include

//size of phonebook counter

int i=0;

struct phonebook

{

//store first name and last name and number

char fname[100],lname[100];

int number;

}p[100];//100 information

//insert method

void insert(char ch1[],char ch2[],int n)

{

strcpy(p[i].fname,ch1);

strcpy(p[i].lname,ch2);

p[i].number=n;

i++;// increment counter

}

//edit function

void edit(int num,char name[])

{

for(int j=0;j

{

if(p[j].number==num)

{

strcpy(p[j].fname,name);

break;

}

}

}

//search function

void search(char name[])

{

for(int j=0;j

{

if(strcmp(p[j].fname,name)==0)

{

printf("%s %s %d ",p[j].fname,p[j].lname,p[j].number);

break;

}

}

}

void display()

{

printf("Phonebook contact details are: ");

for(int j=0;j

{

printf("%s %s %d ",p[j].fname,p[j].lname,p[j].number);

}

}

//delete function

void delete(char name[])

{

for(int j=0;j

{

if(strcmp(p[j].fname,name)==0)

{

strcpy(p[j].fname,"");

strcpy(p[j].lname,"");

p[j].number=0;

break;

}

}

}

int main()

{

while(1)// displaying the menu

{

printf("-:PhoneBook:- ");

printf("1. Add ");

printf("2. Edit ");

printf("3. Search ");

printf("4. Show ");

printf("5. Delete ");

printf("6. Quit. ");

int option;// input the choice of the user

scanf("%d",&option);

if(option==1)

{

printf("Enter the first name: ");

char name[100];

scanf("%s",name);

if(strcmp(name,"")==0)

{

printf("you entered an empty string! ");

return 0;

}

printf("Enter last name: ");

char lname[100];

scanf("%s",lname);

if(strcmp(lname,"")==0)

{

printf("you entered an empty string! ");

return 0;

}

int number;

printf("Enter phone number: ");

scanf("%d",&number);

insert(name,lname,number);// call for insert function

printf("Item added successfully! ");

}

else if(option==2)

{

// input the number as it will be unique for everyone

printf("Enter the number where you want to change anything: ");

int num;

scanf("%d",&num);

printf("Enter first name to edit: ");

char name[100];

scanf("%s",name);

if(strcmp(name,"")==0)

{

printf("you entered an empty string! ");

return 0;

}

edit(num,name);// call for edit function

printf("Contact edited successfully! ");

}

else if(option==3)

{

printf("Enter the first name to search: ");

char name[100];

scanf("%s",name);

if(strcmp(name,"")==0)

{

printf("you entered an empty string! ");

return 0;

}

search(name);// call for search function

}

else if(option==4)

{

display();// call for display function

}

else if(option==5)

{

printf("Enter the first name: ");

char name[100];

scanf("%s",name);

if(strcmp(name,"")==0)

{

printf("you entered an empty string! ");

return 0;

}

delete(name);// call for delete function

printf("Contact deleted successfully! ");

}

else if(option==6)

break;

else

printf("You entered an incorrect number. ");

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions