I need the code in C++ not C. please dont forget to create the menu!!!!
Create a phone book program that allows users to enter
names
and phone numbers of friends and acquaintances. Create a
structure to hold contact information and use
to
calloc()
reserve the first memory segment. The user should be able to
add or modify phone book entries through a menu. Use the
function to add contiguous memory segments to the
realloc()
original memory block when a user adds a new phone book
entry.
PROGRAM SCREEN SHOT:
Sample output:
Code to copy:
// header files
#include<stdio.h>
#include<stdlib.h>
// structure that holds the name and number
struct phonebook{
// character array to store name
char contact[15];
// phone number
double phone_num;
};
// main function
int main()
{
// required variables
int t,i,total;
// structure type def
typedef struct phonebook phone;
// pointer array
phone *arr;
// calloc function
arr = (phone *)calloc(1,sizeof(phone));
// display message
printf("Select 1 to add number, otherwise 0:\t");
// take user input
scanf("%d",&t);
i = 1;
// iterate loop
while(t!=0)
{
// display message
printf("Enter the name:\t");
// take input as contact name
scanf("%s",arr[i-1].contact);
// diplay message
printf("Enter the phone no:\t");
// take input as phone number
scanf("%lf",&arr[i-1].phone_num);
// diplay mesasage
printf("Select 1 to add number, otherwise 0:\t");
// take input
scanf("%d",&t);
// increment the value
i++;
// realloc function
arr = (phone *)realloc(arr,i*sizeof(phone));
}
// assign total numbers
total = i;
// iterate loop
for(i=0;i<total-1;i++)
{ // display Name
printf("Name:\t%s",arr[i].contact);
// display phone number
printf("\tPhone no:\t%.0lf\n",arr[i].phone_num);
}
}
-----------------------------------------------------------------------
PLEASE UPVOTE.
Get Answers For Free
Most questions answered within 1 hours.