Вы находитесь на странице: 1из 10

//

// Created by Alex on 5/27/2019.


//

#ifndef COLOCVIU2018TAXI_COMPANIE_H
#define COLOCVIU2018TAXI_COMPANIE_H

#include <array>
#include <iostream>

using namespace std;

class Companie {
protected:
string denumire;
int codFiscal;
double tarif;
int profit;
public:
Companie(string den, int cod, double tar);
Companie(){};
virtual double calcTarif(){};
virtual void write(ostream& out) = 0;
bool operator<(const Companie& other){
return profit < other.profit;
}
friend ostream& operator<<(ostream& out, Companie& c);
};

Companie::Companie(string den, int cod, double tar) {


denumire = den;
codFiscal = cod;
tarif = tar;
profit = 0;
}

ostream& operator<<(ostream& out, Companie& c) {


out << "Numele companiei: " << c.denumire << " ||| ";
out << "Codul fiscal al companiei: " << c.codFiscal << " ||| ";
out << "Tariful companiei: " << c.tarif << " ||| \n";
c.write(out);
return out;
}

#endif //COLOCVIU2018TAXI_COMPANIE_H

//
// Created by Alex on 5/27/2019.
//

#ifndef COLOCVIU2018TAXI_COMPANIEPRECOMANDA_H
#define COLOCVIU2018TAXI_COMPANIEPRECOMANDA_H

#include <vector>
#include "../Companie.h"
class Precomanda {
private:
string nume, data, ora, sursa, destinatie;
double km;
bool aeroport;
public:
Precomanda(string n, string d, string o, string s, string dest, double k, bool
a)
: nume(n), data(d), ora(o), sursa(s), destinatie(dest), km(k),
aeroport(a) {};
void afisPrecomanda(ostream& os){
os << "Numele clientului: " << nume << '\n';
os << "Data si ora precomenzii: " << data << " " << ora << '\n';
os << "Locul de preluare: " << sursa << '\n';
os << "Destinatia: " << destinatie << '\n';
}
int getKm(){
return km;
}
bool toAirport(){
return aeroport;
}
};

class CompaniePreComanda : public Companie{


vector <Precomanda> precomenzi;
public:
CompaniePreComanda(string den, int cod, double tar) : Companie(den, cod, tar)
{};
void solicitaPrecomanda(Precomanda p){
precomenzi.push_back(p);
profit += p.getKm() * tarif;
}
double getKm(Precomanda p){
if(p.toAirport())
return p.getKm() * 2;
return p.getKm();
}
void write(ostream& out);
};

void CompaniePreComanda::write(ostream& out) {


out << "Compania are un numar de " << precomenzi.size() << " precomenzi\n";
for(int i = 0; i < precomenzi.size(); i++) {
out << "Comanda cu numarul " << i + 1 << ".\n";
precomenzi[i].afisPrecomanda(out);
out << "Cu costul total de " << getKm(precomenzi[i]) * tarif << " lei. \n";
}
}

#endif //COLOCVIU2018TAXI_COMPANIEPRECOMANDA_H

//
// Created by Alex on 5/27/2019.
//

#ifndef COLOCVIU2018TAXI_COMPANIECONTROLSIDRIVER_H
#define COLOCVIU2018TAXI_COMPANIECONTROLSIDRIVER_H

#include <vector>
#include "Companie.h"

class CostControl {
string sursa;
string destinatie;
double km;
public:
CostControl(string s, string d, double k) : sursa(s), destinatie(d), km(k) {};
double getCost(int tarif){
return km * tarif;
}
void afisCostControl(ostream& out) {
out << "Sursa: " << sursa << '\n';
out << "Destinatie: " << destinatie << '\n';
out << "Numar km: " << km << '\n';
}
};

class DesignatedDriver {
string sofer1, sofer2, cod1, cod2;
public:
DesignatedDriver(const string &sofer1, const string &sofer2, const string
&cod1, const string &cod2) : sofer1(
sofer1), sofer2(sofer2), cod1(cod1), cod2(cod2) {};
void afisDesignatedDriver(ostream& out) {
out << "Sofer1: " << sofer1 << '\n';
out << "Sofer2: " << sofer2 << '\n';
out << "Cod1: " << cod1 << '\n';
out << "Cod2: " << cod2 << '\n';
}

};

class CompanieControlSiDriver : public Companie{


int tarifDesignatedDriver;
vector <CostControl> costControl;
vector <DesignatedDriver> designatedDriver;
static int costControlCount;
static int designatedDriverCount;
public:
CompanieControlSiDriver(string den, int cod, double tar, int des) :
Companie(den, cod, tar), tarifDesignatedDriver(des) {};
double addCostControl(string sursa, string destinatie, double km){
costControlCount++;
costControl.push_back(CostControl(sursa, destinatie, km));
return costControl[costControl.size() - 1].getCost(tarif);
}

void addDesignatedDriver(string sofer1, string sofer2, string cod1, string


cod2) {
designatedDriverCount++;
designatedDriver.push_back(DesignatedDriver(sofer1, sofer2, cod1, cod2));
}

void write(ostream& out) {


out << "Compania are un numar de " << costControlCount << " comenzi cu
verificare cost control.\n";
for (int i = 0; i < costControl.size(); i++) {
out << "Verificarea cu numarul " << i + 1 << ":\n";
costControl[i].afisCostControl(out);
out << "Costul calatoriei: " << costControl[i].getCost(tarif) << '\n';
}

out << "Compania are un numar de " << designatedDriverCount << " comenzi cu
Designated Driver. \n";
for (int i = 0; i < designatedDriver.size(); i++) {
out << "Comanda cu numarul " << i + 1 << '\n';
designatedDriver[i].afisDesignatedDriver(out);
}
}

static int getCostControlCount(){


return costControlCount;
}

static int getDesignatedDriverCount(){


return designatedDriverCount;
}

};

