Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Correct any errors in the following code: // Lab 1: telephoneWords.cpp #include #include #include using namespace std; void wordGenerator( const int * const ); int

Correct any errors in the following code:

// Lab 1: telephoneWords.cpp #include #include #include using namespace std;

void wordGenerator( const int * const );

int main() { int phoneNumber[ 7 ] = { 0 }; // holds phone number

// prompt user to enter phone number cout

// loop 8 times: 7 digits plus hyphen; // hyphen is not placed in phoneNumber for ( int u = 0, v = 0; u { int i = cin.get();

// test if i is between 0 and 9 if ( i >= '0' && i => phoneNumber[ v++ ] = i - '0'; } // end for

wordGenerator( phoneNumber ); // form words from phone number } // end main

// function to form words based on phone number void wordGenerator( const int * const n ) { // set output stream and open output file /* Write a declaration for an ofstream object called outFile to open the file "phone.dat" */

// letters corresponding to each number /* Write a declaration for an array of 10 const char *'s called phoneLetters. Use an initializer list to assign each element of the array the corresponding string of three letters. Use dummy characters for 0 and 1 */

// terminate if file could not be opened /* Write code to check if the file was opened successfully, and terminate if not */

int count = 0; // number of words found

// output all possible combinations for ( int i1 = 0; i1 => { for ( int i2 = 0; i2 => { for ( int i3 = 0; i3 => { for ( int i4 = 0; i4 => { for ( int i5 = 0; i5 => { for ( int i6 = 0; i6 => { for ( int i7 = 0; i7 => { /* Write a series of cascaded stream insertion operations to output a set of seven letters to outFile, followed by a space */

if ( ++count % 9 == 0 ) // form rows outFile } // end for } // end for } // end for } // end for } // end for } // end for } // end for

// output phone number outFile

for ( int i = 0; i { if ( i == 3 ) outFile

outFile } // end for

/* Write a statement to close the ouput file */ } // end function wordGenerator

1. To determine every possible seven-letter word, you will need to use seven nested for loops and an array of char *, which can be thought of as a two-dimensional array of chars, containing the three letters that correspond to each digit.

2. To write a particular seven-letter word, output one character at a time. Use the array of char *s, the first subscript of which will be the digit from the phone number and the second subscript of which will be the counter variable from the for loop that corresponds to this digit (i.e., the first letter will use the counter variable from the first, outermost for loop).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Design Operation And Evaluation Of Mobile Communications

Authors: Gavriel Salvendy ,June Wei

1st Edition

3030770249, 978-3030770242

More Books

Students also viewed these Programming questions

Question

define and assess job burnout, boredom at work and work engagement;

Answered: 1 week ago