Write a program that has an array of at least 10 string objects that hold people
ID: 3539280 • Letter: W
Question
Write a program that has an array of at least 10 string objects that hold people s names and phone numbers. 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 search shall return all results with no typos, or one letter typo, or one digit typo with the same string length of the entered search pattern. The letters including a-z and A-Z characters. The digits include 0-9. No other characters are not required to be included in this program. For example, *case 1: search on "8765" also returns the following matched patterns: "8767", "8865", "8715", ...etc. *case 2: search on "abcd" also returns the following matched patterns: "abcb", "zbcd", "abad", ...etc. The output shall display the entire record the same as in the program charllenge 10-18. Hint: To search on pattern (key) with one typo actually make the search to expand the number of search patterns (keys).Explanation / Answer
#include <boost/algorithm/string.hpp>
#include <string>
#include <iostream>
#include <cstring>
#include<cctype>
using namespace std;
string toLower(string);
bool pfind(string,string);
void menu()
{
cout << " === Lab5 Test Menu === "
<< " search "
<< " insert "
<< " delete "
<< " modify "
<< " quit - this program "
<< " Enter your command: ";
}
int main()
{
// to be replaced with a dynamic linked list for next assignment
const int num=10; // a test driver for this exercise;
string pattern,lower_pattern,lower_entry;
string contact[]={
"Becky Warren, 5551223",
"Jeo Looney, 2340097",
"Geri Palmer, 5668788",
"Lynn Presnell, 7671212",
"Holly Gaddis, 2383881",
"Sam Wiggins, 5550998",
"Bob Kain, 5668712",
"Tim Haynes, 5897676",
"Warren Gaddis, 5669037",
"Ron Palmer, 2344939"};
cout << "Here are the list of contact information available :"<<endl;
for (int i=0;i<10;i++)
cout << contact[i] <<endl;
while(true){
string option; // user command
menu();
getline(cin, option);
if(option == "search") {
int count=0; // counting matches
cout<<endl<<"Enter partial information to search :";
getline(cin,pattern);
lower_pattern=toLower(pattern);
if(pattern.size()<=2) {
cout << "Search keyword has to be 3 or more characters! ";
}
else {
cout<<endl<<"The result(s) found: "<<endl;
// traversal through the contact list
for(int i=0;i<num;i++)
{
lower_entry=toLower(contact[i]);
// the included "fixed pattern" pfind() shall be replaced with
// "variant pattern" version of pfind() by you.
if (pfind(lower_pattern,lower_entry))
{
cout<<contact[i]<<endl;
count++;
}
}
if(count==0)
cout <<pattern<<" can NOT be found in the directory. ";
else cout << count << " entries matches " << pattern << ". ";
}
} // end of search
// the following command options are for assignment for the linked list
else if( option == "insert" ){ // insert entry
cout << " The quote: " << pattern << endl;
}
else if( option == "delete" ){ // delete entry
cout << " The quote: " << pattern << endl;
}
else if( option == "modify" ){ // modify entry
cout << " The quote: " << pattern << endl;
}
else if(option == "quit"){
cout << endl << "GOOD BYE :) "<< endl;
break;
}
else
cout << endl<< "INVALID INPUT " ;
} // end of menu loop
return 0;
}
bool pfind(string pattern,string an_entry)
{
>>>>>>>>>>>>>>>>>>>>//HELP
int i,j,m,n,p,char_count=0;
// method one, use the c_str.
//
// index i -> pattern[i]
// ^m
// index j -> an_entry[j]
// ^n
//
// method two, use the string class
std::size_t found = an_entry.find(pattern);
if (found==std::string::npos)
return false;
>>>>>>>>>>>>>>>>>>>//HELP
return true;
}
string toLower(string s)
{
int i;
for(i=0;i<s.length();i++)
s[i] = tolower(s[i]);
return s;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.