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

You are required to write a program that takes a phone number asinput from the u

ID: 3618834 • Letter: Y

Question

You are required to write a program that takes a phone number asinput from the user and stores it as a string value. The phonenumber will consist of country code, city code and actual 7-digitnumber separated by “-”. User can enter the phonenumber in any order. Your program should be able to recognize thecountry code, city code and 7-digit number and display it in thefollowing format.

Detailed Description:

1. Take phone number as input from the user.

2. The number should be stored as a string value.

3. User can enter the phone number in any order for example0092-333-1234567 or333-0092-1234567 or1234567-333-0092 etc.

4. Program should be able to recognize country code, city codeand 7-digit number from the string and display it in the rightsequence.

Sample Output 1  

Enter the complete phone number :0092-1234567-333

Country code is = 0092

City code is = 333

7-digit number is = 1234567

Phone number in correct sequence is = 0092-333-1234567

Sample Output 2

Enter the complete phone number :1234567-321-0092

Country code is = 0092

City code is = 321

7-digit number is = 1234567

Phone number in correct sequence is = 0092-321-1234567

Sample Output 3

Enter the complete phone number :300-0092-9876543

Country code is = 0092

City code is = 300

7-digit number is = 9876543

Phone number in correct sequence is = 0092-300-9876543

HINTS:

You can split the string into three parts and store each part asdifferent string.

You should use strtok, strlen, and strcat functions for solvingthis assignment.

Detailed Description:

1. Take phone number as input from the user.

2. The number should be stored as a string value.

3. User can enter the phone number in any order for example0092-333-1234567 or333-0092-1234567 or1234567-333-0092 etc.

4. Program should be able to recognize country code, city codeand 7-digit number from the string and display it in the rightsequence.

Sample Output 1  

Enter the complete phone number :0092-1234567-333

Country code is = 0092

City code is = 333

7-digit number is = 1234567

Phone number in correct sequence is = 0092-333-1234567

Sample Output 2

Enter the complete phone number :1234567-321-0092

Country code is = 0092

City code is = 321

7-digit number is = 1234567

Phone number in correct sequence is = 0092-321-1234567

Sample Output 3

Enter the complete phone number :300-0092-9876543

Country code is = 0092

City code is = 300

7-digit number is = 9876543

Phone number in correct sequence is = 0092-300-9876543

HINTS:

You can split the string into three parts and store each part asdifferent string.

You should use strtok, strlen, and strcat functions for solvingthis assignment.

Explanation / Answer

please rate - thanks #include #include using namespace std; void fill(char[],char[],char[],char[]); int main() {char phone[17]; char country[8]; char city[3],number[7]; city[0]=''; country[0]=''; number[0]=''; char* str; int pos=0,n; coutphone; str = strtok (phone,"-"); fill(str,city,country,number); str=strtok(NULL,"-"); fill(str,city,country,number); str=strtok(NULL,"-"); fill(str,city,country,number); phone[0]=''; strcat(phone,country); strcat(phone,"-"); strcat(phone,city); strcat(phone,"-"); strcat(phone,number); cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote