C++ Phone Number List. This program should have an array of at least 10 string o
ID: 667802 • Letter: C
Question
C++
Phone Number List.
This program should have an array of at least 10 string objects using char [ ] WITHOUT using the strstr function . The array will hold people’s names and phone numbers. The following list is an example of the data in the array.
"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, 678-4939",
"Ron Palmer, 486-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, 223-8787
Ron Palmer, 486-2783
NOTE: if the user enters “Pal” it should produce the same output.
Explanation / Answer
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main ()
{
/*the str4[][25] is an array multidimensional*/
char str4[][25] ={ "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, 678-4939",
"Ron Palmer, 486-2783"};
int i,j,k, match=0 ;
char search [25];
printf("Please enter a name or partial name to search for in the array ");
cin.getline(search,25);
/*with cin.getline we obtain the string to search */
for (i=0; i<=10; i++) /*i is the number of register*/
{j=0; /*j is the number of character inside of the each register*/
while (str4[i][j]!='')/*the char '' is the last char inside a string, before i used strlen to know when the string over*/
{
if (search[0]==str4[i][j])
{ k=0;
match=0;
{while (search[k]==str4[i][j+k]&& match==0)
{k=k+1;
if (search[k]=='')
{printf("%s ",str4[i]);
match=1;}
}
}
}
j=j+1;
};
};
return 0;
}
/*any question please leave a comment*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.