int CompanieControlSiDriver::costControlCount = 0;
int CompanieControlSiDriver::designatedDriverCount = 0;

#endif //COLOCVIU2018TAXI_COMPANIECONTROLSIDRIVER_H

//
// Created by Alex on 5/27/2019.
//

#ifndef COLOCVIU2018TAXI_COMPANIERENTLEASING_H
#define COLOCVIU2018TAXI_COMPANIERENTLEASING_H

#include <vector>
#include <cstdlib>
#include "Companie.h"

class RentACar{
string nume, data1, ora1, locPreluare, data2, ora2, locPredare;
int tarif;
public:
RentACar(const string &nume, const string &data1, const string &ora1, const
string &locPreluare,
const string &data2, const string &ora2, const string &locPredare,
double tarif) : nume(nume),

data1(data1),
ora1(ora1), locPreluare(
locPreluare), data2(data2), ora2(ora2), locPredare(locPredare)
{
srand(NULL);
tarif = (rand() % 10) + 10;
}
};

class CompanieRentLeasing : public Companie{


vector <RentACar> rentACarOrders;

};

#endif //COLOCVIU2018TAXI_COMPANIERENTLEASING_H

#include <iostream>
#include <algorithm>
#include "cmake-build-debug/CompaniePreComanda.h"
#include "CompanieControlSiDriver.h"

int main() {
CompaniePreComanda comp("Taxi Alex", 29432, 3.23);
comp.solicitaPrecomanda(Precomanda("alex", "27.05.2019", "23:30", "Slatina",
"buc", 180, false));
comp.solicitaPrecomanda(Precomanda("marius", "29.05.2019", "18:42", "Rahova",
"Centru", 5, false));
//cout << comp;
vector < Companie* > c;
c.push_back(&comp);

CompanieControlSiDriver driver("PSD", 19382, 3.50, 15);


driver.addCostControl("Alexandria", "Bucuresti", 75.6);
driver.addCostControl("Rahova", "Victoriei", 6.3);
driver.addDesignatedDriver("Liviu", "Dragnea", "391k2", "dsj382");

c.push_back(&driver);
//cout << *c[1];

cout << CompanieControlSiDriver::getCostControlCount() << " " <<


CompanieControlSiDriver::getDesignatedDriverCount() << '\n';

sort(c.begin(), c.end());
cout << *c[0];

return 0;
}

//
// Created by Alex on 5/27/2019.
//
#ifndef COLOCVIU2018TAXI_COMPANIE_H
#define COLOCVIU2018TAXI_COMPANIE_H

#include <array>
#include <iostream>

using namespace std;

class Companie {
protected:
string denumire;
int codFiscal;
double tarif;
int profit;
public:
Companie(string den, int cod, double tar);
Companie(){};
virtual double calcTarif(){};
virtual void write(ostream& out) = 0;
bool operator<(const Companie& other){
return profit < other.profit;
}
friend ostream& operator<<(ostream& out, Companie& c);
};

Companie::Companie(string den, int cod, double tar) {


denumire = den;
codFiscal = cod;
tarif = tar;
profit = 0;
}

ostream& operator<<(ostream& out, Companie& c) {


out << "Numele companiei: " << c.denumire << " ||| ";
out << "Codul fiscal al companiei: " << c.codFiscal << " ||| ";
out << "Tariful companiei: " << c.tarif << " ||| \n";
c.write(out);
return out;
}

#endif //COLOCVIU2018TAXI_COMPANIE_H

//
// Created by Alex on 5/27/2019.
//

#ifndef COLOCVIU2018TAXI_COMPANIEPRECOMANDA_H
#define COLOCVIU2018TAXI_COMPANIEPRECOMANDA_H

#include <vector>
#include "../Companie.h"

class Precomanda {
private:
string nume, data, ora, sursa, destinatie;
double km;
bool aeroport;
public:
Precomanda(string n, string d, string o, string s, string dest, double k, bool
a)
: nume(n), data(d), ora(o), sursa(s), destinatie(dest), km(k),
aeroport(a) {};
void afisPrecomanda(ostream& os){
os << "Numele clientului: " << nume << '\n';
os << "Data si ora precomenzii: " << data << " " << ora << '\n';
os << "Locul de preluare: " << sursa << '\n';
os << "Destinatia: " << destinatie << '\n';
}
int getKm(){
return km;
}
bool toAirport(){
return aeroport;
}
};

