Question

Phone Number Problem (Use Object-Oriented Programming Style. Otherwise there will be no credit) Write a C++ program that canNote: In a telephone number, if a digit was given by an explicit character, like A or a, that character was fixed and sho

Phone Number Problem (Use Object-Oriented Programming Style. Otherwise there will be no credit) Write a C++ program that can convert any 7-digit telephone number into corresponding words where the equivalence of each digit and its corresponding characters is defined in the telephone keypad, which is shown in the following table: ABC 4 1 JKL MNO 8 TUV WXYZ In the keypad, there is no equivalence for digit 1 and 0, but in reality, the phone number might contain those two digits. So, with the digit 1, just leave it to 1, and with the digit 0, just leave it to 0 in the words found. All the possible words found must be displayed on the screen and (at the same time) written to a text file with a 4-columns format. The total number of words found must also be included in the file. All columns must be aligned properly.
Note: In a telephone number, if a digit was given by an explicit character, like 'A' or 'a', that character was fixed and should not be replaced by any other characters. Lastly, as usual, your name as a programmer must be displayed on the screen at the end of the program execution. The following is a sample of a run: 123MESA 1. 1adMESA 2. 1aeMESA 3. 1afMESA 4. 1bdMESA 7. 1cdMESA 8. 1ceMESA 5. 1beMESA 6. 1bfMESA 9. 1cfMESA
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
class phone//class that creates objects of converted text
{
public:
string id;
phone() {}
phone(char a)
{
switch (a)
{
case '2':
id = "abc";
break;
case '3':
id = "def";
break;
case '4':
id = "ghi";
break;
case '5':
id = "jkl";
break;
case '6':
id = "mno";
break;
case '7':
id = "pqrs";
break;
case '8':
id = "tuv";
break;
case '9':
id = "wxyz";
break;
default:
id = a;
}
}
~phone() {}
};
vector<string> ans; //final vector of answer
void save()//function to save final text
{
ofstream final("ans.txt");
for (auto it = ans.begin(); it != ans.end(); it++)
{
final << it - ans.begin() + 1 << ". " << *it << "\t\t";
if ((it - ans.begin() + 1) % 4 == 0 && (it - ans.begin() + 1) != 0)
final << endl;
}
}
string fact(vector<string> main, int i, string temp)//recursive function to calculate all possible combinations
{
if (i == main.size())
{
ans.push_back(temp);
return "";
}
for (int j = 0; j < main[i].length(); j++)
{
fact(main, i + 1, temp + main[i][j]);
}
return "";
}
int main()
{
cout << "Enter Mobile No\t";
string no;
vector<string> temp;//temporary vector of strings to store decoded text
cin >> no;
for (int i = 0; i < no.length(); i++)
{
char a = no[i];
phone ab(a);//create object
temp.push_back(ab.id);
ab.~phone();//destroy object
}
string g = fact(temp, 0, "");//call recurssive function to calculate final answer
for (auto it = ans.begin(); it != ans.end(); it++)
{
cout << it - ans.begin() + 1 << ". " << *it << "\t\t";//some indentation
if ((it - ans.begin() + 1) % 4 == 0 && (it - ans.begin() + 1) != 0)
cout << endl;
}
save();//call save
}

Enter Mobile No 123MESA 1. 1adMESA 5. 1beMESA 9. 1cfMESA PS E: \fixer> 2. laeMESA 6. 1bfMESA 3. 1afMESA 7. 1cdMESA 4. 1bdMESA

ans.txt - Notepad File Edit Format View Help 1. 1adMESA 5. 1beMESA 3. 1afMESA 4. 1bdMESA 2. 1aeMESA 6. 1bfMESA 7. 1cdMESA 8.

COMMENT DOWN FOR ANY QUERIES AND,

LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.

Add a comment
Know the answer?
Add Answer to:
Phone Number Problem (Use Object-Oriented Programming Style. Otherwise there will be no credit) Write a C++ program tha...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • hello. i need help with number 2 ONLY 1. Use if statements to write a Java...

    hello. i need help with number 2 ONLY 1. Use if statements to write a Java program that inputs a single letter and prints out the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way 2=ABC 3 = DEF 4 GHI 5 JKL 6 - MNO 7 - PRS 8 - TUV 9-WXY No digit corresponds to either Qor Z. For these 2 letters your program should print a message indicating that they...

  • Write a new program (hw6-pr1) meeting at least the following minimum requirements: Opens the text version...

    Write a new program (hw6-pr1) meeting at least the following minimum requirements: Opens the text version of this file (hw6-Spring2017.txt) and searches thru the file for the first occurrence of each of the 26 uppercase characters of the alphabet (A-Z), then each the 10 digits (0-9), and finally each of the 26 lowercase characters of the alphabet (a-z). As it finds each of these characters it should also record its position in the file (assume the first character in the...

  • Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To...

    Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To compile, build, and execute an interactive program with a simple loop, conditions, user defined functions and library functions from stdio.h and ctype.h. You will write a program that will convert characters to integers and integers to characters General Requirements • In your program you will change each letter entered by the user to both uppercase AND lowercase– o Use the function toupper in #include...

  • Write a program **(IN C)** that displays all the phone numbers in a file that match the area code...

    Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...

  • Regular C Programming It is just a random generator of telephone numbers DESCRIPTION To make telephone...

    Regular C Programming It is just a random generator of telephone numbers DESCRIPTION To make telephone numbers easier to remember, some companies use letters to show their telephone number, but mapping the letters to the numbers on a standard telephone keypad: 1 2 ABC 3 DE 4G 5 11 6 MNO 7 PONS 8 Tu 9.xyz # For example, using letters & spaces, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • Programming Concepts CS 225 for C++ To make telephone numbers easier to remember, some companies use...

    Programming Concepts CS 225 for C++ To make telephone numbers easier to remember, some companies use digits and letters (or only letters) to show their telephone number. In some cases, to make a telephone number meaningful, companies might use more than seven digits and letters. Here are some examples: Phone Number in Display Note Actual Phone Number GET LOAN - 438-5626 CALL HOME More than seven digits/letters used for ease of remembrance. 225-5466 111 GOLD - 111-4653 Glass4u - 452-7748...

  • . . In this programming assignment, you need to write a CH+ program that serves as...

    . . In this programming assignment, you need to write a CH+ program that serves as a very basic word processor. The program should read lines from a file, perform some transformations, and generate formatted output on the screen. For this assignment, use the following definitions: A "word" is a sequence of non-whitespace characters. An "empty line" is a line with no characters in it at all. A "blank line" is a line containing only one or more whitespace characters....

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT