Write a program that has an array of at most 50 strings that hold people’s names and phone numbers. You can assume each string’s length is no more than 40. You may make up your own strings, or use the following: "Becky Warren, 555-1223" "Joe Looney, 555-0097" "Geri Palmer, 555-8787" "Lynn Presnell, 555-1212" "Holly Gaddis, 555-8878" "Sam Wiggins, 555-0998" "Bob Kain, 555-8712" "Tim Haynes, 555-7676" "Warren Gaddis, 555-9037" "Jean James, 555-4939" "Ron Palmer, 555-2783"
The program should ask the user to enter a name or partial name to search for in the array. Any entries in the array that match the string entered should be displayed. For example, if the user enters Palmer the program should display the following names from the list: Geri Palmer, 555-8787 Ron Palmer, 555-2783 The program prints the message “Enter a name or partial name to search for: ” and then after the user enters some input and hits return, the program prints the heading: “Here are the results of the search:”, followed by each matched string in the array on a line by itself.
Here is what I have so far:
int main()
{
int const SIZE = 50;
int const BLOCK = 40;
char input[BLOCK];
char arrNames[SIZE][BLOCK] = {
"Becky Warren, 555-1223",
"Joe Looney, 555-0097",
"Geri Palmer, 555-8787",
"Lynn Presnell, 555-1212",
"Holly Gaddis, 555-8878",
"Sam Wiggins, 555-0998",
"Bob Kain, 555-8712",
"Tim Haynes, 555-7676",
"Warren Gaddis, 555-9037",
"Jean James, 555-4939",
"Ron Palmer, 555-2783", };
cout << "Enter a name or partial name to
search for: ";
cin.getline(input, BLOCK);
#include<iostream>
#include <string>
using namespace std;
int const SIZE = 50;
int const BLOCK = 40;
int main()
{
// Create string array of names
string nameArray[SIZE] =
{
"Becky Warren, 555-1223",
"Joe Looney, 555-0097",
"Geri Palmer, 555-8787",
"Lynn Presnell, 555-1212",
"Holly Gaddis, 555-8878",
"Sam Wiggins, 555-0998",
"Bob Kain, 555-8712",
"Tim Haynes, 555-7676",
"Warren Gaddis, 555-9037",
"Jean James, 555-4939",
"Ron Palmer, 555-2783",
};
// Take user input of name to be searched
string input;
cout << "Enter a name or partial name to search for: ";
getline(cin,input);
// This variable remains -1, if names not found
int nameFoundIndex = -1;
bool isFound = false;
cout<<"Here are the results of the search: "<<endl;
// Iterate over array of names
// use string function find
// if name matches to a string, it returns the index of that
name
// if nameFoundIndex != -1 means, name found
// print name
// set isFound to true
for (int i = 0;i<SIZE;i++){
nameFoundIndex = nameArray[i].find(input);
if(nameFoundIndex!=-1){
cout<<nameArray[i]<<endl;
isFound = true;
}
}
// If isFound is not true, means no name found
if(!isFound){
cout<<"No name found!!"<<endl;
}
return 0;
}
OUTPUT-
Write a program that has an array of at most 50 strings that hold people’s names...
C++ with Pseudocode in the beginning This assignment will require you to write a program that will create an array of 10 string objects. The array will be initialized with the strings which contain the person’s name and phone number in one string. The following is an example of test data: “Renee Javens, 678-1223”, “Joe Looney, 586-0097”, “Geri Palmer, 223-8787”, “Lynn Presnell, 887-1212”, “Bill Wolfe, 223-8878”, “Sam Wiggins, 486-0998”, “Bob Kain, 586-8712”, “Tim Haynes, 586-7676”, “John Johnson, 223-9037”, “Jean James,...