class CompaniePreComanda : public Companie{


vector <Precomanda> precomenzi;
public:
CompaniePreComanda(string den, int cod, double tar) : Companie(den, cod, tar)
{};
void solicitaPrecomanda(Precomanda p){
precomenzi.push_back(p);
profit += p.getKm() * tarif;
}
double getKm(Precomanda p){
if(p.toAirport())
return p.getKm() * 2;
return p.getKm();
}
void write(ostream& out);
};

void CompaniePreComanda::write(ostream& out) {


out << "Compania are un numar de " << precomenzi.size() << " precomenzi\n";
for(int i = 0; i < precomenzi.size(); i++) {
out << "Comanda cu numarul " << i + 1 << ".\n";
precomenzi[i].afisPrecomanda(out);
out << "Cu costul total de " << getKm(precomenzi[i]) * tarif << " lei. \n";
}
}

#endif //COLOCVIU2018TAXI_COMPANIEPRECOMANDA_H

//
// Created by Alex on 5/27/2019.
//

#ifndef COLOCVIU2018TAXI_COMPANIECONTROLSIDRIVER_H
#define COLOCVIU2018TAXI_COMPANIECONTROLSIDRIVER_H

#include <vector>
#include "Companie.h"

class CostControl {
string sursa;
string destinatie;
double km;
public:
CostControl(string s, string d, double k) : sursa(s), destinatie(d), km(k) {};
double getCost(int tarif){
return km * tarif;
}
void afisCostControl(ostream& out) {
out << "Sursa: " << sursa << '\n';
out << "Destinatie: " << destinatie << '\n';
out << "Numar km: " << km << '\n';
}
};

class DesignatedDriver {
string sofer1, sofer2, cod1, cod2;
public:
DesignatedDriver(const string &sofer1, const string &sofer2, const string
&cod1, const string &cod2) : sofer1(
sofer1), sofer2(sofer2), cod1(cod1), cod2(cod2) {};
void afisDesignatedDriver(ostream& out) {
out << "Sofer1: " << sofer1 << '\n';
out << "Sofer2: " << sofer2 << '\n';
out << "Cod1: " << cod1 << '\n';
out << "Cod2: " << cod2 << '\n';
}

};

class CompanieControlSiDriver : public Companie{


int tarifDesignatedDriver;
vector <CostControl> costControl;
vector <DesignatedDriver> designatedDriver;
static int costControlCount;
static int designatedDriverCount;
public:
CompanieControlSiDriver(string den, int cod, double tar, int des) :
Companie(den, cod, tar), tarifDesignatedDriver(des) {};
double addCostControl(string sursa, string destinatie, double km){
costControlCount++;
costControl.push_back(CostControl(sursa, destinatie, km));
return costControl[costControl.size() - 1].getCost(tarif);
}

void addDesignatedDriver(string sofer1, string sofer2, string cod1, string


cod2) {
designatedDriverCount++;
designatedDriver.push_back(DesignatedDriver(sofer1, sofer2, cod1, cod2));
}
void write(ostream& out) {
out << "Compania are un numar de " << costControlCount << " comenzi cu
verificare cost control.\n";
for (int i = 0; i < costControl.size(); i++) {
out << "Verificarea cu numarul " << i + 1 << ":\n";
costControl[i].afisCostControl(out);
out << "Costul calatoriei: " << costControl[i].getCost(tarif) << '\n';
}

out << "Compania are un numar de " << designatedDriverCount << " comenzi cu
Designated Driver. \n";
for (int i = 0; i < designatedDriver.size(); i++) {
out << "Comanda cu numarul " << i + 1 << '\n';
designatedDriver[i].afisDesignatedDriver(out);
}
}

static int getCostControlCount(){


return costControlCount;
}

static int getDesignatedDriverCount(){


return designatedDriverCount;
}

};

int CompanieControlSiDriver::costControlCount = 0;
int CompanieControlSiDriver::designatedDriverCount = 0;

#endif //COLOCVIU2018TAXI_COMPANIECONTROLSIDRIVER_H

//
// Created by Alex on 5/27/2019.
//

#ifndef COLOCVIU2018TAXI_COMPANIERENTLEASING_H
#define COLOCVIU2018TAXI_COMPANIERENTLEASING_H

#include <vector>
#include <cstdlib>
#include "Companie.h"

class RentACar{
string nume, data1, ora1, locPreluare, data2, ora2, locPredare;
int tarif;
public:
RentACar(const string &nume, const string &data1, const string &ora1, const
string &locPreluare,
const string &data2, const string &ora2, const string &locPredare,
double tarif) : nume(nume),

data1(data1),

ora1(ora1), locPreluare(
locPreluare), data2(data2), ora2(ora2), locPredare(locPredare)
{
srand(NULL);
tarif = (rand() % 10) + 10;
}
};

class CompanieRentLeasing : public Companie{


vector <RentACar> rentACarOrders;

};

#endif //COLOCVIU2018TAXI_COMPANIERENTLEASING_H

Вам также может понравиться