Advertisement
Guest User

creating database with c++

a guest
Jan 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. typedef struct Person{
  5. double age;
  6. double height;
  7. Person *next;
  8. } PERSON;
  9. void display_list (PERSON *start);
  10. void create_person(PERSON *p);
  11. void add_to_list(PERSON *start);
  12. int main()
  13. {
  14. PERSON *p1 =new PERSON;
  15. PERSON *p2 =new PERSON;
  16. PERSON *p3 = new PERSON;
  17.  
  18. p1 -> age=22;
  19. p1 -> height =180;
  20. p2 -> age =25;
  21. p2 -> height =170;
  22. p3 -> age = 33;
  23. p3 -> height = 168;
  24.  
  25. p1->next = p2;
  26. p2-> next =p3;
  27. p3-> next = NULL;
  28.  
  29. display_list(p1);
  30. for(int i=0; i<=100; i++) add_to_list(p1);
  31. cout<< endl;
  32. display_list(p1);
  33. return 0;
  34. }
  35. void add_to_list(PERSON *start){
  36. PERSON *p0 =start;
  37. while(1){
  38. if(p0->next== NULL) break;
  39. p0=p0->next;
  40. }
  41. PERSON *newperson =new PERSON;
  42. create_person(newperson);
  43. p0->next =newperson;
  44. newperson->next= NULL;
  45.  
  46. }
  47.  
  48.  
  49.  
  50. void create_person(PERSON *p){
  51. p->age = rand()%21+80;
  52. p->height=rand()%50+150;
  53. }
  54.  
  55.  
  56. void display_list (PERSON *start){
  57. PERSON *p0=start;
  58. while(1){
  59. cout<< " age " << p0-> age << "height " << p0->height<< endl;
  60. if (p0->next == NULL) break;
  61. p0=p0->next;
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement