Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stdio.h>
- #include<stdlib.h>
- #include<string>
- #include<time.h>
- #define _CRT_SECURE_NO_WARNING
- using namespace std;
- typedef struct data{
- unsigned short zi, luna, an;
- }data;
- typedef struct adresa {
- string localitate, judet, strada, codPostal;
- unsigned short nr;
- }adresa;
- unsigned short GetAge(struct data &dataNastere) {
- unsigned short age;
- time_t t = time(NULL);
- struct tm tm = *localtime(&t);
- age = tm.tm_year + 1900 - dataNastere.an;
- if (tm.tm_mon + 1 > dataNastere.luna) age--;
- else if (tm.tm_mon + 1 == dataNastere.luna && tm.tm_mday > dataNastere.zi)age--;
- return age;
- }
- unsigned short GetYear(unsigned short year) {
- time_t t = time(NULL);
- struct tm tm = *localtime(&t);
- if (tm.tm_year < year) return 1900 + year;
- else
- return tm.tm_year + 1900 - year;
- }
- class Persoana;
- class Cadou
- {
- protected:
- static Cadou *headCadou;
- Cadou *next;
- string nume, tip;
- double pret;
- public:
- Cadou(string nume, string tip, double pret);
- static void AdaugaCadou(Persoana *q, char*CNP);
- virtual void Afisare() = 0;
- };
- Cadou * Cadou::headCadou = NULL;
- class Jucarii : public Cadou {
- private:
- string marca;
- bool bateriNecesare;
- unsigned short varstaRecomandata;
- public:
- Jucarii(string nume, string tip, double pret, string marca, bool bateriNecesare, unsigned short varstaRecomandata) :Cadou(nume, tip, pret) {
- this->marca = marca;
- this->bateriNecesare = bateriNecesare;
- this->varstaRecomandata = varstaRecomandata;
- }
- void Afisare() {
- cout <<"\n"<< nume << " " << marca << " " << tip;
- if (bateriNecesare) cout << " bateri necesare ";
- else cout << " nu sunt necesare bateri ";
- cout << varstaRecomandata << " " << pret;
- }
- };
- class PachetCadou : public Cadou {
- private:
- bool pentruBarbati;
- unsigned short nrProd;
- public:
- PachetCadou(string nume, string tip, double pret, bool pentruBarbati, unsigned short nrProd) :Cadou(nume, tip, pret) {
- this->pentruBarbati = pentruBarbati;
- this->nrProd = nrProd;
- }
- void Afisare() {
- cout << "\n" << nume << " " << " " << tip <<" " << nrProd;
- if (pentruBarbati) cout << " de barbati ";
- else cout << " de femei ";
- cout << pret;
- }
- };
- class Dulciuri : public Cadou {
- private:
- string ingrediente;
- double calori, gramaj;
- public:
- Dulciuri(string nume, string tip, double pret, string ingrediente, double calori, double gramaj) :Cadou(nume, tip, pret) {
- this->ingrediente = ingrediente;
- this->calori = calori;
- this->gramaj = gramaj;
- }
- void Afisare() {
- cout << "\n" << nume << " " << " " << tip << " " <<gramaj <<" " <<round( calori * 100/ gramaj)<<" "<< ingrediente <<" "<< pret;
- }
- };
- class Persoana {
- private:
- static Persoana *head;
- Persoana *next;
- Cadou *headCadou;
- string nume;
- char CNP[13];
- unsigned short varsta;
- bool isMan;
- struct data dataNastere;
- struct adresa adresa;
- public:
- Persoana(string nume, char *CNP, struct adresa &adresa) {
- this->nume = nume;
- strcpy(this->CNP, CNP);
- if (CNP[0] == '1' || '5') isMan = true;
- else isMan = false;
- dataNastere.an = GetYear((CNP[1]-48) * 10 + (CNP[2]- 48));
- dataNastere.luna = (CNP[3] - 48) * 10 + (CNP[4] - 48);
- dataNastere.zi = (CNP[5] - 48) * 10 + (CNP[6] - 48);
- this->adresa.codPostal = adresa.codPostal;
- this->adresa.judet = adresa.judet;
- this->adresa.localitate = adresa.localitate;
- this->adresa.nr = adresa.nr;
- this->adresa.strada = adresa.strada;
- this->next = NULL;
- this->headCadou = NULL;
- if (head == NULL) {
- head = this;
- return;
- }
- if (head->nume > this->nume) {
- this->next = head;
- head = this;
- return;
- }
- Persoana *q = head;
- while (q->next && q->next->nume < this->nume) q = q->next;
- this->next = q->next;
- q->next = this;
- }
- static void Adauga_cadou(char *CNP) {
- Persoana *q = head;
- while (q && strcmp(q->CNP, CNP))
- q = q->next;
- if (!q) {
- cout << "\nPersoana cu CNP: " << CNP << " nu se afla in baza de date";
- return;
- }
- }
- friend static void Cadou::AdaugaCadou(Persoana *q, char*CNP);
- };
- Persoana * Persoana::head = NULL;
- Cadou::Cadou(string nume, string tip, double pret)
- {
- this->nume = nume;
- this->pret = pret;
- this->tip = tip;
- this->next = NULL;
- Cadou *q = headCadou;
- if (headCadou == NULL) {
- headCadou = this;
- return;
- }
- if (headCadou->nume > this->nume) {
- this->next = headCadou;
- headCadou = this;
- return;
- }
- while (q->next && q->next->nume < this->nume) q = q->next;
- this->next = q->next;
- q->next = this;
- }
- void Cadou::AdaugaCadou(Persoana *q, char *CNP) {
- if (q == NULL) {
- q = Persoana::head;
- while (q && strcmp(q->CNP, CNP)) q = q->next;
- try
- {
- if (Persoana::head == NULL) throw 1;
- if (q == NULL) throw 2;
- }
- catch (int error)
- {
- switch (error)
- {
- case 1: cout << "\nLista este goala"; break;
- case 2: cout << "\nNu exista vreo persoana cu CNP: " << CNP << " in baza de date";
- default:
- break;
- }
- return;
- }
- }
- Dulciuri *dulce;
- Jucarii *jucarie;
- PachetCadou *pachetcadou;
- int opt;
- }
- int main() {
- bool help;
- int opt;
- do {
- cout << "\n\n";
- cout << "1.Adaugare Persoana\n";
- cout << "2.Afis persoane \n";
- cout << "0.Iesire \n";
- cout << "Dati optiunea dvs: ";
- cin >> opt;
- system("cls");
- switch (opt) {
- case 1:
- break;
- case 2:
- break;
- case 0:
- break;
- }
- } while (opt != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement