Question

I need the code in C++ not C. please dont forget to create the menu!!!! Create...

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.

Homework Answers

Answer #1

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.

Know the answer?
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
Similar Questions
PLEASE USING C# TO SOLVE THIS PROBLEM. THANK YOU SO MUCH! a. Create a project with...
PLEASE USING C# TO SOLVE THIS PROBLEM. THANK YOU SO MUCH! a. Create a project with a Program class and write the following two methods (headers provided) as described below: - A Method, public static int InputValue(int min, int max), to input an integer number that is between (inclusive) the range of a lower bound and an upper bound. The method should accept the lower bound and the upper bound as two parameters and allow users to re-enter the number...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
The Business Case for Agility “The battle is not always to the strongest, nor the race...
The Business Case for Agility “The battle is not always to the strongest, nor the race to the swiftest, but that’s the way to bet ’em!”  —C. Morgan Cofer In This Chapter This chapter discusses the business case for Agility, presenting six benefits for teams and the enterprise. It also describes a financial model that shows why incremental development works. Takeaways Agility is not just about the team. There are product-management, project-management, and technical issues beyond the team’s control. Lean-Agile provides...
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation....
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation. case:    W17400 APIGEE: PEOPLE MANAGEMENT PRACTICES AND THE CHALLENGE OF GROWTH Ranjeet Nambudiri, S. Ramnarayan, and Catherine Xavier wrote this case solely to provide material for class discussion. The authors do not intend to illustrate either effective or ineffective handling of a managerial situation. The authors may have disguised certain names and other identifying information to protect confidentiality. This publication may not be...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT