Oops-Program 4-Mdu
Oops-Program 4-Mdu
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
OUTPUT
SBIT/CSE/IV/C++ PROGRAMMING/CSE-206-F
CSE/10/409