Thursday, July 30, 2009

Write a program in C++ that accepts telephone number as input and prints the name and address of owner of tele

write a program in C++ that accepts telephone number as input and prints the name and address of owner of telephone.Define necessary classes ,constructors and destructors

Write a program in C++ that accepts telephone number as input and prints the name and address of owner of tele
first read the input file which consists of three fields


eg:





NAME PHONE NO ADDRESS


abu 233356674 16 easternport


....... ................. ...................





The above is the example file U can extend the above


file to more than 1000 of entries and save it in C drive


after saving the desired file


open the turbo c editor and type the coding





#include%26lt;iostream.h%26gt;


#include%26lt;conio.h%26gt;


#include%26lt;stdio.h%26gt;


#include%26lt;string.h%26gt;


struct details


{


char name[20];


long phno;


char add[200];


}st[100];





int i,j,k,l;


void main()


{


FILE *fp;


clrscr();


fp=fopen("C:\input.txt","r");//opens the file in the readmode;


i=1;


cout%26lt;%26lt;"\n Displaying the contents of the file:";


cout%26lt;%26lt;"\t\tname\t\t phone no\t\t address";





while(fscanf(fp,"%s%ld%s",st[i].name,s...


{





cout%26lt;%26lt;st[i].name;


cout%26lt;%26lt;"\t\t";


cout%26lt;%26lt;st[i].phno;


cout%26lt;%26lt;"\t\t";


cout%26lt;%26lt;st[i].add;


i++;


}


int y;


cout%26lt;%26lt;"\n Enter the phone no";


cin%26gt;%26gt;y;


for(j=1;j%26lt;=i;j++)


{


if(st[j].phno==y)


{


cout%26lt;%26lt;"\n The persons name is:";


cout%26lt;%26lt;st[j].name;


cout%26lt;%26lt;"\n The persons address is:";


cout%26lt;%26lt;st[j].add;


}


}


getch();


}


No comments:

Post a Comment