Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Visual C++ program that reads in a list of unformatted phone number str

ID: 3663101 • Letter: C

Question

Create a Visual C++ program that reads in a list of unformatted phone number strings and converts each one into another string that has the form: (area) prefix-number.

Your program must loop and prompt the user to input a list of raw phone number strings. Each raw phone number will be specified on a separate input line starting in column 1. The end of the input data is detected when the user hits "Enter" and inputs a line with no characters on it (zero length).

A raw phone number string will be either 10 digits in length or 7 digits in length (e.g., with no area code specified). If no area code is specified in the raw string, then your program must convert the 7 digit phone number into a 10 digit new string using the default area code "206".

For example,

2062812945       must be converted into a new string with value: "(206) 281-2945".

4253372797       must be converted into a new string with value: "(425) 337-2797".

9974321             must be converted into a new string with value: "(206) 997-4321". ( CONVERTT 7 LAST DIGIT BY ADDING 206 IN THE FRONT)

As your program reads through the input data, it must process each incoming raw phone number, creating the new string variable with the converted data and outputting a report showing both the raw phone number and the converted formatted phone number. Also, if the phone number prefix is either "281" or "286" then the output must indicate that the phone number is an "SPU" phone number.(IT'S NOT 281 or 286 THAT IN THE FRONT, YOU HAVE TO VALIDATE THE NEXT 3 NUMBERS AFTER THE FIRST 3 NUMBERS!!!) For example, the output for one of the raw input numbers might look like:

Enter an unformatted phone number > 2062812945

Unformatted phone number: 2062812945

Formatted phone number: (206) 281-2945

This is an SPU phone number.

Finally, for this lab exercise:

•   You must use the "C-String" ASCIIZ array of characters datatype for all of the string values in the program, including storage for both the raw string value and storage for the converted value.

• You may not use the built-in "string" datatype for any variables in the program.

• You must create a single string that contains the full formatted phone number value.

• You can use other c-string variables for temporary manipulations if you need to.

•    You may use the any of the c-string functions (e.g., strcpy_s, strcat_s, strcmp, etc.), as well as manipulating the string buffers as arrays of characters using the ASCIIZ conventions.

•    You should use the cin.getline() operation to read each input line from the user and store it in a raw c-string array buffer variable.

• Your program should include the header file, e.g.,

#include

#include

using namespace std;

PLEASE READ CAREFULLY THE LINE THAT I BOLD

Explanation / Answer

#include<iostram>

#include<string.h>

using namespace std;

int main() {

char buff[15];

buff[0] = '';

char final[15];

while(1) {

cout<<"Enter your phone number";

if(strlen(buff) == 0){ break ; }

int length = strlen(buff);

int prefix = 0;

int k = 0;

final[k++] = '(';

if(length == 7) {

final[k++] = '2';

final[k++] = '0';

final[k++] = '6';

}else{

     for(int i=0;i <3 && buff[i] !=''; i++){

     final[k++] = buff[i];

   }

}

final[k++] = ')';

final[k++] = ' ';

if(length == 7) {

for(int i=0;i <3 && buff[i] !=''; i++){

     prefix = prefix*10 + (buff[i] - '0');

     final[k++] = buff[i];

}

}else{

for(int i=3;i <6 && buff[i] !=''; i++){

     prefix = prefix*10 + (buff[i] - '0');

     final[k++] = buff[i];

}

}

final[k++] = '-';

if(prefix == 281 || prefix == 286) {

       cout<<"This is SPU phone number";

}

if(length == 7) {

for(int i=3;i <7 && buff[i] !=''; i++){

     final[k++] = buff[i];

}

}else{

for(int i=6;i <10 && buff[i] !=''; i++){

     final[k++] = buff[i];

}

}

final[k] = '';

cout<<final;

}

return 0;

}