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>
- #include<list>
- #include<iterator>
- #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:
- string nume, tip;
- double pret;
- public:
- Cadou(string nume, string tip, double pret);
- virtual void Afisare() = 0;
- string get_nume() {
- return nume;
- }
- };
- 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:
- string nume;
- char CNP[13];
- unsigned short varsta;
- bool isMan;
- struct data dataNastere;
- struct adresa adresa;
- list <Cadou *> listaCadou;
- 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;
- }
- void CitireCadou();
- };
- Cadou::Cadou(string nume, string tip, double pret)
- {
- this->nume = nume;
- this->pret = pret;
- this->tip = tip;
- }
- void Persoana::CitireCadou()
- {
- list <Cadou *>::iterator it;
- string nume, tip;
- double pret;
- char t;
- cout << "\nCe fel de cadou D- Dulciuri, P- Pachet Cadou, J -Jucarie: "; cin >> t;
- cout << "Nume: "; cin >> nume;
- cout << "Pret: "; cin >> pret;
- cout << "Tip: "; cin >> tip;
- if (t == 'P') {
- string ingrediente;
- double calori, gramaj;
- cout << "Ingerdiente: "; cin >> ingrediente;
- cout << "Calori: "; cin >> calori;
- cout << "Gramaj: "; cin >> gramaj;
- if (listaCadou.empty())
- listaCadou.push_back(new Dulciuri(nume, tip, pret,ingrediente, calori, gramaj));
- else {
- it = listaCadou.begin();
- while (it != listaCadou.end() && (*it)->get_nume() < nume)
- advance(it, 1);
- listaCadou.emplace(it, new Dulciuri(nume, tip, pret, ingrediente, calori, gramaj));
- }
- }
- if (t == 'P') {
- bool pentruBarbati;
- unsigned short nrProd;
- cout << "Este pentru femei - 0, barbati - 1: "; cin >> pentruBarbati;
- cout << "Numar de produse in pachet: "; cin >> nrProd;
- if (listaCadou.empty())
- listaCadou.push_back(new PachetCadou(nume, tip, pret, pentruBarbati, nrProd));
- else {
- it = listaCadou.begin();
- while (it != listaCadou.end() && (*it)->get_nume() < nume)
- advance(it, 1);
- listaCadou.emplace(it, new PachetCadou(nume, tip, pret, pentruBarbati, nrProd));
- }
- }
- if (t == 'J') {
- string marca;
- bool bateriNecesare;
- unsigned short varstaRecomandata;
- cout << "Marca: "; cin >> marca;
- cout << "Are nevoie de bateri Nu - 0, Da - 1: "; cin >> bateriNecesare;
- cout << "Varsta recomandata: "; cin >> varstaRecomandata;
- if (listaCadou.empty())
- listaCadou.push_back(new Jucarii(nume, tip, pret, marca, bateriNecesare, varstaRecomandata));
- else {
- it = listaCadou.begin();
- while (it != listaCadou.end() && (*it)->get_nume() < nume)
- advance(it, 1);
- listaCadou.emplace(it, new Jucarii(nume, tip, pret, marca, bateriNecesare, varstaRecomandata));
- }
- }
- }
- int main() {
- string nume;
- char CNP[20];
- unsigned short varsta;
- bool isMan;
- struct data dataNastere;
- struct adresa adresa;
- int opt;
- do {
- cout << "\n\n";
- cout << "1.Adaugare Persoana si lista de cadouri\n";
- cout << "2.Afisare persoane si lista caduri sub forma tabelara\n";
- cout << "0.Iesire \n";
- cout << "Dati optiunea dvs: ";
- cin >> opt;
- system("cls");
- switch (opt) {
- case 1:
- cout << "Nume persoana: "; cin >> nume;
- cout << "CNP: "; cin >> CNP;
- try
- {
- if (strlen(CNP) < 12) throw 1;
- }
- catch (int error)
- {
- if (error == 1) cout << "CNP are prea putine cifre";
- }
- break;
- case 2:
- break;
- case 0:
- break;
- }
- } while (opt != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement