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

2013 Visual studio C++ When a new customer\'s information is entered into a comp

ID: 3822140 • Letter: 2

Question

2013 Visual studio C++

When a new customer's information is entered into a computer program the information should be verified to be of an appropriate format. For instance a zip code should be all numerical digits and of length five. Write a program which accepts a phone number in the form of a string and detects whether it is valid. Verify the following: The phone number is of length 12 If is of the format ###-###-#### where a # is a numerical digit Detect if a dash is not present Detect that a numerical digit is present in all the locations that have a # Finally, prints to the console "Phone Number is valid" if the input is valid and "Phone Number is not valid" otherwise.

Explanation / Answer

Dear Student,

Here is the complete C++ code....

NOTE: Please note that the following program has been tested on ubuntu 14.04 system and compiled under g++ compiler..

program...

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

#include<iostream>

#include<stdlib.h>

#include<string.h>

using namespace std;

int main()

{

int s;

char phone_number[100];

char c;

int pos=0;

int i;

cout<<"Please enter a phone number:";

cin>>phone_number;

s = strlen(phone_number);

while(phone_number[pos] != '')

{

if(phone_number[3] !='-' && phone_number[7] !='-' && s != 12)

{

cout<<"Phone number is invalid."<<endl;

}

/*else

{

cout<<"Phone number is valid"<<endl;

}*/

pos++;

}

return 0;

}

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

Here i have attached the output as a screen shot...

Output...
-----------------------------------------------------------------------------------------------------------------------------------------