Pagini recente » Cod sursa (job #602907) | Cod sursa (job #2794455) | Cod sursa (job #1825585) | Cod sursa (job #3184495) | Cod sursa (job #2207252)
// Darii Dan 134
// GNU GCC Compiler
#include <iostream>
#include <bits/stdc++.h>
template<class T>
struct Triplet
{
T zi,luna,an;
};
typedef Triplet<int> Data;
using namespace std;
class Companie
{
protected:
static int nr;
string denumire;
string cod_fiscal;
float tarif;
float dist;
public:
Companie(){nr++;}
~Companie(){}
friend istream& operator>> (istream&, Companie&);
string get_nume()
{
return denumire;
}
virtual void print()
{
cout << denumire << " " << cod_fiscal << " " << "Tarif = " << tarif << " Distanta = " << dist << endl;
}
};
int Companie::nr = 0;
istream& operator>> (istream&in, Companie& x)
{
cout << "Dati denumire companiei\n";
in >> x.denumire;
cout << "Dati codul fiscal\n";
in >> x.cod_fiscal;
cout << "Dati tariful\n";
in >> x.tarif;
cout << "Dati distanta";
in >> x.dist;
return in;
}
class Precomanda : public Companie
{
string numele;
string data;
string ora;
string sursa;
string destinatie;
static float profit;
public:
void aeroport()
{
if (destinatie == "aeroport")
tarif = tarif*2;
}
friend istream& operator>>(istream&, Precomanda&);
void print()
{
cout << numele << " " << data << " " << ora << " " << sursa << " " << destinatie << endl;
}
float get_profit()
{
return profit;
}
};
float Precomanda::profit = 0;
istream& operator>>(istream& in, Precomanda& x)
{
in >> (Companie&)x;
cout << "Dati numele\n";
in >> x.numele;
cout << "Dati data\n";
in >> x.data;
cout << "Dati ora\n";
in >> x.ora;
cout <<"Dati sursa\n";
in >> x.sursa;
cout << "Dati destinatia";
in >> x.destinatie;
x.aeroport();
x.profit = x.profit + x.tarif;
return in;
}
class Uber: public Companie
{
string nume;
string nr_licenta;
bool limuzina;
string nume_client;
string marca;
string data;
string ora;
string locatia;
static float profit;
public:
Uber(){}
~Uber(){}
friend istream& operator>> (istream&, Uber&);
float get_profit()
{
return profit;
}
void print()
{
cout << " Sofer: " << nume << " " << nr_licenta << " ";
if (limuzina == true)
{
cout << nume_client << " " << marca << " " << data << " " << ora << " " << locatia << endl;
}
}
};
float Uber::profit = 0;
istream& operator>> (istream& in , Uber& x)
{
in>> (Companie&)x;
cout << "Dati numele soferului\n";
in >> x.nume;
cout << "Dati numar licenta \n";
in >> x.nr_licenta;
cout << "Doriti limuzina ?(0/1)\n";
in >> x.limuzina;
if (x.limuzina == true )
{
cout << "Dati numele clientului\n";
in >> x.nume_client;
cout << "Dati marca\n";
in >> x.marca;
cout << "Dati data\n";
in >> x.data;
cout << "Dati ora\n";
in >>x.ora;
cout << "Dati locatia \n";
in >> x.locatia;
}
x.profit = x.profit + x.tarif;
return in;
}
int main()
{
int nr,op,flag = 0;
cout << "Dati numarul de comenzi\n";
cin >> nr;
Companie **p = new Companie*[nr];
for (int i = 0; i <nr; i++)
{
cout << "Tip companie \n 1.Cu precomanda \n 2. Uber\n";
cin >> op;
switch(op)
{
case 1:
{
p[i] = new Precomanda;
cin >> *dynamic_cast<Precomanda*>(p[i]);
break;
}
case 2:
{
p[i] = new Uber;
cin >> *dynamic_cast<Uber*>(p[i]);
break;
}
}
}
for (int i =0 ; i< nr; i++)
{
p[i]->print();
cout << endl;
}
while (flag == 0)
{
cout << "Alegeti optiunea\n 1. A afisa toate comezile \2. A Afisa companiile in ordinea desc a profitului \3.exit";
cin >> op;
switch(op)
{
case 1:
{
for (int i =0 ; i< nr; i++)
{
p[i]->print();
cout << endl;
}
break;
}
case 2:
{Precomanda a; Uber b;
if (a.get_profit() < b.get_profit())
{
cout << b.get_nume() << " " << a.get_nume() << endl;
}
else cout << a.get_nume() << " " << b.get_nume() << endl;
break;}
case 3:
flag = 1;
}
}
return 0;
}