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 } */
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
//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
}
*/

- Start.
Define a struct named
StructuredPhoneNumber
to represent phone numbers with area code, prefix, and line number as strings.Create a default constructor and a parameterized constructor for the
StructuredPhoneNumber
struct.Define a function
phoneNumBreakdown
that takes a long long integer representing a phone number and converts it into aStructuredPhoneNumber
object.In
phoneNumBreakdown
, check if the input number is valid (not negative and exactly 10 digits).Convert the phone number to a string and extract the area code, prefix, and line number.
Overload the equality operator
==
forStructuredPhoneNumber
to compare two phone numbers.Implement unit tests to verify the correctness of the
phoneNumBreakdown
function and the==
operator overloading.In the
main
function, run the unit tests, and print the results.- End,.
Step by step
Solved in 5 steps with 4 images









