Q: (a) Declare a structure Phone that has three int fieldscalled country, area a
ID: 3618531 • Letter: Q
Question
Q:
(a) Declare a structure Phone that has three int fieldscalled country, area and number. In main,declare a pointer variableto a Phone structure named newPhone. Then write assignmentstatements to indirectly (using the pointer) store the values 1,888 and 5551122 into these fields.
(b) Write a Boolean-value returning function calledShallowCompare that takes two variables of type pointer to phonestructure (declared in parta), and returns true if they point tothe same structure, and false otherwise.
////////////////////////////////////////////////////////////
For (a) Output should be like this :
Country code :1
Area code :888
Number :5551122
/////////////////////////////////////////////////////////////
For (b) Output should be like this :
Two structure variables are pointing to same structure. //if returns true;
Two structure variables are not pointing to same structure.//if returns false;
Explanation / Answer
#include<iostream.h>
#include<conio.h>
struct phone
{
int country;
int area;
int number;
};
void main()
{
cout<<" <<CS-LAB No-07 >> <<BYPC MATI UR RAB>> ";
phone phone1;
phone *newphone=&phone1;
newphone->country=1;
newphone->area=888;
newphone->number=5551122;
cout<<" Country :"<<newphone->country;
cout<<" Area :"<<newphone->area;
cout<<" Number :"<<newphone->number;
getche();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.