Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Phone Number List. This program should have an array of at least 10 string o

ID: 667818 • Letter: C

Question

C++

Phone Number List.

This program should have an array of at least 10 string objects using char [ ] . 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.

C - Strings are NOT allowed. NO strstr, strlen, str.size etc. This program is for an introductory to programming, so please refrain from more advanced coding.

Explanation / Answer

The below code is used to read the details of n number of people details initially, then read the search name, and will print all the details which match the string:

#include <iostream>
#include <stdio.h>
using namespace std;
int found(char [], char []);
int main()
{
char details[10][20],key[10];
int n,i;
cout<<"Enter the number of people details you want to enter: ";
cin>>n;
cout<<"Enter "<<n<<" details:";
for(i=0;i<n;i++)
gets(details[i]);
cout <<"Enter the name or partial name to search: ";
cin>>key;
for(i=0;i<n;i++)
{
if(found(key,details[i]))
cout <<puts(details[i]);
}
}

int found(char key[], char details[])
{
int i, j, startpos;
i = 0, j = 0;

while (details[i] != '') {

while (details[i] != key[0] && details[i] != '')
i++;

if (details[i] == '')
return (0);

startpos = i;

while (details[i] == key[j] && details[i] != '' && key[j] != '') {
i++;
j++;
}

if (key[j] == '')
return 1;
if (details[i] == '')
return (0);

i = startpos + 1;
j = 0;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote