Facebook
From jarek, 3 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 54
  1. #include <iostream>
  2. #include <string>
  3.  
  4. struct person
  5.  
  6.     std::string name;
  7.     std::string surename;
  8.     std::string email;
  9.     std::string adress;
  10.     int nr_tel;
  11.     person * next;
  12. };
  13. person * poczatek = NULL;
  14. void add_person()
  15. {
  16.     person * nowa = new person;
  17.     nowa ->next = NULL;
  18.     std::cout <<"Enter a name: ";
  19.     std::cin >> nowa ->name;
  20.     std::cout <<"Enter surename ";
  21.     std::cin >> nowa->surename;
  22.     std::cout <<"Enter email ";
  23.     std::cin >> nowa->email;
  24.     std::cout <<"Enter adress ";
  25.     std::cin >> nowa->adress;
  26.     std::cout <<"Enter nr_tel ";
  27.     std::cin >> nowa->nr_tel;
  28.     if(poczatek == NULL )
  29.     {
  30.         poczatek = nowa;
  31.     }
  32.     else
  33.     {
  34.         person * szukaj = poczatek;
  35.         while( szukaj->next != NULL )
  36.         {
  37.             szukaj = szukaj->next;
  38.         }
  39.         szukaj->next = nowa;
  40.     }
  41.    
  42.    
  43. }
  44. void showperson()
  45. {
  46.  
  47.     if( poczatek != NULL ) //zmieniłem z == na !=
  48.     {
  49.         person * pokaz = poczatek;
  50.         while( pokaz->next != NULL )
  51.         {
  52.             std::cout <<"+++++++++++++++++++++"<<std::endl;
  53.             std::cout << pokaz->name << std::endl;
  54.             std::cout << pokaz->surename << std::endl;
  55.             std::cout << pokaz->email << std::endl;
  56.             std::cout << pokaz->adress << std::endl;
  57.             std::cout << pokaz->nr_tel << std::endl;
  58.             pokaz = pokaz->next;
  59.         }
  60.         std::cout <<"+++++++++++++++++++++"<<std::endl;
  61.         std::cout <<"Name: "<<pokaz->name << std::endl;
  62.         std::cout <<"Surename: " <<pokaz->surename <<std::endl;
  63.         std::cout <<"Email: "<< pokaz->email << std::endl;
  64.         std::cout <<"Adress: "<< pokaz->adress << std::endl;
  65.         std::cout <<"Phone number: " <<pokaz->nr_tel << std::endl;
  66.    
  67.     }
  68. }
  69. int main()
  70. {
  71.     int ilosc;
  72.     int answer;
  73. do
  74. {
  75. std::cout << "Welcome to the address book" <<std::endl;
  76.     std::cout <<"[1]Save Person"<<std::endl;
  77.     std::cout <<"[2] Show person" <<std::endl;
  78.     std::cout <<"Enter a number: ";
  79.     std::cin>>answer;
  80.     switch(answer)
  81.     {
  82.         case 1:
  83.         {
  84.             add_person();
  85.             break;
  86.         }
  87.         case 2:
  88.         {
  89.             system("cls");
  90.             showperson();
  91.             break;
  92.         }
  93.         default:
  94.         {
  95.             std::cout << "Father not available" <<std::endl;
  96.         }
  97.     }
  98. }while(answer != 4);
  99.    
  100. }