0% found this document useful (0 votes)
4 views2 pages

Phone Number Structure Program

The document outlines a program that stores and displays phone numbers using a structure in C++. It defines a 'phone' structure with three parts: area code, exchange, and number. The program initializes one phone number and prompts the user to input another, then displays both numbers in a formatted way.

Uploaded by

zishanashraf9162
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Phone Number Structure Program

The document outlines a program that stores and displays phone numbers using a structure in C++. It defines a 'phone' structure with three parts: area code, exchange, and number. The program initializes one phone number and prompts the user to input another, then displays both numbers in a formatted way.

Uploaded by

zishanashraf9162
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program No.

– 3

Aim: 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.

Source code:
#include <iostream>
using namespace std;

struct phone {
int areaCode;
int exchange;
int number;
};

int main() {

phone myPhone = {212, 767, 8900};

phone userPhone;

cout << "Enter your area code, exchange, and number: ";
cin >> [Link] >> [Link] >> [Link];

cout << "My number is (" << [Link] << ") "
<< [Link] << "-" << [Link] << endl;

cout << "Your number is (" << [Link] << ") "
<< [Link] << "-" << [Link] << endl;

return 0;
}
Output:

You might also like