#include using namespace std;   // Function to return a vector that contains // all the generated letter combinations vector letterCombinationsUtil(const int number[],int n,const string table[]) { // To store the generated letter combinations vector list;   queue q; q.push("");   while (!q.empty()) {

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
#include <bits/stdc++.h>
using namespace std;
 
// Function to return a vector that contains
// all the generated letter combinations
vector<string> letterCombinationsUtil(const int number[],int n,const string table[])
{
// To store the generated letter combinations
vector<string> list;
 
queue<string> q;
q.push("");
 
while (!q.empty())
{
string s = q.front();
q.pop();
 
// If complete word is generated
// push it in the list
if (s.length() == n)
{
list.push_back(s);
}
else
{
// Try all possible letters for current digit
// in number[]
for (autoletter : table[number[s.length()]])
{
q.push(s + letter);
}
}
}
// Return the generated list
return list;
}
 
// Function that creates the mapping and
// calls letterCombinationsUtil
void letterCombinations(const int number[], int n)
{
 
// table[i] stores all characters that
// corresponds to ith digit in phone
string table[10]
= { "0", "1", "abc", "def", "ghi",
"jkl", "mno", "pqrs", "tuv", "wxyz" };
 
vector<string> list
= letterCombinationsUtil(number, n, table);
 
// Print the contents of the vector
for (autoword : list)
cout << word << " ";
 
return;
}
 
// Driver code
int main()
{
intinput = 0;
intp = 0;
string w = "";
intnumber[] = { 2, 3 };
intn = sizeof(number) / sizeof(number[0]);
do
{
enumchoices{phone = 1, quit = 2};
cout << "What do you want to do?" << endl;
cout << "Enter 1 to enter phone number and word to find the possible matching strings" << endl;
cout << "Enter 3 to quit" << endl;
cin >> input;
switch(input)
{
case1:
cout << "Please enter phone number" << endl;
cin >> p;
cout << "Please enter word" << endl;
cin >> w;
cout << "Finding all possible matching stings..." << endl;
// Function call
letterCombinations(number, n);
//Need to print possible matching strings
break;
case2:
cout << "Thank you and good bye!" << endl;
break;
default:
cout << "Wrong choice. Enter again." << endl;
input = 0;
break;
}
}
while(input != 3);
return0;
}
 
 
How do i make it so that when I ask user to enter phone number and a word, it will print possible matching strings. Im confused on how to implement this. Please help.
Write a program that, when provided with a potential phone number (3569377) and
word (flower), returns all combinations containing the search word ("flowerp",
"flowerq", "flowerr", "flowers"). For reference the numbers of a phone keypad map
to letters as shown in the hash below. Note 0 and 1 do not have corresponding
letters.
Digit to Letter hash:
0: [""]
1: [""]
2: ["a","b","c"]
3: ["d","e","f"]
4: ["g","h","i"]
5: ["j","k","l"]
6: ["m","n","o"]
7: ["p","q","r","s"]
8: ["t","u","v"]
9: ["w","x","y","z"]
Transcribed Image Text:Write a program that, when provided with a potential phone number (3569377) and word (flower), returns all combinations containing the search word ("flowerp", "flowerq", "flowerr", "flowers"). For reference the numbers of a phone keypad map to letters as shown in the hash below. Note 0 and 1 do not have corresponding letters. Digit to Letter hash: 0: [""] 1: [""] 2: ["a","b","c"] 3: ["d","e","f"] 4: ["g","h","i"] 5: ["j","k","l"] 6: ["m","n","o"] 7: ["p","q","r","s"] 8: ["t","u","v"] 9: ["w","x","y","z"]
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education