Write a program that implements the following using C++ structure. The program should finally displays the values stored in a phone directory (for 10 people)
1)Name
2)phone number
3)city and country
#include <iostream>
// The program will prompt the user to enter nameS of 10 users
//The vales shall be stored in a structure
//The for loop shall be used to read and display the info.
using namespace std;
struct phone // structure name is phone
{
char name[10]; //memmbers
char phonenumber[10];
char country[10];
char city[10];
};
int main(){
int n=2;
phone dir[10];
for(int i=0;i<n;++i){
cout<<"Enter name for person "<<i+1<<endl;
cin>>dir[i].name;
cout<<"Enter phone number for person "<<i+1<<endl;
cin>>dir[i].phonenumber;
cout<<"Enter country for person "<<i+1<<endl;
cin>>dir[i].country;
cout<<"Enter city for person "<<i+1<<endl;
cin>>dir[i].city;
}
cout<<"************************************"<<endl;
for( i=0;i<n;++i){
cout<<"************************************"<<endl;
cout<<"Details for person"<<i+1<<endl;
cout<<"______________________________________"<<endl;
cout<<"Name "<<dir[i].name<<endl;
cout<<"______________________________________"<<endl;
cout<<"Phone number "<<dir[i].phonenumber<<endl;
cout<<"______________________________________"<<endl;
cout<<"Country "<<dir[i].country<<endl;
cout<<"______________________________________"<<endl;
cout<<"City "<<dir[i].city<<endl;
}
cout<<"************************************"<<endl;
return 0;
}
Comments
Leave a comment