Sunteți pe pagina 1din 4

#include<iostream>

#include<string.h>
#include<conio.h>

using namespace std;


class Agentie
{
int ofertaNr;
char *locTara;
int pret;
int nrZile;
Agentie *urm;
public:
Agentie(int ofertanr, char loctara[], int p, int nrzile)
{
ofertaNr = ofertanr;
locTara = new char(strlen(loctara) + 1);
strcpy(locTara, loctara);
pret = p;
nrZile = nrzile;
urm = NULL;
}
virtual void afisare()
{
cout << ofertaNr << " " << locTara << " " << pret << " " <<
nrZile << " ";
}
friend class Lista;
};
class VacantaLaMare : public Agentie
{
char *tipNisip;
int temperatura;
public:
VacantaLaMare(int ofertanr, char loctara[], int p, int nrzile, char
tipnisip[], int temp) : Agentie(ofertanr, loctara, p, nrzile)
{
tipNisip = new char(strlen(tipnisip) + 1);
strcpy(tipNisip, tipnisip);
temperatura = temp;
}
void afisare()
{
Agentie::afisare();
cout << tipNisip << " " << temperatura << "\n\n";
}
friend class Lista;
};
class VacantaLaMunte : public Agentie
{
int altitudine;
public:
VacantaLaMunte(int ofertanr, char loctara[], int p, int nrzile, int
alt) : Agentie(ofertanr, loctara, p, nrzile)
{
altitudine = alt;
}
void afisare()
{
Agentie::afisare();
cout << altitudine << "\n\n";
}
friend class Lista;
};
class Lista
{
public:
Agentie *head;
void adaugare(Agentie *a);
void afisare();
void afisarePretMic(int pretMaxim);
};
void Lista::adaugare(Agentie *a)
{
Agentie *p;
p = head;
if (!p)
{
head = a;
}
else
{
if (strcmp(a->locTara , p->locTara) < 0)
{
a->urm = p;
head = a;
}
else
{
while (p->urm && strcmp(a->locTara, p->locTara)>0)
{
p = p->urm;
}
a->urm = p->urm;
p->urm = a;
}
}
}
void Lista::afisare()
{
Agentie *p;
p = head;
if (!p)
cout << "Lista vida" << endl;
else
{
while (p)
{
p->afisare();
p = p->urm;
}
}
}

void Lista::afisarePretMic(int pretMaxim)


{
Agentie *p;
p = head;
if (!p)
cout << "Lista vida" << endl;
else
{
while (p)
{
if (p->pret <= pretMaxim) {
p->afisare();
}
p = p->urm;
}
}
}

void inserare(Lista &l, int x)


{
Agentie *a;
char tipnisip[30], loctara[30];
int temp, alt, ofertanr, pretul, nrzile;
cout << "Oferta nr:";
cin >> ofertanr;
cout << "Pretul: ";
cin >> pretul;
cout << "Localitate si tara:";
cin >> loctara;
cout << "Numar zile: ";
cin >> nrzile;
if (x == 0)
{
VacantaLaMare *mare;
cout << "Tip nisip: ";
cin >> tipnisip;
cout << "Temperatura: ";
cin >> temp;
mare = new VacantaLaMare(ofertanr, loctara, pretul, nrzile,
tipnisip, temp);
a = mare;
l.adaugare(a);
}
if (x == 1)
{
VacantaLaMunte *munte;
cout << "Altitudine: ";
cin >> alt;
munte = new VacantaLaMunte(ofertanr, loctara, pretul,
nrzile, alt);
a = munte;
l.adaugare(a);
}
}
int main()
{
Lista l;
l.head = NULL;
int opt = -1; char n[30];
while (opt != 0)
{
cout << "1. Adaugare vacanta mare\n";
cout << "2. Adaugare vacanta munte\n";
cout << "3. Afisare vacante\n";
cout << "4. Afisare oferte cu pret maxim ales\n";
cout << "0. Exit\n\nIntroduceti optiunea dvs: ";
cin >> opt;
switch (opt)
{
case 1:
inserare(l, 0);
break;
case 2:
inserare(l, 1);
break;
case 3:
l.afisare();
break;
case 4:
int pm;
cout << "Pret maxim:";
cin >> pm;
l.afisarePretMic(pm);
break;
case 0:
break;
default:
cout << "Comanda invalida" << endl;
break;
}
}
return 0;
}