Question

In: Computer Science

(C++) keep things as simple as possible. I would love a good starting point with hints...

(C++) keep things as simple as possible. I would love a good starting point with hints to be able to finish it!

Write a function called is valid phone number that takes a phone number as an array of characters and its size, and returns true if the input array is a valid phone number, false otherwise. A phone number is valid only if it is of the following format: (uuu) uuu-uuuu where u is from ‘0’, ‘1’, ‘2’, etc. The parentheses, hypen and the space after ’)’ are necessary. Do not use the string or regex libraries

Solutions

Expert Solution

#include <iostream>

using namespace std;

//to check if u is in '0' to '9'

bool ir(char a)

{

    if(a>='0' && a<='9')

        return true;

    else

        return false;

}

//checking if given phone number is valid or not

//(uuu) uuu-uuuu (111) 985-1235

bool isvalid(char *str,int size)

{

    if(size!=14)

        return false;

    else

    {

        bool ans=false;

        if ((str[0]=='(') && (str[4]==')') && (str[5]==' ') && (str[9]=='-'))

        {

            if(ir(str[1]) && ir(str[2]) && ir(str[3]) && ir(str[6]) && ir(str[7]) && ir(str[8]) && ir(str[10]) && ir(str[11]) && ir(str[12]) && ir(str[13]) )

                ans=true;

        }

        return ans;

    }

}

int main()

{

    int size;

    cout << "Enter size: ";

    cin >> size;

    char str[size], ab[2];

    cin.getline( ab,2);

    cout << "Enter phone number: ";

    cin.getline( str,size+1);

    if(isvalid(str,size))

        cout<<"phone number is valid.";

    else

        cout<<"INVALID phone number";

    return 0;

}

//SAMPLE OUTPUT

//PLEASE LIKE IT RAISE YOUR THUMBS UP
//IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT SECTION


Related Solutions

USE C++ for the program and kindly keep it as simple as possible , use recursion...
USE C++ for the program and kindly keep it as simple as possible , use recursion and do not use loops please keep program simple and comment if possible Suppose you have been given the task to design a text editor which will take any multiline text from user and then display the statistics like total number of characters i.e., characters_count (excluding the white space and punctuations), words_count, and redundant_words_count. Create a structure named Text_Editor having four type members namely...
USE C++ and please keep program as simple as possible and also comment so it is...
USE C++ and please keep program as simple as possible and also comment so it is easy to understad Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the...
Some things that need to be added to it are: Make it as simple as possible...
Some things that need to be added to it are: Make it as simple as possible colors background colors fonts borders position everything horizontally Heres the code I have so far: <html>    <head>    <title> TheWebpage</title>               <meta charset="utf-8" />           </head>        <body>            <header>                <h1>Welcome to my first web page.</h1>            </header>                   <article>        <h1>Favorite dream vacation</h1>...
PROGRAM LANGUAGE IN C NOT C# or C++ KEEP IT SIMPLE EVEN IF IT IS REDUNDANT...
PROGRAM LANGUAGE IN C NOT C# or C++ KEEP IT SIMPLE EVEN IF IT IS REDUNDANT PLEASE. Problem: Driving Function driving(): Write a function driving(), that updates the odometer and fuel gauge of a car. The function will take in a reference to the variables storing the odometer and fuel gauge readings, along with a double representing the miles per gallon (mpg) the car gets and the number of miles the driver intends to go. The function should update the...
Please write in C++ as simple as possible I want you to create a Book Class...
Please write in C++ as simple as possible I want you to create a Book Class for a bookstore. I am not going to tell you what variables should go into it, that is for you to figure out (but you should have at least 5+). And then you must create a UML with all the variables and methods (like: the getters and setters, a default constructor, and a constructor that takes all the variables and finally the printValues() )....
Things are not as simple as up is good and down is bad (visa versa). Consider...
Things are not as simple as up is good and down is bad (visa versa). Consider the following statements. "A rise in long-term interest rates reflect good economic conditions" Versus "A rise in long-term interest rates reflects bad economic conditions." Both could be true. How is that possible?
A good starting point is to explore the life of Pythagoras and his contribution to the...
A good starting point is to explore the life of Pythagoras and his contribution to the world of mathematics, and one part of his life or his discoveries. supported with a detailed example.
Syntax error in C. I am not familiar with C at all and I keep getting...
Syntax error in C. I am not familiar with C at all and I keep getting this one error "c error expected identifier or '(' before } token" Please show me where I made the error. The error is said to be on the very last line, so the very last bracket #include #include #include #include   int main(int argc, char*_argv[]) {     int input;     if (argc < 2)     {         input = promptUserInput();     }     else     {         input = (int)strtol(_argv[1],NULL, 10);     }     printResult(input);...
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem...
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem you will take a list of names from the user and sort them alphabetically using selection sort. The code for selection sort for integer is available in the "Lab and Weekly Coding Solution module" in webcourses. Ask the user how many names the user wants to input. Let's say the number be N. Then take N number of names and put them in an...
Please keep it simple for Hyperbolic Geometry (the response I was given was great, but it...
Please keep it simple for Hyperbolic Geometry (the response I was given was great, but it was well beyond what we needed) Illustrate with a picture showing that the following are simply not true in Hyperbolic Geometry c). The angle sum of any triangle is 180 d). Rectangles exist
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT