#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()) {
#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
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.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
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.Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education