Using C++ complete the following program10.18: Phone Number ListWrite a program that has an array of at least 50 string objects that hold people’s names and phone numbers. The program then reads lines of text from a file named phonebook  into the array.The program should ask the user to enter a name or partial name to search for in the array. All entries in the array that match the string entered should be displayed-- thus there may be more than one entry displayed.Prompts And Output Labels. The program prints the message "Enter a name or partial name to search for: " and then after the user enters a some input and hits return, the program skips a line, and prints the heading: "Here are the results of the search:", followed by each matched string in the array on a line by itself.Input Validation. None.

Question
Asked Nov 27, 2019
6 views

Using C++ complete the following program

10.18: Phone Number List
Write a program that has an array of at least 50 string objects that hold people’s names and phone numbers. The program then reads lines of text from a file named phonebook  into the array.

The program should ask the user to enter a name or partial name to search for in the array. All entries in the array that match the string entered should be displayed-- thus there may be more than one entry displayed.

Prompts And Output Labels. The program prints the message "Enter a name or partial name to search for: " and then after the user enters a some input and hits return, the program skips a line, and prints the heading: "Here are the results of the search:", followed by each matched string in the array on a line by itself.

Input Validation. None.

check_circle

Expert Answer

Step 1

Program Instructions:

  • Declare a string array phoneDirectory[] and open the file named “phonebook.txt".
  • Get the data from file and store in the array phoneDirectory[].
  • Get the input from user and use find() function to search for the phrase entered by the user in array.
Step 2

Program:

 

#include<iostream>

#include<fstream>

#include<string>

 

using namespace std;

 

int main()

{

     const int SIZE = 50;

     // array to hold phonenumber and name

     string phoneDirectory[SIZE];

     int size=0;

     string name;

     // file object

     ifstream inFile;

    

     inFile.open("phonebook.txt");

     // if file is present

     while (!inFile.fail()) {

          getline(inFile,phoneDirectory[size]);

          // to get the number of records in fle

          size++;

     }

     inFile.close();

    

     // get data from user to search

     cout << "Enter a name or partial name to search for: ";

     getline(cin, name);

    

     // print search result

     cout...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: How do I creat a switch statement in java for directions? Ex. North, South, East, West.

A: Switch statement: In Java, the switch statement is used to select a single statement out of multiple...

question_answer

Q: Problem 3 Guessing game: For this program, have the user guess a number from 1-5. Next, generate a r...

A: Program instructions:Create a form with two fields and one submit button.User enters the number in a...

question_answer

Q: The prompt asks: Write a function that calculates the amount of money a person would earn over a per...

A: Program Approach-1)Define function named totalEarned () with years as a parameter.2)Declare and init...

question_answer

Q: Write a program with python using random module for a (very) rudimentary shooter "game". You are the...

A: Program Algorithm-START-Step1: Import the essential modulesStep2: Define the shoot function.Step3: U...

question_answer

Q: Given the assumptions above and the page table below, translate the following virtual addresses (exp...

A: Assuming the page size to be 4KB. The calculations for physical addresses are given below: (a) VA = ...

question_answer

Q: List and describe four vulnerability intelligence sources. Which seems the most effective? Why?

A: Sources of Vulnerability IntelligenceSecurity VendorsSoftware VendorsGovernment and public organizat...

question_answer

Q: Forest and domain functional level means Windows Operating System version. which one applies? Member...

A: Explanation:A Windows Server 2008 functional level requires that all the Domain Controller (DC)s mus...

question_answer

Q: Given the following business rules, define the relationships between entities and cardinalities:   A...

A: Relationship between entitiesHere entities are university, school, department, professor and course....

question_answer

Q: Counting using while loops-Python (Using Pycharm Community edition) Ask the user for 3 inputs.  Tel...

A: A Python program for the given criteria is as follows,start=int(input("What is your starting number?...