.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Simulation of Telephone directory

Posted By:Nikhil Kumar       Posted Date: February 28, 2010    Points: 10    Category: Collections    URL: http://www.dotnetspark.com  

Simulation of Telephone directory
 

#include
#include
#include
#include
const int size=3;
struct person{
char fname[5];
char lname[5];
long tel;}td[size],t;
void swap(person &s1,person &s2)
{
strcpy(t.fname,s1.fname) ;
strcpy(t.lname,s1.lname) ;
t.tel=s1.tel ;
s1.tel=s2.tel;
 
strcpy(s2.fname,t.fname) ;
strcpy(s2.lname,t.lname) ;
}
void main()
{
  clrscr();
 int i,j;
                for(i=0;i
                {
                cout<<"person"<
                cin>>td[i].fname;
                cout<<"person"<
                cin>>td[i].lname;
                cout<<"person"<
                cin>>td[i].tel;
                }
 
 for(i=0;i
 {
 for(j=0;j
 {
 if(strcmp(td[j].lname,td[j+1].lname)>0)
               swap(td[j],td[j+1]);
               else if(strcmp(td[j].lname,td[j+1].lname)==0)
               if (strcmp(td[j].fname,td[j+1].fname)>0)
               swap(td[j],td[j+1]);
 }
 }
 for(i=0;i
 {
 cout<<"person"<
 cout<
 }
 getch();
 }
 
OUTPUT 
 
***TELEPHONE DIRECTORY SIMULATION***
 
person1FIRST NAME
AREEB
 
person1LAST NAME
NAQI
 
person1TELEPHONE
23279449
 
person2FIRST NAME
HARSH
 
person2LAST NAME
PANDYA
 
person2TELEPHONE
23546982
 
 
 
person3FIRST NAME
ANANT
 
person3LAST NAME
BANSAL
 
person3TELEPHONE
24578965
 
person1
LASTNAME IS NAQI
FIRST NAME AREEB
TELEPHONE 23279449
 
person2
LASTNAME IS HARSH
FIRST NAME PANDYA
TELEPHONE 23546982
 
person3
LASTNAME IS ANANT                  
FIRST NAME BANSAL
TELEPHONE 24578965
 Thanks !!!


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend