Alx09

Untitled

Dec 11th, 2020
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.26 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string>
  5. #include<time.h>
  6. #define _CRT_SECURE_NO_WARNING
  7. using namespace std;
  8.  
  9.  typedef struct data{
  10.     unsigned short zi, luna, an;
  11. }data;
  12.  
  13.  typedef struct adresa {
  14.      string localitate, judet, strada, codPostal;
  15.      unsigned short nr;
  16.  }adresa;
  17.  unsigned short GetAge(struct data &dataNastere) {
  18.      unsigned short age;
  19.      time_t t = time(NULL);
  20.      struct tm tm = *localtime(&t);
  21.      age = tm.tm_year + 1900  - dataNastere.an;
  22.      if (tm.tm_mon + 1 > dataNastere.luna) age--;
  23.      else if (tm.tm_mon + 1 == dataNastere.luna && tm.tm_mday > dataNastere.zi)age--;
  24.      return age;
  25.  }
  26.  unsigned short GetYear(unsigned short year) {
  27.      time_t t = time(NULL);
  28.      struct tm tm = *localtime(&t);
  29.      if (tm.tm_year  < year) return 1900 + year;
  30.      else
  31.          return tm.tm_year + 1900 - year;
  32.  }
  33.  class Cadou
  34.  {
  35.  protected:
  36.      static Cadou *headCadou;
  37.      Cadou *next;
  38.      string nume, tip;
  39.      double pret;
  40.  public:
  41.      Cadou(string nume, string tip, double pret);
  42.  
  43.  };
  44.  Cadou * Cadou::headCadou = NULL;
  45.  
  46. class Persoana {
  47. private:
  48.     static Persoana *head;
  49.     Persoana *next;
  50.     Cadou *headCadou;
  51.     string nume;
  52.     char CNP[13];
  53.     unsigned short varsta;
  54.     bool isMan;
  55.     struct data dataNastere;
  56.     struct adresa adresa;
  57. public:
  58.     Persoana(string nume, char *CNP, struct adresa &adresa) {
  59.         this->nume = nume;
  60.         strcpy(this->CNP, CNP);
  61.         if (CNP[0] == '1' || '5') isMan = true;
  62.         else isMan = false;
  63.         dataNastere.an = GetYear((CNP[1]-48) * 10 + (CNP[2]- 48));
  64.         dataNastere.luna = (CNP[3] - 48) * 10 + (CNP[4] - 48);
  65.         dataNastere.zi = (CNP[5] - 48) * 10 + (CNP[6] - 48);
  66.         this->adresa.codPostal = adresa.codPostal;
  67.         this->adresa.judet = adresa.judet;
  68.         this->adresa.localitate = adresa.localitate;
  69.         this->adresa.nr = adresa.nr;
  70.         this->adresa.strada = adresa.strada;
  71.         this->next = NULL;
  72.         this->headCadou = NULL;
  73.         if (head == NULL) {
  74.             head = this;
  75.             return;
  76.         }
  77.         if (head->nume > this->nume) {
  78.             this->next = head;
  79.             head = this;
  80.             return;
  81.         }
  82.         Persoana *q = head;
  83.         while (q->next && q->next->nume < this->nume) q = q->next;
  84.         this->next = q->next;
  85.         q->next = this;
  86.     }
  87.     static void Adauga_cadou(char *CNP) {
  88.         Persoana *q = head;
  89.         while (q && strcmp(q->CNP, CNP))
  90.             q = q->next;
  91.         if (!q) {
  92.             cout << "\nPersoana cu CNP: " << CNP << " nu se afla in baza de date";
  93.             return;
  94.         }
  95.        
  96.     }
  97.     void setHeadcadou(Persoana *q, Cadou *c) {
  98.         q->headCadou = c;
  99.     }
  100. };
  101.  
  102. Persoana * Persoana::head = NULL;
  103.  
  104. Cadou::Cadou(string nume, string tip, double pret)
  105. {
  106.     this->nume = nume;
  107.     this->pret = pret;
  108.     this->tip = tip;
  109.     this->next = NULL;
  110.    
  111.     Cadou *q = headCadou;
  112.     if (headCadou == NULL) {
  113.         headCadou = this;
  114.         return;
  115.     }
  116.     if (headCadou->nume > this->nume) {
  117.         this->next = headCadou;
  118.         headCadou = this;
  119.         return;
  120.     }
  121.  
  122.     while (q->next && q->next->nume < this->nume) q = q->next;
  123.     this->next = q->next;
  124.     q->next = this;
  125.  
  126. }
  127.  
  128.  
  129.  
  130.  
  131. int main() {
  132.    
  133.     bool help;
  134.     int opt;
  135.     do {
  136.         cout << "\n\n";
  137.         cout << "1.Adaugare Persoana\n";
  138.         cout << "2.Afis  persoane \n";
  139.         cout << "0.Iesire \n";
  140.         cout << "Dati optiunea dvs: ";
  141.         cin >> opt;
  142.         system("cls");
  143.         switch (opt) {
  144.         case 1:
  145.        
  146.             break;
  147.         case 2:
  148.        
  149.             break;
  150.  
  151.         case 0:
  152.             break;
  153.  
  154.         }
  155.     } while (opt != 0);
  156.     return 0;
  157. }
  158.  
Advertisement
Add Comment
Please, Sign In to add comment