Answer to Question #50072 in C++ for Umer Inayat

Question #50072
A phone number, such as (212) 767-8900, can be thought of as having three parts: the
area code (212), the exchange (767), and the number (8900). Write a program that uses a
structure to store these three parts of a phone number separately. Call the structure
phone. Create two structure variables of type phone. Initialize one, and have the user
input a number for the other one. Then display both numbers. The interchange might
look like this:

Enter your area code, exchange, and number: 415 555 1212
My number is (212) 767-8900
Your number is (415) 555-1212
1
Expert's answer
2020-07-15T06:44:32-0400
#include <iostream>
#include <string>
using namespace std;

struct phone
{
string part1;
string part2;
string part3;
};

int main( )
{
phone first, second;
second.part1="212";
second.part2="767";
second.part3="8900";
cout<<"Enter your area code,exchange, and number: ";
cin>>first.part1>>first.part2>>first.part3;

cout<<"My number is("<<second.part1<<")
"<<second.part2<<"-"<<second.part3<<endl;
cout<<"My number is("<<first.part1<<")
"<<first.part2<<"-"<<first.part3<<endl;

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS