Address book

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 4
Reputation: ryukifaiz is an unknown quantity at this point 
Solved Threads: 0
ryukifaiz ryukifaiz is offline Offline
Newbie Poster

Address book

 
0
  #1
Sep 8th, 2008
Can someone help me on how to write the program?

The details i already upload.See the attachment.The due date is tomorrow,i hope someone can help me.Thanks!
Attached Files
File Type: doc doc 1.doc (31.0 KB, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,858
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Address book

 
1
  #2
Sep 8th, 2008
>The due date is tomorrow
And you were given the assignment today, I'm sure. You seem like yet another boob who screwed around when he should have been working and expects us to provide a free lunch.

You want help? Show us your code. If it looks like you've actually been working on this assignment, you'll appear less like a hopeless leech.
Last edited by Narue; Sep 8th, 2008 at 4:50 pm.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 4
Reputation: ryukifaiz is an unknown quantity at this point 
Solved Threads: 0
ryukifaiz ryukifaiz is offline Offline
Newbie Poster

Re: Address book

 
0
  #3
Sep 8th, 2008
Here is my code.But some function does not working.And i dun noe how to make the date and time automatically updated.???

  1. //Header Files
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6.  
  7. //File Name Definition
  8. char fname[] = "data.txt";
  9. char fswap[] = "swap.txt";
  10.  
  11. //Main Menu Function Declare
  12. void mainmenu();
  13.  
  14. //Misc Function Declare
  15. void empty(FILE *x, char y[],char z[]);
  16. void change(FILE *x, char y[],char z[]);
  17. void credit();
  18.  
  19.  
  20. //Search Function Declare
  21. void search();
  22. void s_name();
  23.  
  24. //Add Functions Declare
  25. void add();
  26.  
  27. //Delete Function Declare
  28. void delete();
  29. void d_name();
  30.  
  31. //Edit Function Declare
  32. void edit();
  33. void e_name();
  34. void e_email();
  35. void e_phonenumber();
  36. void e_dateupdated();
  37.  
  38. //Display Options Declare
  39. void display_options();
  40.  
  41. //Structure Data Declare
  42. struct data
  43. {
  44. char name[50];
  45. char email[20];
  46. char phonenumber[30];
  47. char date_updated[30];
  48. }record;
  49.  
  50. //Global Variable Declare
  51. long sum=0;
  52.  
  53. int main()
  54. {
  55. credit();
  56. mainmenu();
  57. }
  58.  
  59. /* Main Menu Generated */
  60. void mainmenu()
  61. {
  62. char a[1];
  63. int c=1;
  64. while(c!=-1)
  65. {
  66. system("cls");
  67. printf("Personal Address Book");
  68. printf("\n");
  69. printf("\n");
  70. printf("What you want to do\n");
  71. printf("\n");
  72. printf("a. Search Record");
  73. printf("\n");
  74. printf("b. Add Record");
  75. printf("\n");
  76. printf("c. Delete Record");
  77. printf("\n");
  78. printf("d. Edit Record");
  79. printf("\n");
  80. printf("e. Display Options");
  81. printf("\n");
  82. printf("f. Exit");
  83. printf("\n");
  84. printf("\n");
  85.  
  86. if ( c < 1|| c > 6 )
  87. {
  88. printf("!!!!Please Enter a-f!!!!\n");
  89.  
  90. }
  91. printf("Choose An Option:");
  92. scanf("%s", a);
  93.  
  94. if(isdigit(a[0])) //Determine The Entered Value
  95. c = atoi (a);
  96. else
  97. c = -2;
  98.  
  99.  
  100. switch (c)
  101. {
  102. case 1: search(); break; //Goto Search Record Function
  103. case 2: add(); break; //Goto Add Record Function
  104. case 3: delete(); break; //Goto Delete Record Function
  105. case 4: edit(); break; //Goto Edit Record Function
  106. case 5: display_options(); break; //Goto Display Options
  107. case 6: exit(1); break; //Exit Program
  108. default: break; //Loop Main()
  109. }
  110. }
  111. }
  112.  
  113.  
  114. /*
  115. Add Record Function
  116. ===================
  117. Insert Name,Email,Phone Number
  118. Save Into File Stream
  119. */
  120. void add()
  121. {
  122. system("cls");
  123. FILE *fp;
  124. int a=1;
  125.  
  126. fp = fopen(fname,"ab");
  127. if(fp!=NULL)
  128. {
  129. while ( a == 1 )
  130. {
  131. system("cls");
  132. printf("<<----Adding New Record---->>");
  133. printf("\n");
  134. printf("Enter first Name:\n");
  135. scanf("%s", record.name);
  136. printf("Enter Last Name:\n");
  137. scanf("%s", record.name);
  138. printf("Enter Email:\n");
  139. scanf("%s", record.email);
  140. printf("Enter Phone Number:\n");
  141. scanf("%s", record.phonenumber);
  142.  
  143. fwrite(&record, sizeof(record), 1, fp);
  144.  
  145. printf("Record Saved\n");
  146. printf("DO YOU WISH TO CONTINUE..[1]/[0]: \n");
  147. scanf("%1d", &a);
  148. if( a == 0)
  149. break;
  150. }
  151. fclose(fp);
  152. }
  153. else
  154. {
  155. printf("Unable To Open/Create File...");
  156. system("pause");
  157. }
  158. }
  159.  
  160. /*
  161. Search Record Function
  162. ====================
  163. Generate Searching Option Menu
  164. Search Record by Name
  165. */
  166. void search()
  167. {
  168. char a[1];
  169. int c=1;
  170. while(c!=-1)
  171. {
  172. system("cls");
  173. puts("a. Search by Name");
  174. puts("b. Back");
  175. puts("");
  176. if ( c < 0 || c > 1)
  177. {
  178. printf("!!!!Please Enter a-b!!!!\n");
  179. }
  180. printf("Choose an Option: ");
  181. scanf("%s", a);
  182.  
  183. if(isdigit(a[0])) //Determine The Entered Value
  184. c = atoi (a);
  185. else
  186. c = -2;
  187.  
  188. switch (c)
  189. {
  190. case 1: s_name(); break; //Goto Search by Name
  191. case 0: mainmenu(); break; //Return Main Menu
  192. default: break; //Loop Search()
  193. }
  194. }
  195. }
  196.  
  197. /*
  198. Search by Name Function
  199. ===================================
  200. Read Through File Stream
  201. Insert Search String
  202. String Comparison between Search String and Name
  203. Retrieve Data for String Comparison is True
  204. Print Out All Retrieved Data
  205. */
  206. void s_name()
  207. {
  208. int a;
  209. int ch;
  210. FILE *fp;
  211. char check[10];
  212. system("cls");
  213.  
  214. fp=fopen(fname,"rb+");
  215.  
  216. if (fp!=NULL)
  217. {
  218. printf("Please Enter Search String: ");
  219. scanf("%s", check);
  220.  
  221. while ( fread(&record, sizeof(record), 1, fp) && strcmp(check,record.name) );
  222.  
  223. ch=strcmp(check,record.name);
  224. if(ch!=0)
  225. {
  226. system("cls");
  227. printf("==SEARCHING==");
  228. printf("\n");
  229. system("pause");
  230. system("cls");
  231. printf("==RECORD NOT FOUND==\n");
  232. }
  233. else
  234. {
  235. system("cls");
  236. printf("==SEARCHING==");
  237. printf("\n");
  238. system("pause");
  239. system("cls");
  240. printf("records found:\n");
  241. printf("%s\n\%s\n\%2s\n\%s\n","Name:","Email:","Phone number:","Date Updated:");
  242. for ( a = 0; a<=78; a++)
  243. printf("=");
  244. printf("\n");
  245. rewind(fp);
  246. while ( fread(&record, sizeof(record), 1, fp))
  247. {
  248. if (!strcmp(check,record.name))
  249. printf("%s\n\%s\n\%2s\n\%s\n", record.name, record.email, record.phonenumber, record.date_updated);
  250. }
  251. }
  252. fclose(fp);
  253. system("pause");
  254. }
  255. else
  256. {
  257. printf("Unable To Open File...\n");
  258. system("pause");
  259. }
  260. }
  261.  
  262. /*
  263. Delete Record Function
  264. ======================
  265. Generate Delete Option Menu
  266. Delete Record by Searhing Name
  267. */
  268. void delete()
  269. {
  270. char a[1];
  271. int c=1;
  272. while(c!=-1)
  273. {
  274. system("cls");
  275. puts("[1] Delete by Name");
  276. puts("[0] Back");
  277. puts("");
  278. if ( c < 1 || c > 0)
  279. {
  280. printf("!!!!Please Enter 0-1!!!!\n");
  281. }
  282. printf("Choose an Option: ");
  283. scanf("%s", a);
  284.  
  285. if(isdigit(a[0])) //Determine The Entered Value
  286. c = atoi (a);
  287. else
  288. c = -2;
  289.  
  290. switch (c)
  291. {
  292. case 1: d_name(); break; //Goto Delete by Name
  293. case 0: mainmenu(); break; //Return Main Menu
  294. default: break; //Loop Del()
  295. }
  296. }
  297. }
  298.  
  299. /*
  300. Delete by Name
  301. ========================
  302. Read Through File Stream
  303. Insert Search String
  304. String Comparison between Search String and Record Name
  305. Retrieve Data for String Comparison is True
  306. Print Out Data
  307. Flag For Delete The Printed Data
  308.   if true Clear the Record by Goto empty()
  309.   if false Return Back Delete Menu Function
  310. */
  311. void d_name()
  312. {
  313. int a;
  314. int ch;
  315. FILE *fp;
  316. char check[10];
  317. int flag;
  318. system("cls");
  319.  
  320. fp=fopen(fname,"rb+");
  321.  
  322. if(fp!=NULL)
  323. {
  324. printf("Please Enter Search String: ");
  325. scanf("%s", check);
  326.  
  327. while ( fread(&record, sizeof(record), 1, fp) && strcmp(check,record.name) );
  328.  
  329. ch=strcmp(check,record.name);
  330. if(ch!=0)
  331. {
  332. printf("==RECORD NOT FOUND==\n");
  333. system("pause");
  334. }
  335. else
  336. {
  337. system("cls");
  338. printf("==SEARCH SUCCESSFUL==\n");
  339. system("pause");
  340. system("cls");
  341. printf("%s%10s%20s%20s\n","Name","Email","Phone Number","Date Updated");
  342. for ( a = 0; a<=78; a++)
  343. printf("=");
  344. printf("\n");
  345. rewind(fp);
  346. while ( fread(&record, sizeof(record), 1, fp))
  347. {
  348. if (!strcmp(check,record.name))
  349. printf("%s%10s%20s%20s\n", record.name, record.email, record.phonenumber, record.date_updated);
  350. }
  351. printf("Delete this Record [1]/[0]: ");
  352. scanf("%1d", &flag);
  353. if (flag == 1)
  354. {
  355. empty(fp,check, record.name);
  356. printf("RECORD DELETED !!!\n");
  357. system("pause");
  358. }
  359. else
  360. return;
  361. }
  362. }
  363. else
  364. {
  365. printf("Unable To Open File...\n");
  366. system("pause");
  367. }
  368. }
  369.  
  370. /*
  371. Edit Record Function
  372. ======================
  373. Generate Edit Option Menu
  374. Edit Record by Searhing Name, Email, Phone Number, Date Updated
  375. */
  376. void edit()
  377. {
  378. char a[1];
  379. int c=1;
  380. while(c!=-1)
  381. {
  382. system("cls");
  383. puts("[1] Edit Name");
  384. puts("[2] Edit Email");
  385. puts("[3] Edit Phone number");
  386. puts("[0] Back");
  387. puts("");
  388. if ( c < 0 || c > 4)
  389. {
  390. printf("!!!!Please Enter 0-3!!!!\n");
  391. }
  392. printf("Choose an Option: ");
  393. scanf("%s", a);
  394.  
  395. if(isdigit(a[0])) //Determine The Entered Value
  396. c = atoi (a);
  397. else
  398. c = -2;
  399.  
  400. switch (c)
  401. {
  402. case 1: e_name(); break; //Goto Edit by Name
  403. case 2: e_email(); break; //Goto Edit by Email
  404. case 3: e_phonenumber(); break; //Goto Edit by PhoneNumber
  405. case 0: mainmenu(); break; //Return Main Menu
  406. default: break;//Loop Edit()
  407. }
  408. }
  409. }
  410.  
  411. /*
  412. Edit by Name Function
  413. =================================
  414. Read Through File Stream
  415. Insert Search String
  416. String Comparison between Search String and Record Name
  417. Retrieve Data for String Comparison is True
  418. Print Out Data
  419. Flag For Edit The Printed Data
  420.   if true Clear the Record by Goto change()
  421.   if false Return Back Edit Menu Function
  422. */
  423. void e_name()
  424. {
  425. int a;
  426. int ch;
  427. FILE *fp;
  428. char check[10];
  429. int flag;
  430. system("cls");
  431.  
  432. fp=fopen(fname,"rb+");
  433.  
  434. printf("Please Enter Search String: \n");
  435. scanf("%s", check);
  436.  
  437. while ( fread(&record, sizeof(record), 1, fp) && strcmp(check,record.name) );
  438.  
  439. ch=strcmp(check,record.name);
  440. if(ch!=0)
  441. {
  442. printf("==RECORD NOT FOUND==\n");
  443. system("pause");
  444. }
  445. else
  446. {
  447. system("cls");
  448. printf("==SEARCH SUCCESSFUL==\n");
  449. system("pause");
  450. system("cls");
  451. printf("%s%9s%10s%20s\n","Name","","Email","Phonenumber","DateUpdated");
  452. for ( a = 0; a<=78; a++)
  453. printf("=");
  454. printf("\n");
  455. printf("%5.5s%9.8s%10.9s%20.19s\n", record.name, record.email, record.phonenumber, record.date_updated);
  456. printf("Edit this Record [1]/[0]: ");
  457. scanf("%1d", &flag);
  458. if (flag == 1)
  459. {
  460. change(fp,check, record.name);
  461. printf("RECORD Edited !!!\n");
  462. system("pause");
  463. }
  464. else
  465. return;
  466. }
  467. }
  468.  
  469. /*
  470. Edit by Email Function
  471. =========================
  472. Read Through File Stream
  473. Insert Search String
  474. String Comparison between Search String and Record Email
  475. Retrieve Data for String Comparison is True
  476. Print Out Data
  477. Flag For Edit The Printed Data
  478.   if true Clear the Record by Goto change()
  479.   if false Return Back Edit Menu Function
  480. */
  481. void e_email()
  482. {
  483. int a;
  484. int ch;
  485. FILE *fp;
  486. char check[10];
  487. int flag;
  488. system("cls");
  489.  
  490. fp=fopen(fname,"rb+");
  491.  
  492. printf("Please Enter Search String: \n");
  493. scanf("%s", check);
  494.  
  495. while ( fread(&record, sizeof(record), 1, fp) && strcmp(check,record.email) );
  496.  
  497. ch=strcmp(check,record.email);
  498. if(ch!=0)
  499. {
  500. printf("==RECORD NOT FOUND==\n");
  501. system("pause");
  502. }
  503. else
  504. {
  505. system("cls");
  506. printf("==SEARCH SUCCESSFUL==\n");
  507. system("pause");
  508. system("cls");
  509. printf("%s%9s%10s%20s\n","Name","Email","PhoneNumber","DateUpdated");
  510. for ( a = 0; a<=78; a++)
  511. printf("=");
  512. printf("\n");
  513. printf("%5.5s%9.8s%10.9s%20.19s\n", record.name, record.email, record.phonenumber, record.date_updated);
  514. printf("Edit this Record [1]/[0]: ");
  515. scanf("%1d", &flag);
  516. if (flag == 1)
  517. {
  518. change(fp,check, record.email);
  519. printf("RECORD Edited !!!\n");
  520. system("pause");
  521. }
  522. else
  523. return;
  524. }
  525. }
  526.  
  527. /*
  528. Edit by PhoneNumber Function
  529. =================================
  530. Read Through File Stream
  531. Insert Search String
  532. String Comparison between Search String and Record PhoneNumber
  533. Retrieve Data for String Comparison is True
  534. Print Out Data
  535. Flag For Edit The Printed Data
  536.   if true Clear the Record by Goto change()
  537.   if false Return Back Edit Menu Function
  538. */
  539. void e_phonenumber()
  540. {
  541. int a;
  542. int ch;
  543. FILE *fp;
  544. char check[10];
  545. int flag;
  546. system("cls");
  547.  
  548. fp=fopen(fname,"rb+");
  549.  
  550. printf("Please Enter Search String: \n");
  551. scanf("%s", check);
  552.  
  553. while ( fread(&record, sizeof(record), 1, fp) && strcmp(check,record.phonenumber) );
  554.  
  555. ch=strcmp(check,record.phonenumber);
  556. if(ch!=0)
  557. {
  558. printf("==RECORD NOT FOUND==\n");
  559. system("pause");
  560. }
  561. else
  562. {
  563. system("cls");
  564. printf("==SEARCH SUCCESSFUL==\n");
  565. system("pause");
  566. system("cls");
  567. printf("%s%9s%10s%20s\n","Name","Email","PhoneNumber","DateUpdated");
  568. for ( a = 0; a<=78; a++)
  569. printf("=");
  570. printf("\n");
  571. printf("%5.5s%9.8s%10.9s%20.19s\n", record.name, record.email, record.phonenumber, record.date_updated);
  572. printf("Edit this Record [1]/[0]: ");
  573. scanf("%1d", &flag);
  574. if (flag == 1)
  575. {
  576. change(fp,check, record.phonenumber);
  577. printf("RECORD Edited !!!\n");
  578. system("pause");
  579. }
  580. else
  581. return;
  582. }
  583. }
  584.  
  585. /*
  586. Edit by DateUpdated Function
  587. =====================
  588. Read Through File Stream
  589. Insert Search String
  590. String Comparison between Search String and Record DateUdated
  591. Retrieve Data for String Comparison is True
  592. Print Out Data
  593. Flag For Edit The Printed Data
  594.   if true Clear the Record by Goto change()
  595.   if false Return Back Edit Menu Function
  596. */
  597. void e_dateupdated()
  598. {
  599. int a;
  600. int ch;
  601. FILE *fp;
  602. char check[10];
  603. int flag;
  604. system("cls");
  605.  
  606. fp=fopen(fname,"rb+");
  607.  
  608. printf("Please Enter Search String: \n");
  609. scanf("%s", check);
  610.  
  611. while ( fread(&record, sizeof(record), 1, fp) && strcmp(check,record.date_updated) );
  612.  
  613. ch=strcmp(check,record.date_updated);
  614. if(ch!=0)
  615. {
  616. printf("==RECORD NOT FOUND==\n");
  617. system("pause");
  618. }
  619. else
  620. {
  621. system("cls");
  622. printf("==SEARCH SUCCESSFUL==\n");
  623. system("pause");
  624. system("cls");
  625. printf("%s%9s%10s%20s\n","Name","Email","Phonenumber","DateUpdated");
  626. for ( a = 0; a<=78; a++)
  627. printf("=");
  628. printf("\n");
  629. printf("%5.5s%9.8s%10.9s%20.19s\n", record.name, record.email, record.phonenumber, record.date_updated);
  630. printf("Edit this Record [1]/[0]: ");
  631. scanf("%1d", &flag);
  632. if (flag == 1)
  633. {
  634. change(fp,check, record.date_updated);
  635. printf("RECORD Edited !!!\n");
  636. system("pause");
  637. }
  638. else
  639. return;
  640. }
  641. }
  642.  
  643. /*
  644. Display Options
  645. ===============
  646. Read through file stream
  647. Display Options
  648. */
  649. void display_options()
  650. {
  651.  
  652. system("cls");
  653. printf("Personal Address Book");
  654. printf("\n");
  655. printf("\n");
  656. printf("What you want to do\n");
  657. printf("\n");
  658. printf("[a]Search Record");
  659. printf("\n");
  660. printf("[b]Add Record");
  661. printf("\n");
  662. printf("[c]Delete Record");
  663. printf("\n");
  664. printf("[d]Edit Record");
  665. printf("\n");
  666. printf("[e]Display Options");
  667. printf("\n");
  668. printf("[f]Exit");
  669. printf("\n");
  670. printf("\n");
  671.  
  672. }
  673.  
  674. /*
  675. Clear Specific Data Memory
  676. ==========================
  677. Create a Temporary Swap File Stream
  678. Copy Specific Data Memory to Temporary Swap File Stream
  679. Delete Original File Stream
  680. Rename Temporary Swap File Stream to Original File Stream
  681. */
  682. void empty(FILE *fp, char check[],char data[])
  683. {
  684. FILE *temp;
  685. temp = fopen(fswap,"w");
  686. rewind(fp);
  687. while ( fread(&record, sizeof(record), 1, fp))
  688. {
  689. if (strcmp(check,data))
  690. fwrite(&record, sizeof(record), 1, temp);
  691. }
  692. fclose(fp);
  693. fclose(temp);
  694. remove(fname);
  695. rename(fswap, fname);
  696. }
  697.  
  698.  
  699. /*
  700. Sort Specific Data Memory
  701. ==========================
  702. Create a Temporary Swap File Stream
  703. Sort Specific Data Memory to Temporary Swap File Stream
  704. Delete Original File Stream
  705. Rename Temporary Swap File Stream to Original File Stream
  706. */
  707. void sort(FILE *fp, char data[], int type)
  708. {
  709. FILE *temp;
  710. char a = 'A';
  711. char b = '0';
  712. temp = fopen(fswap,"w");
  713. rewind(fp);
  714. switch (type)
  715. {
  716. case 1:
  717. {
  718.  
  719. while ( b >= '0' && b <= '9')
  720. {
  721. rewind(fp);
  722. while ( fread(&record, sizeof(record), 1, fp))
  723. {
  724. if (strncmp(data, &b ,1)== 0)
  725. fwrite(&record, sizeof(record), 1, temp);
  726. }
  727. b++;
  728. }
  729.  
  730. while ( a >= 'A' && a <= 'z')
  731. {
  732. rewind(fp);
  733. while ( fread(&record, sizeof(record), 1, fp))
  734. {
  735. if (strncmp(data, &a ,1)== 0)
  736. fwrite(&record, sizeof(record), 1, temp);
  737. }
  738. a++;
  739. }
  740. break;
  741. }
  742.  
  743. case 2:
  744. {
  745. char c[][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  746. int i;
  747. for(i=0;i<=11;i++)
  748. {
  749. rewind(fp);
  750. while ( fread(&record, sizeof(record), 1, fp))
  751. {
  752. if (strncmp(data, c[i] ,3)== 0)
  753. fwrite(&record, sizeof(record), 1, temp);
  754. }
  755. }
  756. break;
  757. }
  758.  
  759. }
  760.  
  761. fclose(fp);
  762. fclose(temp);
  763. remove(fname);
  764. rename(fswap, fname);
  765. }
  766.  
  767. /*
  768. Edit Specific Data Memory
  769. =========================
  770. Seeking The Address of Specific Data Memory
  771. Enter Information for Edit Data Memory
  772. Edit Specific Data Memory by Overwrite the Original Specific Data Memory
  773. */
  774. void change(FILE *fp, char check[],char data[])
  775. {
  776. rewind(fp);
  777. while ( fread(&record, sizeof(record), 1, fp) && strcmp(check,data));
  778. if (!strcmp(check,data))
  779. {
  780. printf("Enter Name: ");
  781. scanf("%s", record.name);
  782. printf("Enter Email: ");
  783. scanf("%s", record.email);
  784. printf("Enter PhoneNumber: ");
  785. scanf("%s", record.phonenumber);
  786. printf("Enter DateUpdated: ");
  787. scanf("%s", record.date_updated);
  788.  
  789. fseek(fp, ftell(fp) - sizeof(record),0);
  790. fwrite(&record, sizeof(record), 1, fp);
  791. }
  792. fclose(fp);
  793. }
  794.  
  795. void credit()
  796. {
  797. puts("ECP1016 Take Home Assignment");
  798. puts("Topic 1: Simple Personal Address Book");
  799. puts("================================================");
  800. puts("");
  801. puts("Inquiry Lecturer: Mr. Chin");
  802. puts("");
  803. puts("Group Member");
  804. puts("------------");
  805. puts("1. Sia Saoh Liang ID:1061103072 Lecture Group:EC104 Tutorial Group:ECD03");
  806. system("pause");
  807. }
Last edited by Narue; Sep 8th, 2008 at 4:56 pm. Reason: fixed code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,858
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Address book

 
1
  #4
Sep 8th, 2008
Amazing! I see you in a completely different light now. It's incredible how showing your code changes you from a leech into someone who deserves help.

>But some function does not working.
Which ones? No offense, but that's a lot of code to troubleshoot with only the "not working" bug report.

>i dun noe how to make the date and time automatically updated
I'm not sure if you're allowed to use it, but strftime is the easiest way to format a date and time. Just call it when you need to update the string and you're solid. Here's an example of how to use it for the current time:
  1. #include <ctime>
  2. #include <iostream>
  3.  
  4. int main()
  5. {
  6. char dummy;
  7.  
  8. do {
  9. char buffer[1024];
  10. time_t now = time ( 0 );
  11.  
  12. strftime ( buffer, 1024, "%d-%m-%Y %H:%M:%S", localtime ( &now ) );
  13. std::cout<< buffer <<'\n';
  14. } while ( std::cin.get ( dummy ) );
  15. }
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 4
Reputation: ryukifaiz is an unknown quantity at this point 
Solved Threads: 0
ryukifaiz ryukifaiz is offline Offline
Newbie Poster

Re: Address book

 
0
  #5
Sep 8th, 2008
Mr.Programmer,did you open the file i attached?Can u help me write the program or modified my code?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,858
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Address book

 
1
  #6
Sep 8th, 2008
>did you open the file i attached?
Seeing as how that was the only way I could have known the required format for the date-time, it's safe to assume that I did. Thanks for asking though.

>Can u help me write the program or modified my code?
Can you read? Because I'm certain I asked you for more detail. If you fail to provide that detail, I'm not going to spend my valuable time rooting through your mass of code trying to find bugs when I have no vested interest in the program.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 4
Reputation: ryukifaiz is an unknown quantity at this point 
Solved Threads: 0
ryukifaiz ryukifaiz is offline Offline
Newbie Poster

Re: Address book

 
0
  #7
Sep 8th, 2008
Mr.Programmer,i hope u will help me because i really don't know how to continue my work on it

How to add and search :if i add
jimmyneutron
neutron jimmy
how to make this two contact apppear when i type jimmy in search function?


And how to use the auto update time and date in my program?how to declare it?
Last edited by ryukifaiz; Sep 8th, 2008 at 5:45 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: Address book

 
0
  #8
Sep 8th, 2008
It sounds like you need a map, or an algorithm to determine a match for a set amount of values.

Personally, to get things working, I'd take the easy way out until I found a more efficient solution.

What immediately comes to mind is something like this--

  1. #include <iostream>
  2. #include <map>
  3. #include <utility>
  4. #include <string>
  5. #include <vector>
  6.  
  7. using std::string;
  8. using std::map;
  9. using std::pair;
  10. using std::vector;
  11.  
  12. template<class L, class N> void safeInsert(map<L, vector<N> >&, L, N);
  13. template<class L, class N> pair<L, vector<N> > safePair(L, vector<N>);
  14.  
  15. template<class L, class R>
  16. void safeInsert(map<L, vector<R> > &m, L key, R value){
  17. if(&m[key] == NULL){
  18. vector<R> temp;
  19. temp.push_back(value);
  20. m.insert(safePair<L, R>(key, temp));
  21. }
  22. else m[key].push_back(value);
  23. }
  24.  
  25. template<class L, class R>
  26. pair<L, vector<R> > safePair(L lhs, vector<R> rhs){
  27. pair<L, vector<R> > p (lhs, rhs);
  28. return p;
  29. }
  30.  
  31. int main(){
  32.  
  33. map<string, vector<string> > myList;
  34. safeInsert(myList, string("Joe"), string("Joe"));
  35. safeInsert(myList, string("Joe"), string("Joe Smith"));
  36. safeInsert(myList, string("Bob"), string("Bob Marley"));
  37.  
  38. vector<string> result = myList[string("Joe")];
  39.  
  40. for(vector<string>::iterator next = result.begin(); next != result.end(); next++)
  41. std::cout << *next << std::endl;
  42.  
  43. return 0;
  44. }

-- though again it might not be perfect, but it meets the criteria without dipping far into algorithms or relying on queries to achieve similar results.

Edit: Rereading the post, I realized you need either a regex or a parser to determine the key to use the above method.

This link might also help - substr
Last edited by Alex Edwards; Sep 8th, 2008 at 6:59 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 476 | Replies: 7
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC