Telephone Directory Management (C++ Sample Program)


SUBMITTED BY: Hole2

DATE: April 9, 2017, 8:13 p.m.

FORMAT: C

SIZE: 20.4 kB

HITS: 741

  1. //HEADER FILES
  2. #include<iostream.h>
  3. #include<fstream.h>
  4. #include<conio.h>
  5. #include<stdio.h>
  6. #include<string.h>
  7. #include<iomanip.h>
  8. #include<dos.h>
  9. struct node //The basic linked node declaration
  10. {
  11. unsigned long recno;
  12. char pin[15];
  13. char name[64];
  14. node *link;
  15. } *first,*ptr1,*ptr2,*ptr,*temp;
  16. class person //The global class from which we are managing the file "phoneno.dat"
  17. {
  18. private:unsigned long record_id;
  19. char person_name[64];
  20. char res_address[64];
  21. char res_pincode[15];
  22. char res_phone_no1[15];
  23. char occu_pation[25];
  24. char company_name[25];
  25. char off_address[25];
  26. char off_pincode[15];
  27. char off_phone_no1[15];
  28. public:
  29. person() //default constructor
  30. {
  31. record_id=0;
  32. strcpy(person_name,"");
  33. strcpy(res_address,"");
  34. strcpy(res_pincode,"");
  35. strcpy(res_phone_no1,"");
  36. strcpy(occu_pation,"");
  37. strcpy(company_name,"");
  38. strcpy(off_address,"");
  39. strcpy(off_pincode,"");
  40. strcpy(off_phone_no1,"");
  41. }
  42. unsigned long get_rec_no();
  43. void get_data();
  44. void show_data();
  45. void add_object();
  46. void make_index();
  47. void sort_name();
  48. void sort_recno();
  49. void sort_pin();
  50. void show_object();
  51. void sort_print();
  52. void del_object();
  53. void modify_object();
  54. void search_object();
  55. void sort_object();
  56. void reports();
  57. }pers;
  58. unsigned long person::get_rec_no() //gets the lowest +ve unclaimed record id
  59. {
  60. int found=0;
  61. unsigned long rec_no,temp_recno;
  62. struct node1
  63. {
  64. unsigned long recno;
  65. node1 *link;
  66. };
  67. node1 *start,*ptr,*ptr1,*ptr2;
  68. fstream infile;
  69. infile.open("phoneno.dat",ios::in|ios::binary);
  70. infile.seekg(0,ios::end);
  71. int n=infile.tellg();
  72. infile.close();
  73. if(n==0)
  74. rec_no=1;
  75. else
  76. {
  77. infile.open("phoneno.dat",ios::in|ios::binary);
  78. start=ptr=new node1;
  79. infile.seekg(0,ios::beg);
  80. infile.read((char*)&pers,sizeof(pers));
  81. while(!infile.eof())
  82. {
  83. ptr->recno=record_id;
  84. ptr->link=new node1;
  85. ptr=ptr->link;
  86. infile.read((char*)&pers,sizeof(pers));
  87. }
  88. ptr->link=NULL;
  89. ptr1=start;
  90. while(ptr1->link!=NULL) //find the largest occupied record no
  91. {
  92. ptr2=ptr1->link;
  93. while(ptr2!=NULL)
  94. {
  95. if(ptr2->recno < ptr1->recno)
  96. {
  97. temp_recno=ptr2->recno;
  98. ptr2->recno=ptr1->recno;
  99. ptr1->recno=temp_recno;
  100. }
  101. ptr2=ptr2->link;
  102. }
  103. ptr2=ptr1->link;
  104. ptr1=ptr2;
  105. }
  106. ptr1=start;
  107. while(ptr1!=NULL && found!=1)
  108. {
  109. ptr2=ptr1;
  110. ptr1=ptr1->link;
  111. if((ptr2->recno)+1!=ptr1->recno)
  112. {
  113. rec_no=(ptr2->recno)+1;
  114. found=1;
  115. }
  116. }
  117. if(found!=1)rec_no=(ptr2->recno)+1;
  118. ptr=start;
  119. //clear up the memory lest memory leaks
  120. while(start!=NULL)
  121. {
  122. start=start->link;
  123. delete ptr;
  124. }
  125. }
  126. return rec_no;
  127. }
  128. void person::get_data() //function to enter the values to the class variable
  129. {
  130. clrscr();
  131. record_id=pers.get_rec_no();
  132. gotoxy(5,7); //move cursor to position (5,7)
  133. cout<<"ENTER THE NAME---------------------------> ";
  134. gets(person_name);
  135. gotoxy(5,8);
  136. cout<<"RESIDENTIAL ADDRESS----------------------> ";
  137. gets(res_address);
  138. gotoxy(5,9);
  139. cout<<"ENTER RESIDENTIAL PINCODE----------------> ";
  140. gets(res_pincode);
  141. gotoxy(5,10);
  142. cout<<"ENTER RESIDENTIAL PHONE NO---------------> ";
  143. gets(res_phone_no1);
  144. gotoxy(5,11);
  145. cout<<"ENTER THE OCCUPATION---------------------> ";
  146. gets(occu_pation);
  147. gotoxy(5,12);
  148. cout<<"ENTER COMPANY'S NAME---------------------> ";
  149. gets(company_name);
  150. gotoxy(5,13);
  151. cout<<"ENTER COMPANY'S ADDRESS------------------> ";
  152. gets(off_address);
  153. gotoxy(5,14);
  154. cout<<"ENTER OFFICE PINCODE---------------------> ";
  155. gets(off_pincode);
  156. gotoxy(5,15);
  157. cout<<"ENTER OFFICE PHONE NO--------------------> ";
  158. gets(off_phone_no1);
  159. gotoxy(5,16);
  160. clrscr();
  161. }
  162. void person::show_data() //view the the class members
  163. {
  164. clrscr();
  165. gotoxy(5,2);
  166. cout<<"RECORD NUMBER----------------------------->"<<record_id;
  167. gotoxy(5,3);
  168. cout<<"NAME-------------------------------------->"<<person_name;
  169. gotoxy(5,4);
  170. cout<<"RESIDENTIAL ADDERSS----------------------->"<<res_address;
  171. gotoxy(5,5);
  172. cout<<"RESIDENTIAL PINCODE----------------------->"<<res_pincode;
  173. gotoxy(5,6);
  174. cout<<"RESIDENTIAL PHONE NO---------------------->"<<res_phone_no1;
  175. gotoxy(5,7);
  176. cout<<"OCCUPATION-------------------------------->"<<occu_pation;
  177. gotoxy(5,8);
  178. cout<<"COMPANY's NAME---------------------------->"<<company_name;
  179. gotoxy(5,9);
  180. cout<<"COMPANY's ADDRESS------------------------->"<<off_address;
  181. gotoxy(5,10);
  182. cout<<"OFFICE PINCODE---------------------------->"<<off_pincode;
  183. gotoxy(5,11);
  184. cout<<"OFFICE PHONE NO--------------------------->"<<off_phone_no1;
  185. gotoxy(10,20);
  186. cout<<"PRESS ANY KEY TO CONTINUE";
  187. getch();
  188. }
  189. void person::add_object() //write the entered data in class 'person' to the file
  190. {
  191. fstream file;
  192. char choice='y';
  193. while(choice=='y')
  194. {
  195. file.open("phoneno.dat",ios::app|ios::binary);
  196. get_data();
  197. file.write((char*)&pers,sizeof(pers));
  198. file.flush();
  199. file.close();
  200. clrscr();
  201. gotoxy(10,11);
  202. cout<<"ANY MORE RECORDS YOU WANNA ADD<<Y/N>>-------------->";
  203. cin>>choice;
  204. }
  205. }
  206. void person::del_object() //delete a record based on its record id no.
  207. {
  208. fstream infile,outfile;
  209. unsigned long rec_no;
  210. clrscr();
  211. cout<<"ENTER THE RECORD ID.NO.TO BE DELETED--------->";
  212. cin>>rec_no;
  213. infile.open("phoneno.dat",ios::in|ios::binary);
  214. infile.seekg(0);
  215. outfile.open("tempno.dat",ios::app|ios::binary);
  216. //As the file cannot be modified directly, we create a temporary file where we don't copy the record.
  217. infile.read((char*)&pers,sizeof(pers));
  218. while(!infile.eof())
  219. {
  220. if(pers.record_id!=rec_no)
  221. outfile.write((char*)&pers,sizeof(pers));
  222. outfile.flush();
  223. infile.read((char*)&pers,sizeof(pers));
  224. }
  225. infile.close();
  226. outfile.close();
  227. //Replace the original file with the temporary file.
  228. remove("phoneno.dat");
  229. rename("tempno.dat","phoneno.dat");
  230. }
  231. void person::search_object() //searching and counting of records based on the user's choice
  232. {
  233. fstream infile;
  234. int search_choice;
  235. unsigned long rec_no;
  236. char phno[15];
  237. char name[64];
  238. do
  239. {
  240. clrscr();
  241. int counter=0;//for counting values
  242. gotoxy(22,7);
  243. cout<<" SEARCH MENU ";
  244. gotoxy(22,9);
  245. cout<<"-----------------";
  246. gotoxy(22,11);
  247. cout<<setiosflags(ios::left) << setw(30)<<"RECORD ID NO."<<"...1";
  248. gotoxy(22,12);
  249. cout<<setiosflags(ios::left) << setw(30)<<"NAME"<<"...2";
  250. gotoxy(22,13);
  251. cout<<setiosflags(ios::left) << setw(30)<<"PHONE NO."<<"...3";
  252. gotoxy(22,14);
  253. cout<<setiosflags(ios::left) << setw(30)<<"EXIT SEARCH MENU"<<"...4";
  254. gotoxy(1,20);
  255. cout<<"ENTER THE FIELD CHOICE ACCORDING TO WHICH A RECORD";
  256. cout<<"IS TO BE SEARCHED--------->";
  257. cin>>search_choice;
  258. switch(search_choice)
  259. {
  260. case 1:
  261. clrscr();
  262. cout<<"\n ENTER THE RECORD ID.NO. TO BE SEARCHED----->";
  263. cin>>rec_no;
  264. infile.open("phoneno.dat",ios::in|ios::binary);
  265. infile.seekg(0,ios::beg);
  266. infile.read((char*)&pers,sizeof(pers));
  267. while(!infile.eof())
  268. {
  269. if(pers.record_id==rec_no) //count record no matching the one being searched
  270. {
  271. counter++;
  272. pers.show_data();
  273. }
  274. infile.read((char*)&pers,sizeof(pers));
  275. }
  276. infile.close();
  277. gotoxy(20,24);
  278. cout<<"RECORDS FOUND="<<counter;
  279. getch();
  280. break;
  281. case 2:
  282. clrscr();
  283. cout<<"\n ENTER THE NAME TO BE SEARCHED---------->";
  284. gets(name);
  285. infile.open("phoneno.dat",ios::in|ios::binary);
  286. infile.seekg(0,ios::beg);
  287. infile.read((char*)&pers,sizeof(pers));
  288. while(!infile.eof())
  289. {
  290. if(strcmpi(pers.person_name,name)==0)
  291. {
  292. counter++;
  293. pers.show_data();
  294. }
  295. infile.read((char*)&pers,sizeof(pers));
  296. }
  297. infile.close();
  298. gotoxy(20,24);
  299. cout<<"RECORDS FOUND="<<counter;
  300. getch();
  301. break;
  302. case 3:
  303. clrscr();
  304. cout<<"\nENTER THE PHONE NO.TO BE SEARCHED-------->";
  305. cin>>phno;
  306. infile.open("phoneno.dat",ios::in|ios::binary);
  307. infile.seekg(0,ios::beg);
  308. infile.read((char*)&pers,sizeof(pers));
  309. while(!infile.eof())
  310. {
  311. if(strcmp(pers.res_phone_no1,phno)==0||strcmp(pers.off_phone_no1,phno)==0)
  312. {
  313. counter++;
  314. pers.show_data();
  315. }
  316. infile.read((char*)&pers,sizeof(pers));
  317. }
  318. infile.close();
  319. gotoxy(20,24);
  320. cout<<"RECORDS FOUND="<<counter;
  321. getch();
  322. break;
  323. case 4:
  324. clrscr();
  325. gotoxy(22,15);
  326. cout<<"YOU HAVE ENDED THE SEARCH SESSION";
  327. gotoxy(27,18);
  328. cout<<"THANK YOU!";
  329. delay(700); //This is a strictly dos command. For windows use 'Sleep(int);'
  330. break;
  331. }
  332. }while(search_choice!=4);
  333. }
  334. void person::modify_object() //modify a record present in the file
  335. {
  336. fstream file;
  337. unsigned long code;
  338. int modify_choice;
  339. do
  340. {
  341. clrscr();
  342. gotoxy(22,7);
  343. cout<<" MODIFY MENU ";
  344. gotoxy(22,8);
  345. cout<<"---------------------";
  346. gotoxy(22,10);
  347. cout<<setiosflags(ios::left) << setw(40)<<"RESIDENTIAL INFORMATON"<<"...1";
  348. gotoxy(22,11);
  349. cout<<setiosflags(ios::left) << setw(40)<<"OFFICIAL INFORMATION"<<"...2";
  350. gotoxy(22,12);
  351. cout<<setiosflags(ios::left) << setw(40)<<"EXIT"<<"...3";
  352. gotoxy(22,13);
  353. cout<<"SELECT THE INFORMATION TO BE CHANGED : ";
  354. gotoxy(22,14);
  355. cout<<"ENTER YOUR CHOICE----->";
  356. cin>>modify_choice;
  357. //The files are modified by looking for the position of the entered record no. and then modifying the record
  358. if(modify_choice!=3)
  359. {
  360. clrscr();
  361. gotoxy(10,15);
  362. cout<<"ENTER THE RECORD NO. OF THE PERSON---->";
  363. cin>>code;
  364. file.open("phoneno.dat",ios::in|ios::out);
  365. file.seekg(0,ios::beg);
  366. file.read((char*)&pers,sizeof(pers));
  367. int n=file.tellg();
  368. while(!file.eof())
  369. {
  370. if(pers.record_id==code)
  371. {
  372. switch(modify_choice)
  373. {
  374. case 1:
  375. clrscr();
  376. cout<<"***** The Details of "<<pers.person_name;
  377. cout<<"\n\nThe old Address is :-"<<pers.res_address;
  378. cout<<"\nENTER NEW RESIDENTIAL ADDRESS-------------->";
  379. gets(pers.res_address);
  380. cout<<"The old Pin code is :-"<<pers.res_pincode;
  381. cout<<"\nENTER NEW PINCODE-------------------------->";
  382. gets(pers.res_pincode);
  383. cout<<"The old Phone No.is :-"<<pers.res_phone_no1;
  384. cout<<"\nENTER NEW RESIDENTIAL PHONE NO------------->";
  385. gets(pers.res_phone_no1);
  386. file.seekg(n-sizeof(pers));
  387. file.write((char*)&pers,sizeof(pers));
  388. file.flush();
  389. break;
  390. case 2:
  391. clrscr();
  392. cout<<"\nENTER THE OCCUPATION------------->";
  393. gets(pers.occu_pation);
  394. cout<<"\nENTER NEW COMPANY'S NAME--------->";
  395. gets(pers.company_name);
  396. cout<<"\nENTER NEW OFFICE ADDRESS--------->";
  397. gets(pers.off_address);
  398. cout<<"\nENTER NEW OFFICE PIN CODE-------->";
  399. gets(pers.off_pincode);
  400. cout<<"\nENTER NEW OFFICE PHONE NO-------->";
  401. gets(pers.off_phone_no1);
  402. file.seekg(n-sizeof(pers));
  403. file.write((char*)&pers,sizeof(pers));
  404. file.flush();
  405. break;
  406. }
  407. }
  408. file.read((char*)&pers,sizeof(pers));
  409. n=file.tellg();
  410. }
  411. file.close();
  412. }
  413. }while(modify_choice!=3);
  414. clrscr();
  415. gotoxy(22,10);
  416. cout<<"YOU ENDED MODIFY INFORTION SESSION";
  417. gotoxy(30,13);
  418. cout<<"THANK YOU";
  419. delay(700);
  420. }
  421. void ex_change() //exchange the lvalues in pointers ptr1 & ptr2
  422. {
  423. temp=new node;
  424. temp->link=NULL;
  425. temp->recno=ptr2->recno;
  426. strcpy(temp->pin,ptr2->pin);
  427. strcpy(temp->name,ptr2->name);
  428. ptr2->recno=ptr1->recno;
  429. strcpy(ptr2->pin,ptr1->pin);
  430. strcpy(ptr2->name,ptr1->name);
  431. ptr1->recno=temp->recno;
  432. strcpy(ptr1->pin,temp->pin);
  433. strcpy(ptr1->name,temp->name);
  434. delete temp;
  435. }
  436. void person::make_index() //create a linked stack containing name, record id no., pin no.
  437. {
  438. fstream infile;
  439. first=new node;
  440. ptr=first;
  441. infile.open("phoneno.dat",ios::in|ios::binary);
  442. infile.seekg(0,ios::beg);
  443. infile.read((char*)&pers,sizeof(pers));
  444. while(!infile.eof())
  445. {
  446. ptr->recno=record_id;
  447. strcpy(ptr->pin,res_pincode);
  448. strcpy(ptr->name,pers.person_name);
  449. ptr->link=new node;
  450. ptr=ptr->link;
  451. infile.read((char*)&pers,sizeof(pers));
  452. }
  453. ptr->link=NULL;
  454. infile.close();
  455. }
  456. void person::sort_name() //sort the records in the liked stack made by name in ascending order
  457. {
  458. pers.make_index();
  459. ptr1=first;
  460. while(ptr1->link!=NULL)
  461. {
  462. ptr2=ptr1->link;
  463. while(ptr2->link!=NULL)
  464. {
  465. if(strcmpi(ptr2->name,ptr1->name)<0)
  466. ex_change();
  467. ptr2=ptr2->link;
  468. }
  469. ptr2=ptr1->link;
  470. ptr1=ptr2;
  471. }
  472. }
  473. void person::sort_recno() //sort the records in the liked stack by record no. in ascending order
  474. {
  475. pers.make_index();
  476. ptr1=first;
  477. while(ptr1->link!=NULL)
  478. {
  479. ptr2=ptr1->link;
  480. while(ptr2->link!=NULL)
  481. {
  482. if(ptr2->recno<ptr1->recno)
  483. ex_change();
  484. ptr2=ptr2->link;
  485. }
  486. ptr2=ptr1->link;
  487. ptr1=ptr2;
  488. }
  489. }
  490. void person::sort_pin() //sort the records in the liked stack by pin no. in ascending order
  491. {
  492. pers.make_index();
  493. ptr1=first;
  494. while(ptr1->link!=NULL)
  495. {
  496. ptr2=ptr1->link;
  497. while(ptr2!=NULL)
  498. {
  499. if(strcmpi(ptr2->pin,ptr1->pin)<0)
  500. ex_change();
  501. ptr2=ptr2->link;
  502. }
  503. ptr2=ptr1->link;
  504. ptr1=ptr2;
  505. }
  506. }
  507. void person::sort_print() //display the sorted stack node by node
  508. {
  509. fstream infile;
  510. ptr=first;
  511. while(ptr!=NULL)
  512. {
  513. infile.open("phoneno.dat",ios::in|ios::binary);
  514. infile.seekg(0,ios::beg);
  515. //convert the entire database into a linked stack
  516. infile.read((char*)&pers,sizeof(pers));
  517. while(!infile.eof())
  518. {
  519. if(ptr->recno==pers.record_id)
  520. {
  521. pers.show_data();
  522. infile.seekg(0,ios::end);
  523. }
  524. infile.read((char*)&pers,sizeof(pers));
  525. }
  526. infile.close();
  527. ptr=ptr->link;
  528. }
  529. }
  530. void del_index() //clears up the stack completely
  531. {
  532. while(first!=NULL)
  533. {
  534. ptr=first;
  535. first=first->link;
  536. delete ptr;
  537. }
  538. }
  539. void person::sort_object() //function to display sort menu
  540. {
  541. int sort_choice;
  542. do
  543. {
  544. clrscr();
  545. gotoxy(22,7);
  546. cout<<" SORT MENU ";
  547. gotoxy(22,8);
  548. cout<<"-------------------";
  549. gotoxy(22,10);
  550. cout<<setiosflags(ios::left) << setw(40)<<"SORTED RECORDS NOS."<<"...1";
  551. gotoxy(22,11);
  552. cout<<setiosflags(ios::left) << setw(40)<<"SORTED NAMES"<<"...2";
  553. gotoxy(22,12);
  554. cout<<setiosflags(ios::left) << setw(40)<<"SORTED PINCODES NOS."<<"...3";
  555. gotoxy(22,13);
  556. cout<<setiosflags(ios::left) << setw(40)<<"EXIT SORT MENU"<<"...4";
  557. gotoxy(22,20);
  558. cout<<"ENTER YOUR CHOICE NO.----->";
  559. cin>>sort_choice;
  560. switch(sort_choice)
  561. {
  562. case 1:
  563. clrscr();
  564. pers.sort_recno();
  565. pers.sort_print();
  566. del_index();//clear up the stack to prevent memory leaking
  567. delay(200);
  568. break;
  569. case 2:
  570. clrscr();
  571. pers.sort_name();
  572. pers.sort_print();
  573. del_index();
  574. delay(200);
  575. break;
  576. case 3:
  577. clrscr();
  578. pers.sort_pin();
  579. pers.sort_print();
  580. del_index();
  581. delay(200);
  582. break;
  583. case 4:
  584. clrscr();
  585. gotoxy(22,10);
  586. cout<<"YOU ENDED THE SORTED SESSION";
  587. gotoxy(27,13);
  588. cout<<"THANK YOU!";
  589. delay(700);
  590. break;
  591. }
  592. }while(sort_choice!=4);
  593. }
  594. void person::reports() //function to display report menu (which uses a table to display)
  595. {
  596. fstream infile;
  597. int report_choice;
  598. do
  599. {
  600. clrscr();
  601. gotoxy(22,7);
  602. cout<<" REPORT MENU ";
  603. gotoxy(22,8);
  604. cout<<"------------------";
  605. gotoxy(5,10);
  606. cout<<setiosflags(ios::left) << setw(61)<<"SORTED LIST OF NAMES WITH RESIDENCE AND OFFICE PHONE NOS"<<setw(5)<<"...1";
  607. gotoxy(5,11);
  608. cout<<setiosflags(ios::left) << setw(61)<<"LIST OF NAMES WITH THIER OFFICE DETAILS"<<setw(5)<<"...2";
  609. gotoxy(5,12);
  610. cout<<setiosflags(ios::left) << setw(61)<<"LIST OF NAMES WITH THEIR RECORD NOS.AND RESIDENTIAL ADDRESS"<<setw(5)<<"...3";
  611. gotoxy(5,13);
  612. cout<<setiosflags(ios::left) << setw(61)<<"EXIT REPORT SESSION"<<setw(5)<<"...4";
  613. gotoxy(5,14);
  614. cout<<"ENTER YOUR CHOICE NO.------>";
  615. cin>>report_choice;
  616. switch(report_choice)
  617. {
  618. case 1:
  619. clrscr();
  620. cout<<setiosflags(ios::left) << setw(28)<< "NAME" << setw(30)<< "RES.PHONE NO." << setw(30)<< "OFFICE PHONE NO.";
  621. cout<<"\n";
  622. cout<<"\n-------------------------------------------------------------------------------";
  623. pers.sort_name();
  624. ptr=first;
  625. while(ptr!=NULL)
  626. {
  627. infile.open("phoneno.dat",ios::in|ios::binary);
  628. infile.seekg(0,ios::beg);
  629. infile.read((char*)&pers,sizeof(pers));
  630. while(!infile.eof())
  631. {
  632. if(ptr->recno==pers.record_id)
  633. {
  634. cout<<"\n";
  635. cout<<setiosflags(ios::left)<<setw(28)<<pers.person_name<<setw(30)<<pers.res_phone_no1<<setw(30) <<pers.off_phone_no1;
  636. infile.seekg(0,ios::end);
  637. }
  638. infile.read((char*)&pers,sizeof(pers));
  639. }
  640. infile.close();
  641. ptr=ptr->link;
  642. }
  643. del_index();
  644. gotoxy(20,40);
  645. cout<<"PRESS ANY KEY TO CONTINUE";
  646. getch();
  647. break;
  648. case 2:
  649. clrscr();
  650. infile.open("phoneno.dat",ios::in|ios::binary);
  651. infile.seekg(0,ios::beg);
  652. infile.read((char*)&pers,sizeof(pers));
  653. while(!infile.eof())
  654. {
  655. gotoxy(10,5);
  656. cout<<"NAME-------------------->"<<pers.person_name;
  657. gotoxy(10,6);
  658. cout<<"COMPNAY'S NAME---------->"<<pers.company_name;
  659. gotoxy(10,7);
  660. cout<<"COMPANY'S ADDESS-------->"<<pers.off_address;
  661. gotoxy(10,8);
  662. cout<<"OFFICE PHONE NO--------->"<<pers.off_phone_no1;
  663. gotoxy(10,10);
  664. cout<<"PRESS ANY KEY TO CONTINUE";
  665. getch();
  666. infile.read((char*)&pers,sizeof(pers));
  667. clrscr();
  668. }
  669. infile.close();
  670. break;
  671. case 3:
  672. clrscr();
  673. cout<<setiosflags(ios::left)<<setw(16)<<"\nREC NO." << setw(15)<< "NAME" << setw(35)<< "RES.ADDRESS" << setw(18)<< "RES PHONE NO";
  674. cout<<"\n-------------------------------------------------------------------------------";
  675. infile.open("phoneno.dat",ios::in|ios::binary);
  676. infile.seekg(0,ios::beg);
  677. infile.read((char*)&pers,sizeof(pers));
  678. while(!infile.eof())
  679. {
  680. cout<<"\n";
  681. cout<<setiosflags(ios::left)<<setw(15)<<pers.record_id<<setw(15)<<pers.person_name<<setw(35)<<pers.res_address<<setw(18)<<res_phone_no1;
  682. infile.read((char*)&pers,sizeof(pers));
  683. }
  684. infile.close();
  685. gotoxy(20,40);
  686. cout<<"PRESS ANY KEY TO CONTINUE";
  687. getch();
  688. break;
  689. case 4:
  690. clrscr();
  691. gotoxy(22,10);
  692. cout<<"YOU HAVE ENDED REPORT SESSION";
  693. gotoxy(27,30);
  694. cout<<"THANK YOU";
  695. delay(700);
  696. break;
  697. }
  698. }
  699. while(report_choice!=4);
  700. }
  701. void main() //MAIN FUNCTION
  702. {
  703. int main_choice;
  704. do
  705. {
  706. clrscr();
  707. gotoxy(22,7);
  708. cout<<" MAIN MENU ";
  709. gotoxy(25,11);
  710. cout<<setiosflags(ios::left) << setw(30)<<" ADD A NEW RECORD"<<"...1";
  711. gotoxy(25,12);
  712. cout<<setiosflags(ios::left) << setw(30)<<" DELETE A RECORD"<<"...2";
  713. gotoxy(25,13);
  714. cout<<setiosflags(ios::left) << setw(30)<<" MODIFY A RECORD"<<"...3";
  715. gotoxy(25,14);
  716. cout<<setiosflags(ios::left) << setw(30)<<" SEARCH A RECORD"<<"...4";
  717. gotoxy(25,15);
  718. cout<<setiosflags(ios::left) << setw(30)<<" SORTED INFORMATION"<<"...5";
  719. gotoxy(25,16);
  720. cout<<setiosflags(ios::left) << setw(30)<<" REPORTS"<<"...6";
  721. gotoxy(25,17);
  722. cout<<setiosflags(ios::left) << setw(30)<<" EXIT"<<"...7";
  723. gotoxy(25,20);
  724. cout<<"ENTER YOUR CHOICE NO.--------->";
  725. cin>>main_choice;
  726. switch(main_choice)
  727. {
  728. case 1:
  729. pers.add_object();
  730. break;
  731. case 2:
  732. pers.del_object();
  733. break;
  734. case 3:
  735. pers.modify_object();
  736. break;
  737. case 4:
  738. pers.search_object();
  739. break;
  740. case 5:
  741. pers.sort_object();
  742. break;
  743. case 6:
  744. pers.reports();
  745. break;
  746. case 7:
  747. clrscr();
  748. gotoxy(22,10);
  749. cout<<"YOU HAVE ENDED THE SESSION";
  750. gotoxy(27,13);
  751. cout<<"THANK YOU";
  752. delay(1000);
  753. break;
  754. }
  755. }while(main_choice!=7);
  756. }

comments powered by Disqus