in C++ make sure input for entering phone # is availible Given a long long integer representing a 10-digit phone number, write a function to segment this number into a three-digit area code a three-digit prefix a four-digit line number Ex: If the input is: 8005551212 It will be segmented into: 800, 555, and 1212.   Your code needs to       1.  declare a new datatype      struct StructuredPhoneNumber{    std::string areaCode="000";  //3 digits    std::string prefix="000"; //3 digits    std::string lineNo="0000"; // 4 digits };  2. Use the following function prototype to implement your algorithm: //converts a phone number from a 10-digit long long to {area code, prefix, lineNo} /returns a StructuredPhoneNumber object {"000", "000", "0000"} if the input number is negative or does not contain 10 digits.  StructuredPhoneNumber phoneNumBreakdown(long long phoneNum_ll);   3.  include three unit tests test1( ), test2(), and test3(), each of which returns true       if phoneNumBreakdown( ) correctly calculates the three piceces of info            For example:             bool test1()      {         //if you wish, you can print out a message here e.g., "my first test ...\n".        //call phoneNumBreakdown(8005551212) ;        //check the result      }       4.  overload the operator== to compare whether two StructuredPhoneNumber objects      contain exactly the same phone number. 5. include two unit tests to test the above overloaded operator==     bool test_operator1(){        //call the overloaded operator==        //check if it produces the expected result     }          bool test_operator2(){        //call the overloaded operator==        //check if it produces the expected result     } */

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

in C++

make sure input for entering phone # is availible

Given a long long integer representing a 10-digit phone number, write a function to segment this number into

  • a three-digit area code
  • a three-digit prefix
  • a four-digit line number

Ex: If the input is:

8005551212

It will be segmented into: 800, 555, and 1212.


  Your code needs to 
  
  1.  declare a new datatype
  
  struct StructuredPhoneNumber{
   std::string areaCode="000";  //3 digits
   std::string prefix="000"; //3 digits
   std::string lineNo="0000"; // 4 digits
};

 2. Use the following function prototype to implement your algorithm:

//converts a phone number from a 10-digit long long to {area code, prefix, lineNo}
/returns a StructuredPhoneNumber object {"000", "000", "0000"} if the input number is negative or does not contain 10 digits. 
StructuredPhoneNumber phoneNumBreakdown(long long phoneNum_ll);  

3.  include three unit tests test1( ), test2(), and test3(), each of which returns true 
     if phoneNumBreakdown( ) correctly calculates the three piceces of info
     
     For example: 
     
     bool test1()
     {
        //if you wish, you can print out a message here e.g., "my first test ...\n".
       //call phoneNumBreakdown(8005551212) ;
       //check the result
     }
     
4.  overload the operator== to compare whether two StructuredPhoneNumber objects 
    contain exactly the same phone number.
5. include two unit tests to test the above overloaded operator==
    bool test_operator1(){
       //call the overloaded operator==
       //check if it produces the expected result
    }
    
    bool test_operator2(){
       //call the overloaded operator==
       //check if it produces the expected result
    }
*/

 

Expert Solution
Step 1: Algorithm:
  1. Start.
  2. Define a struct named StructuredPhoneNumber to represent phone numbers with area code, prefix, and line number as strings.

  3. Create a default constructor and a parameterized constructor for the StructuredPhoneNumber struct.

  4. Define a function phoneNumBreakdown that takes a long long integer representing a phone number and converts it into a StructuredPhoneNumber object.

  5. In phoneNumBreakdown, check if the input number is valid (not negative and exactly 10 digits).

  6. Convert the phone number to a string and extract the area code, prefix, and line number.

  7. Overload the equality operator == for StructuredPhoneNumber to compare two phone numbers.

  8. Implement unit tests to verify the correctness of the phoneNumBreakdown function and the == operator overloading.

  9. In the main function, run the unit tests, and print the results.

  10. End,.
steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education