0% found this document useful (0 votes)
66 views

Oops-Program 4-Mdu

The program uses a structure called "phone" to store the three parts of a phone number - area code, exchange, and number - as separate integer values. Two structure variables of type phone are declared. One is initialized, while the other is input by the user. Both phone numbers are then displayed on output.

Uploaded by

Atul Malhotra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Oops-Program 4-Mdu

The program uses a structure called "phone" to store the three parts of a phone number - area code, exchange, and number - as separate integer values. Two structure variables of type phone are declared. One is initialized, while the other is input by the user. Both phone numbers are then displayed on output.

Uploaded by

Atul Malhotra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

C++ Programming Lab File Name: program4.

cpp

PROGRAM NO. 4
Objective: - 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

#include<iostream> //header file using namespace std; struct phone //structure declaration { int area_code; int exchange; int number; }; int main() //main() function { phone p1,p2; //variable of structure phone p1.area_code=212; p1.exchange=767; p1.number=8900; cout<<"Enter your area code,exchange and number:"; cin>>p2.area_code>>p2.exchange>>p2.number; //receiving input cout<<"My number is:"; cout<<"("<<p1.area_code<<")"<<p1.exchange<<"-"<<p1.number<<"\n"; cout<<"Your number is:"; cout<<"("<<p2.area_code<<")"<<p2.exchange<<"-"<<p2.number<<"\n"; return 0; } //end of main()

SBIT/CSE/IV/C++ PROGRAMMING/CSE-206-F

CSE/10/409

C++ Programming Lab

OUTPUT

SBIT/CSE/IV/C++ PROGRAMMING/CSE-206-F

CSE/10/409

You might also like