Question

Phonebook This program is used to create a phonebook for storing contact information into a text...

Phonebook

This program is used to create a phonebook for storing contact information into a text file.

The program begins by asking the user to provide a name for the file that will contain their phone book information. It will then ask the user to provide the names and numbers of their contacts. It should keep asking the user for contact information until they type in Done (case-sensitive).

After the user types Done, store all contact information into the file name they provided at the beginning of the program. If the user does not add any contacts, then the file should be empty.

Please see the sample output below to guide the design of your program.

Sample Output:

Please provide the file name for your phone book: contacts.txt

Contact 1:
Please provide the name: Elsie Simon
Please provide their number: (202)555-0115

Contact 2:
Please provide the name: Kaisha Cope
Please provide their number: 5455689016

Contact 3:
Please provide the name: Sultan Vargas
Please provide their number: 371-998-4166

Contact 4:
Please provide the name: Done

Saving phonebook into contacts.txt

Done!

Please in simple in C++ code

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

Program Screenshots:

Sample Output:

Sample output file:contacts.txt

Code to Copy:

// Include the necessary header files.

#include <iostream>

#include <fstream>

#include<cstdlib>

// Define the namespace.

using namespace std;

// Start the main function.

int main()

{

// Declare variables.

fstream o_data;

string f_Name;

// Prompt the user to enter filename.

cout<<"please provide the file name for your phone book :";

getline(cin,f_Name);

// open the file.

o_data.open(f_Name.c_str());

// Check the condition.

if( !o_data ) {

cout << "Error: file unable to open" << endl;

exit(1);

}

// Declare variables.

int i=1;

string inp_name,num;

// Start the do wjile loop

do

{

// Prompt the uset ro enter the name.

cout<<"\nContact: "<<i<<endl;

cout<<"please provide the name: ";

getline(cin,inp_name);

// Check the condition.

if(inp_name=="Done")

break;

// Prompt the user to enter number.

cout<<"please provide their number: ";

getline(cin,num);

// Write the content in file.

o_data<<inp_name<<endl;

o_data<<num<<"\n"<<endl;

i++;

// end do while loop

}while(inp_name!="Done");

// Display the statement on console.

cout<<"\nSaving phonebook into "<<f_Name<<endl;

cout<<"\nDone!";

// CLose the file

o_data.close();

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Phonebook This program is used to create a phonebook for storing contact information into a text...
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
  • This program is used to create a phonebook for storing contact information into a text file....

    This program is used to create a phonebook for storing contact information into a text file. The program begins by asking the user to provide a name for the file that will contain their phone book information. It will then ask the user to provide the names and numbers of their contacts. It should keep asking the user for contact information until they type in Done (case-sensitive). After the user types Done, store all contact information into the file name...

  • Write a program that will maintain a personal phonebook.   The program should be menu driven. Create...

    Write a program that will maintain a personal phonebook.   The program should be menu driven. Create a new phonebook Print the phonebook Add person to the phonebook Remove a person from the phonebook Sort Modify a person Search for a person by name Save to a data file   (Can't be done but leave an error message if the user selects)    Retreive phonebook from data file  (Can't be done but leave an error message if the user selects) Quit Create a...

  • In this assignment, you will create an application that holds a list of contact information. You ...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. MUST BE IN PYTHON FORMAT Create the folllowing objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • In this assignment, you will create an application that holds a list of contact information. You...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. Must Be In Python Format Create the following objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • Write a contacts database program that presents the user with a menu that allows the user...

    Write a contacts database program that presents the user with a menu that allows the user to select between the following options: (In Java) Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...

  • Phonebook. You want to have a phone book that allows you to manipulate Contacts. A contact...

    Phonebook. You want to have a phone book that allows you to manipulate Contacts. A contact is made up of First Name, Last Name, Phone, Address, Birthday Date. (On java) Options: 1. Set number of contacts to store 2. Enter contact 3. Show entered contacts 4. Sort by last name 5. Sort by birthday day 6. Exit

  • Fix the following null pointer error. import java.util.*; import java.io.*; public class PhoneBook { public static...

    Fix the following null pointer error. import java.util.*; import java.io.*; public class PhoneBook { public static void main(String[]args)throws IOException { PhoneBook obj = new PhoneBook(); PhoneContact[]phBook = new PhoneContact[20]; Scanner in = new Scanner(System.in); obj.acceptPhoneContact(phBook,in); PrintWriter pw = new PrintWriter("out.txt"); obj.displayPhoneContacts(phBook,pw); pw.close(); } public void acceptPhoneContact(PhoneContact[]phBook, Scanner k) { //void function that takes in the parameters //phBook array and the scanner so the user can input the information //declaring these variables String fname = ""; String lname = ""; String...

  • language:python VELYIEW Design a program that you can use to keep information on your family or...

    language:python VELYIEW Design a program that you can use to keep information on your family or friends. You may view the video demonstration of the program located in this module to see how the program should function. Instructions Your program should have the following classes: Base Class - Contact (First Name, Last Name, and Phone Number) Sub Class - Family (First Name, Last Name, Phone Number, and Relationship le. cousin, uncle, aunt, etc.) Sub Class - Friends (First Name, Last...

  • 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...

  • 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...

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