6.5k views
4 votes
Given a long integer representing a 10-digit phone number, output the area code, prefix, and line number using the format (800) 555-1212.

User AlexanderM
by
5.0k points

1 Answer

4 votes

Answer:

See explanation!

Step-by-step explanation:

Here we have a program written in C++ language. Each // symbol is a relative comment explaining the reason for each command line (and is not included during the program execution).

The Program:

#include <iostream>

//c++ build in library

using namespace std;

//main code body starts here

int main()

{

//declare variable to store phone numbers,its area code, prefix and line number.

long pnumber; //declare long variable

int ac, prefix, lnumber;

//declare integer variables, where ac: Area Code and lnumber is the Line Number

cout<<"Enter a 10-digit Phone Number: "<<endl;

//cout command prints on screen the desired message

cin>>pnumber;

//cin command enables the user to interact with the programm and enter information manually

//main body to obtain the desired output starts below

//each 'division' is used to allocate the correct value at the correct

//since prefix is used to get the desired output of ( ) -

ac = pnumber/10000000;

prefix = (pnumber/10000)%1000;

lnumber = pnumber%10000;

//main body ends here

cout<<"Based on your 10-digit number"<<endl;

cout<<"below you have (AreaCode), Prefix, and - line number "<<endl;

cout<<"("<<ac<<")"<<""<<prefix<<"-"<<lnumber<<endl;

//Prints on screen the desired output of the long 10 digit Number

return 0; //ends program

}

-------------------------------------------------------------------------------------------------------

The Output Sample:

Enter a 10-digit Phone Number:

8019004673

Based on your 10-digit number

below you have (Area Code), Prefix, and - line number

(801) 900-4673

....Programm finished with exit code 0

User Dewaun Ayers
by
5.1k points