Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Adam Staworowski
- //213B 2016/2017
- //Komis samochodowy
- #include "stdafx.h"
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <ctime>
- #include <string>
- using namespace std;
- class Vehicle {
- private:
- unsigned int price;
- bool damaged;
- public:
- friend class Workshop;
- virtual void print() = 0;
- virtual void printPrice() = 0;
- virtual void initialization() = 0;
- virtual string getMake() = 0;
- virtual string getEngine() = 0;
- virtual unsigned int getPrice() = 0;
- virtual unsigned int getYear() = 0;
- virtual bool getDamaged() = 0;
- virtual void setMake(string m) = 0;
- virtual void setEngine(string e) = 0;
- virtual void setPrice(unsigned int p) = 0;
- virtual void setYear(unsigned int y) = 0;
- virtual void setDamaged(bool d) = 0;
- };
- class Car :public Vehicle, public Engine
- {
- private:
- string make;
- string engine;
- unsigned int price;
- unsigned int year;
- bool damaged;
- public:
- friend class Workshop;
- Car();
- Car(string m, string e, unsigned int p, unsigned int y, bool d, unsigned int w);
- Car(const Car& car);
- ~Car();
- void setMake(string m);
- void setEngine(string e);
- void setPrice(unsigned int p);
- void setYear(unsigned int y);
- void setDamaged(bool d);
- string getMake();
- string getEngine();
- unsigned int getPrice();
- unsigned int getYear();
- bool getDamaged();
- friend ostream & operator<<(ostream& out, const Car& car);
- friend istream & operator >> (istream& in, Car& car);
- Car operator()(const Car& car);
- void operator=(const Car& Car);
- void operator->();
- friend int operator+(const Car& car);
- friend int operator-(const Car& car);
- void print();
- void printPrice();
- void initialization();
- };
- class Truck :public Car {
- private:
- unsigned int capacity;
- unsigned int totalWeight;
- public:
- friend class Workshop;
- Truck() :capacity(0), totalWeight(0), Car(){}
- ~Truck();
- void setCapacity(unsigned int c);
- void setTotalWeight(unsigned int tw);
- unsigned int getCapacity();
- unsigned int getTotalWeight();
- };
- class Motorcycle : public Car{
- private:
- int cubicCapacity;
- int HP;
- public:
- friend class Workshop;
- Motorcycle() :cubicCapacity(0), HP(0), Car(){}
- ~Motorcycle();
- void setCubicCapacity(unsigned int cC);
- void setHP(int Hp);
- unsigned int getCubicCapacity();
- unsigned int getHP();
- };
- class Engine {
- private:
- string type;
- unsigned int hp;
- unsigned int fuelAmmount;
- public:
- Engine();
- Engine(string t, unsigned int hP, unsigned int fA);
- ~Engine();
- void fuelUp();
- void startEngine();
- };
- class Client {
- private:
- string name;
- int age;
- unsigned int carAmmount;
- public:
- friend class Workshop;
- Client();
- Client(string n, int a, unsigned int cA);
- ~Client();
- Vehicle *ownedVehicle[5];
- void setName(string n);
- void setAge(int i);
- string getName();
- int getAge();
- void print();
- void initialization();
- };
- class Workshop {
- private:
- unsigned int vehicleCount;
- unsigned int clientCount;
- int balance;
- Vehicle **myVehicle;
- Client **myClient;
- static Workshop *singleton;
- public:
- class Mechanic {
- private:
- string name;
- int age;
- public:
- Mechanic();
- Mechanic(string n, int a);
- ~Mechanic();
- void repairVehicle(Vehicle*& vehicle);
- };
- static Workshop *getInstance() {
- if (singleton == NULL) {
- singleton = new Workshop;
- }
- return singleton;
- }
- Workshop();
- Workshop(unsigned int cC, unsigned int clC, int b);
- ~Workshop();
- void viewClients();
- void presentCars();
- void addClient();
- void addCar();
- void sellCar();
- void buyCar();
- void repairCar();
- };
- class MemoryManagement {
- public:
- static void dynamicAllocation(Car*& car);
- static void initialization(Car* car);
- static void print(Car* car);
- static void remove(Car*& car);
- static void dynamicAllocation(Client*& client);
- static void initialization(Client* client);
- static void print(Client* client);
- static void remove(Client*& client);
- static void dynamicAllocation(Car*& car, int size);
- static void initialization(Car* car, int size);
- static void print(Car* car, int size);
- static void remove(Car*& car, int size);
- static void dynamicAllocation(Client*& client, int size);
- static void initialization(Client* client, int size);
- static void print(Client* client, int size);
- static void remove(Client*& car, int size);
- static void dynamicAllocation(Vehicle**& vehicle, int size);
- static void initialization(Vehicle** vehicle, int size);
- static void print(Vehicle** vehicle, int size);
- static void remove(Vehicle** vehicle, int size);
- static void dynamicAllocation(Client**& client, int size);
- static void initialization(Client**& client, int size);
- static void print(Client** client, int size);
- static void remove(Client**& client, int size);
- static void addAtTheEnd(Car*& car, int size);
- static void addAtTheEnd(Client*& client, int size);
- static void removeFromTheEnd(Car*& car, int size);
- static void removeFromTheEnd(Client*& client, int size);
- static void addPtrToArray(Vehicle**& vehicle, int size);
- static void addPtrToArray(Client**& client, int size);
- static void removePtrFromTheEnd(Car**& car, int size);
- static void removePtrFromTheEnd(Client**& client, int size);
- static void addObjectAtNth(Car*& car, int size, int target);
- static void addObjectAtNth(Client*& car, int size, int target);
- static void removeObjFromNth(Car*& car, int size, int target);
- static void removeObjFromNth(Client*& client, int size, int target);
- static void addPtrToArray(Vehicle**& vehicle, int size, int target);
- static void addPtrToArray(Client**& client, int size, int target);
- static void removePtrFromNth(Vehicle**& vehicle, int size, int target);
- static void removePtrFromNth(Client**& client, int size, int target);
- };
- string make[5] = { "volkswagen", "audi", "bmw", "opel", "mercedes" };
- string engine[2] = { "diesel", "petrol" };
- int main()
- {
- Workshop *WorkshopPtr = NULL;
- int czas;
- czas = time(NULL);
- srand(czas);
- WorkshopPtr = new Workshop;
- WorkshopPtr->addCar();
- int choice = 0;
- cout << "Komis samochodowy v0.5" << endl;
- cout << "wybierz jedna z dostepnych operacji" << endl;
- do {
- cout << "1. sprzedaj auto z naszej oferty" << endl;
- cout << "2. kup auto od klienta" << endl;
- cout << "3. wyswietl nasza oferte" << endl;
- cout << "4. wyswietl liste kontrahentow " << endl;
- cout << "5. napraw pojazd" << endl;
- cout << "0. zakoncz" << endl;
- cin >> choice;
- switch (choice) {
- case 1: {
- WorkshopPtr->sellCar();
- break;
- }
- case 2: {
- WorkshopPtr->buyCar();
- break;
- }
- case 3: {
- WorkshopPtr->presentCars();
- break;
- }
- case 4: {
- WorkshopPtr->viewClients();
- break;
- }
- case 5: {
- WorkshopPtr->repairCar();
- break;
- }
- }
- } while (choice != 0);
- delete(WorkshopPtr);
- return 0;
- }
- void MemoryManagement::dynamicAllocation(Car*& car) {
- car = new Car;
- }
- void MemoryManagement::initialization(Car* car) {
- /*
- string make[5]{ "volkswagen", "audi", "bmw", "opel", "mercedes" };
- string engine[2]{ "diesel", "petrol" };
- string randomMake = make[(rand() % 4)];
- string randomEngine = engine[rand() % 2];
- unsigned int price = 1000 * (5 + rand() % 27);
- unsigned int year = 1999 + rand() % 11;
- bool damaged = rand() % 2;
- car->setMake(randomMake);
- car->setEngine(randomEngine);
- car->setPrice(price);
- car->setYear(year);
- car->setDamaged(damaged);
- */
- car->initialization();
- }
- void MemoryManagement::print(Car* car) {
- car->print();
- }
- void MemoryManagement::remove(Car*& car) {
- delete car;
- car = NULL;
- }
- void MemoryManagement::dynamicAllocation(Client*& client) {
- client = new Client;
- }
- void MemoryManagement::initialization(Client* client) {
- /*
- string engine[2]{ "diesel", "petrol" };
- string randomEngine = engine[(rand() % 1)];
- unsigned int price = 1000 * (5 + rand() % 27);
- unsigned int priceRange = 1000 * (3 + rand() % 4);
- bool damaged = rand() % 2;
- client->setEngine(randomEngine);
- client->setPrice(price);
- client->setPriceRange(priceRange);
- client->setDamaged(damaged);
- */
- client->initialization();
- }
- void MemoryManagement::print(Client* client) {
- client->print();
- }
- void MemoryManagement::remove(Client*& client) {
- delete client;
- client = NULL;
- }
- void MemoryManagement::dynamicAllocation(Car*& car, int size) {
- car = new Car[size];
- }
- void MemoryManagement::initialization(Car* car, int size) {
- for (int i = 0; i < size; i++) {
- /*
- string make[5]{ "volkswagen", "audi", "bmw", "opel", "mercedes" };
- string engine[2]{ "diesel", "petrol" };
- string randomMake = make[(rand() % 4)];
- string randomEngine = engine[rand() % 2];
- unsigned int price = 1000 * (5 + rand() % 27);
- unsigned int year = 1999 + rand() % 11;
- bool damaged = rand() % 2;
- car[i].setMake(randomMake);
- car[i].setEngine(randomEngine);
- car[i].setPrice(price);
- car[i].setYear(year);
- car[i].setDamaged(damaged);
- */
- car[i].initialization();
- }
- }
- void MemoryManagement::print(Car* car, int size) {
- for (int i = 0; i<size; i++) {
- car[i].print();
- }
- }
- void MemoryManagement::remove(Car*& car, int size) {
- delete[] car;
- car = NULL;
- }
- void MemoryManagement::dynamicAllocation(Client*& client, int size) {
- client = new Client[size];
- }
- void MemoryManagement::initialization(Client* client, int size) {
- for (int i = 0; i < size; i++) {
- /*
- string engine[2]{ "diesel", "petrol" };
- string randomEngine = engine[(rand() % 1)];
- unsigned int price = 1000 * (5 + rand() % 27);
- unsigned int priceRange = 1000 * (3 + rand() % 4);
- bool damaged = rand() % 2;
- client[i].setEngine(randomEngine);
- client[i].setPrice(price);
- client[i].setPriceRange(priceRange);
- client[i].setDamaged(damaged);
- */
- client[i].initialization();
- }
- }
- void MemoryManagement::print(Client* client, int size) {
- for (int i = 0; i<size; i++) {
- client[i].print();
- }
- }
- void MemoryManagement::remove(Client*& client, int size) {
- delete[] client;
- client = NULL;
- }
- void MemoryManagement::dynamicAllocation(Vehicle**&vehicle, int size) {
- vehicle = new Vehicle*[size];
- for (int i = 0; i< size; i++) {
- vehicle[i] = new Car;
- }
- }
- void MemoryManagement::initialization(Vehicle**vehicle, int size) {
- for (int i = 0; i < size; i++) {
- /*
- string make[5]{ "volkswagen", "audi", "bmw", "opel", "mercedes" };
- string engine[2]{ "diesel", "petrol" };
- string randomMake = make[(rand() % 4)];
- string randomEngine = engine[rand() % 2];
- unsigned int price = 1000 * (5 + rand() % 27);
- unsigned int year = 1999 + rand() % 11;
- bool damaged = rand() % 2;
- car[i]->setMake(randomMake);
- car[i]->setEngine(randomEngine);
- car[i]->setPrice(price);
- car[i]->setYear(year);
- car[i]->setDamaged(damaged);
- */
- vehicle[i]->initialization();
- }
- }
- void MemoryManagement::print(Vehicle**vehicle, int size) {
- for (int i = 0; i<size; i++) {
- vehicle[i]->print();
- }
- }
- void MemoryManagement::remove(Vehicle**vehicle, int size) {
- for (int i = 0; i<size; i++)
- delete vehicle[i];
- delete[] vehicle;
- }
- void MemoryManagement::dynamicAllocation(Client**&client, int size) {
- client = new Client*[size];
- for (int i = 0; i< size; i++) {
- client[i] = new Client;
- }
- }
- void MemoryManagement::initialization(Client**&client, int size) {
- for (int i = 0; i < size; i++) {
- /*
- string engine[2]{ "diesel", "petrol" };
- string randomEngine = engine[(rand() % 1)];
- unsigned int price = 1000 * (5 + rand() % 27);
- unsigned int priceRange = 1000 * (3 + rand() % 4);
- bool damaged = rand() % 2;
- client[i]->setEngine(randomEngine);
- client[i]->setDamaged(damaged);
- */
- client[i]->initialization();
- }
- }
- void MemoryManagement::print(Client**client, int size) {
- for (int i = 0; i<size; i++) {
- client[i]->print();
- }
- }
- void MemoryManagement::remove(Client**& client, int size) {
- for (int i = 0; i<size; i++)
- delete client[i];
- delete[] client;
- }
- //1 dodaj obiekt na koncu dynamicznej tablicy obiektow w z czasie wykonania
- void MemoryManagement::addAtTheEnd(Car*& car, int size) {
- int n = size;
- Car* temp = NULL;
- temp = new Car[size + 1];
- for (int i = 0; i < size; i++) {
- temp[i] = car[i];
- }
- delete[] car;
- string make[5] = { "volkswagen", "audi", "bmw", "opel", "mercedes" };
- string engine[2] = { "diesel", "petrol" };
- string randomMake = make[(rand() % 4)];
- string randomEngine = engine[rand() % 2];
- unsigned int price = 1000 * (5 + rand() % 27);
- unsigned int year = 1999 + rand() % 11;
- bool damaged = rand() % 2;
- temp[n].setMake(randomMake);
- temp[n].setEngine(randomEngine);
- temp[n].setPrice(price);
- temp[n].setYear(year);
- temp[n].setDamaged(damaged);
- car = temp;
- }
- void MemoryManagement::addAtTheEnd(Client*&client, int size) {
- int n = size;
- Client* temp = NULL;
- temp = new Client[size + 1];
- for (int i = 0; i < size; i++) {
- temp[i] = client[i];
- }
- delete[] client;
- temp[n].initialization();
- client = temp;
- }
- //2 usun obiekt z konca tablicy
- void MemoryManagement::removeFromTheEnd(Car*& car, int size) {
- Car* temp = NULL;
- temp = new Car[size - 1];
- for (int i = 0; i < size - 1; i++) {
- temp[i] = car[i];
- }
- car = temp;
- }
- void MemoryManagement::removeFromTheEnd(Client*& client, int size) {
- Client* temp = NULL;
- temp = new Client[size - 1];
- for (int i = 0; i < size - 1; i++) {
- temp[i] = client[i];
- }
- client = temp;
- }
- //3 dodaj wskaznik na obiekt do tablicy
- void MemoryManagement::addPtrToArray(Vehicle**& vehicle, int size) {
- int n = size;
- Vehicle** temp;
- temp = new Vehicle*[size + 1];
- for (int i = 0; i< size + 1; i++) {
- temp[i] = new Car;
- }
- for (int i = 0; i < size; i++) {
- temp[i] = vehicle[i];
- }
- string make[5] = { "volkswagen", "audi", "bmw", "opel", "mercedes" };
- string engine[2] = { "diesel", "petrol" };
- string randomMake = make[(rand() % 4)];
- string randomEngine = engine[rand() % 2];
- unsigned int price = 1000 * (5 + rand() % 27);
- unsigned int year = 1999 + rand() % 11;
- bool damaged = rand() % 2;
- temp[n]->setMake(randomMake);
- temp[n]->setEngine(randomEngine);
- temp[n]->setPrice(price);
- temp[n]->setYear(year);
- temp[n]->setDamaged(damaged);
- vehicle = temp;
- }
- void MemoryManagement::addPtrToArray(Client**& client, int size) {
- int n = size;
- Client** temp;
- temp = new Client*[size + 1];
- for (int i = 0; i< size + 1; i++) {
- temp[i] = new Client;
- }
- for (int i = 0; i < size; i++) {
- temp[i] = client[i];
- }
- temp[n]->initialization();
- client = temp;
- }
- //4 usun wskaznik na obiekt z ostatniego miejsca tablicy wskaznikow
- void MemoryManagement::removePtrFromTheEnd(Car**& car, int size) {
- int n = size;
- Car** temp;
- temp = new Car*[size - 1];
- for (int i = 0; i< size - 1; i++) {
- temp[i] = new Car;
- }
- for (int i = 0; i < size - 1; i++) {
- temp[i] = car[i];
- }
- car = temp;
- }
- void MemoryManagement::removePtrFromTheEnd(Client**& client, int size) {
- int n = size;
- Client** temp;
- temp = new Client*[size - 1];
- for (int i = 0; i< size - 1; i++) {
- temp[i] = new Client;
- }
- for (int i = 0; i < size - 1; i++) {
- temp[i] = client[i];
- }
- client = temp;
- }
- //5 wstaw obiekt do tablicy obiektow na wskazane misjce
- void MemoryManagement::addObjectAtNth(Car*& car, int size, int target) {
- if (target > size) {
- cout << "cel znajduje sie poza tablica, nie dodac";
- return;
- }
- Car* temp = NULL;
- temp = new Car[size + 1];
- for (int i = 0; i < target - 1; i++) {
- temp[i] = car[i];
- }
- string make[5] = { "volkswagen", "audi", "bmw", "opel", "mercedes" };
- string engine[2] = { "diesel", "petrol" };
- string randomMake = make[(rand() % 4)];
- string randomEngine = engine[rand() % 2];
- unsigned int price = 1000 * (5 + rand() % 27);
- unsigned int year = 1999 + rand() % 11;
- bool damaged = rand() % 2;
- temp[target - 1].setMake(randomMake);
- temp[target - 1].setEngine(randomEngine);
- temp[target - 1].setPrice(price);
- temp[target - 1].setYear(year);
- temp[target - 1].setDamaged(damaged);
- for (int j = target; j < size + 1; j++) {
- temp[j] = car[j - 1];
- }
- delete[]car;
- car = temp;
- }
- void MemoryManagement::addObjectAtNth(Client*& client, int size, int target) {
- if (target > size) {
- cout << "cel znajduje sie poza tablica, nie dodac";
- return;
- }
- Client* temp = NULL;
- temp = new Client[size + 1];
- for (int i = 0; i < target - 1; i++) {
- temp[i] = client[i];
- }
- temp[target - 1].initialization();
- for (int j = target; j < size + 1; j++) {
- temp[j] = client[j - 1];
- }
- delete[]client;
- client = temp;
- }
- //6 usun obiekt ze wskazanego miejsca
- void MemoryManagement::removeObjFromNth(Car*& car, int size, int target) {
- if (target>size) {
- cout << "Nie mozna usunac; element znajduej sie poza tablcia" << endl;
- return;
- }
- Car* temp = NULL;
- temp = new Car[size - 1];
- for (int i = 0; i < target - 1; i++) {
- temp[i] = car[i];
- }
- for (int j = target; j < size; j++) {
- temp[j - 1] = car[j];
- }
- delete[] car;
- car = temp;
- }
- void MemoryManagement::removeObjFromNth(Client*& client, int size, int target) {
- if (target>size) {
- cout << "Nie mozna usunac; element znajduej sie poza tablcia" << endl;
- return;
- }
- Client* temp = NULL;
- temp = new Client[size - 1];
- for (int i = 0; i < target - 1; i++) {
- temp[i] = client[i];
- }
- for (int j = target; j < size; j++) {
- temp[j - 1] = client[j];
- }
- delete[] client;
- client = temp;
- }
- //7 wstaw wskznik na obiekt dla wskazanego miejsca w tablicy wskaznkow na obiekt
- void MemoryManagement::addPtrToArray(Vehicle**& vehicle, int size, int target) {
- if (target > size) {
- cout << "cel znajduje sie poza tablica, nie mozna usunac";
- return;
- }
- Vehicle** temp = NULL;
- temp = new Vehicle*[size + 1];
- for (int i = 0; i < target - 1; i++) {
- temp[i] = vehicle[i];
- }
- string make[5] = { "volkswagen", "audi", "bmw", "opel", "mercedes" };
- string engine[2] = { "diesel", "petrol" };
- string randomMake = make[(rand() % 4)];
- string randomEngine = engine[rand() % 2];
- unsigned int price = 1000 * (5 + rand() % 27);
- unsigned int year = 1999 + rand() % 11;
- bool damaged = rand() % 2;
- temp[target - 1]->setMake(randomMake);
- temp[target - 1]->setEngine(randomEngine);
- temp[target - 1]->setPrice(price);
- temp[target - 1]->setYear(year);
- temp[target - 1]->setDamaged(damaged);
- for (int j = target; j < size + 1; j++) {
- temp[j] = vehicle[j - 1];
- }
- delete[]vehicle;
- vehicle = temp;
- }
- void MemoryManagement::addPtrToArray(Client**& client, int size, int target) {
- if (target > size) {
- cout << "cel znajduje sie poza tablica, nie mozna usunac";
- return;
- }
- Client** temp = NULL;
- temp = new Client*[size + 1];
- for (int i = 0; i < target - 1; i++) {
- temp[i] = client[i];
- }
- temp[target - 1]->initialization();
- for (int j = target; j < size + 1; j++) {
- temp[j] = client[j - 1];
- }
- delete[]client;
- client = temp;
- }
- //8 usun wskaznik na obiekt ze wskazanego miejsca w tablicy wskaznikow na obiekt
- void MemoryManagement::removePtrFromNth(Vehicle**& vehicle, int size, int target) {
- if (target>size) {
- cout << "Nie mozna usunac; element znajduej sie poza tablcia" << endl;
- return;
- }
- int n = size;
- Vehicle** temp = NULL;
- temp = new Vehicle*[size - 1];
- for (int i = 0; i < target - 1; i++) {
- temp[i] = vehicle[i];
- }
- for (int j = target; j < size; j++) {
- temp[j - 1] = vehicle[j];
- }
- delete[] vehicle;
- vehicle = temp;
- }
- void MemoryManagement::removePtrFromNth(Client**& client, int size, int target) {
- if (target>size) {
- cout << "Nie mozna usunac; element znajduej sie poza tablcia" << endl;
- return;
- }
- int n = size;
- Client** temp = NULL;
- temp = new Client*[size - 1];
- for (int i = 0; i < target - 1; i++) {
- temp[i] = client[i];
- }
- for (int j = target; j < size; j++) {
- temp[j - 1] = client[j];
- }
- delete[] client;
- client = temp;
- }
- Car::Car() {
- make = "empty";
- engine = "empty";
- price = 0;
- year = 0;
- damaged = 0;
- }
- Car::Car(string m, string e, unsigned int p, unsigned int y, bool d, unsigned int w) {
- make = m;
- engine = e;
- price = p;
- year = y;
- damaged = d;
- }
- Car::Car(const Car& car) {
- make = car.make;
- engine = car.engine;
- price = car.price;
- year = car.year;
- damaged = car.damaged;
- };
- Car::~Car() {
- }
- Truck::~Truck() {
- }
- Motorcycle::~Motorcycle() {
- }
- void Motorcycle::setCubicCapacity(unsigned int cC) {
- cubicCapacity = cC;
- }
- void Motorcycle::setHP(int HPp) {
- HP = HPp;
- }
- unsigned int Motorcycle::getCubicCapacity() {
- return cubicCapacity;
- }
- unsigned int Motorcycle::getHP() {
- return cubicCapacity;
- }
- Client::Client() {
- name = "empty";
- age = 0;
- carAmmount = 0;
- }
- Client::Client(string n, int a, unsigned int cA) {
- name = n;
- age = a;
- carAmmount = cA;
- }
- Client::~Client() {
- }
- Workshop::Mechanic::Mechanic() {
- name = "empty";
- age = 0;
- }
- Workshop::Mechanic::Mechanic(string n, int a) {
- name = n;
- age = a;
- }
- Workshop::Mechanic::~Mechanic() {
- }
- void Workshop::Mechanic::repairVehicle(Vehicle*&vehicle) {
- if (vehicle->damaged == 0) {
- cout << "pojazd nie jest uszkodzony!" << endl;
- }
- else {
- cout << "czy chcesz naprawic pojazd?" << endl;
- cout << "0.nie 1.tak" << endl;
- bool choice;
- cin >> choice;
- if (choice == 0) return;
- else {
- cout << "naprawa bedzie kosztowac" << 1000 << endl;
- cout << "czy chcesz dokonac naprawy?" << endl;
- cout << "0.nie 1.tak" << endl;
- bool choicee;
- cin >> choicee;
- if (choicee == 0)return;
- else {
- vehicle->setDamaged(0);
- }
- }
- }
- }
- Workshop::Workshop() {
- vehicleCount = 0;
- clientCount = 0;
- balance = 50000;
- }
- Workshop::Workshop(unsigned int cC, unsigned int clC, int b) {
- vehicleCount = cC;
- clientCount = clC;
- balance = b;
- }
- Workshop::~Workshop() {
- }
- /*
- Car::Engine::Engine() {
- string type = "empty";
- unsigned int hp = 0;
- unsigned int fuelAmmount = 0;
- }
- Car::Engine::Engine(string t, unsigned int hP, unsigned int fA) {
- string type = t;
- unsigned int hp = hP;
- unsigned int fuelAmmount = fA;
- }
- Car::Engine::~Engine() {
- }
- */
- ostream& operator<<(ostream& out, const Car& car) {
- out << car.make << "\t" << car.price << "\t" << car.year << "\t" << car.engine << "\t" << car.damaged;
- return out;
- }
- istream& operator >> (istream& in, Car& car) {
- cout << "marka, cena, rok produkcji, rodzaj silnika, uszkodzony?" << endl;
- in >> car.make;
- in >> car.price;
- in >> car.year;
- in >> car.engine;
- in >> car.damaged;
- return in;
- }
- Car Car::operator()(const Car& car) {
- Car carb;
- make = car.make;
- engine = car.engine;
- price = car.price;
- year = car.year;
- damaged = car.damaged;
- return car;
- }
- void Car::operator=(const Car& car) {
- make = car.make;
- engine = car.engine;
- price = car.price;
- year = car.year;
- damaged = car.damaged;
- }
- void Car::operator->() {
- //TODO
- }
- int operator+(const Car& car) {
- int suma = 0;
- suma += car.price;
- return suma;
- }
- int operator-(const Car& car) {
- int roznica = 0;
- roznica -= car.price;
- return roznica;
- }
- void Car::setMake(string m) {
- make = m;
- }
- void Car::setEngine(string m) {
- engine = m;
- }
- void Car::setPrice(unsigned int p) {
- price = p;
- }
- void Car::setYear(unsigned int y) {
- year = y;
- }
- void Car::setDamaged(bool d) {
- damaged = d;
- }
- string Car::getMake() {
- return make;
- }
- string Car::getEngine() {
- return engine;
- }
- unsigned int Car::getPrice() {
- return price;
- }
- unsigned int Car::getYear() {
- return year;
- }
- bool Car::getDamaged() {
- return damaged;
- }
- void Truck::setCapacity(unsigned int c) {
- capacity = c;
- }
- void Truck::setTotalWeight(unsigned int tw) {
- totalWeight = tw;
- }
- unsigned int Truck::getCapacity() {
- return capacity;
- }
- unsigned int Truck::getTotalWeight() {
- return totalWeight;
- }
- void Client::setName(string n) {
- name = n;
- }
- void Client::setAge(int a) {
- age = a;
- }
- string Client::getName() {
- return name;
- }
- int Client::getAge() {
- return age;
- }
- void Car::print() {
- cout << make << "\t";
- cout << engine << "\t";
- cout << price << "\t";
- cout << year << "\t";
- cout << damaged << "\t";
- cout << endl;
- cout << endl;
- }
- void Car::printPrice() {
- cout << price << endl;
- }
- void Car::initialization() {
- string make[5] = { "volkswagen", "audi", "bmw", "opel", "mercedes" };
- string engine[2] = { "diesel", "petrol" };
- string randomMake = make[(rand() % 4)];
- string randomEngine = engine[rand() % 2];
- Car::make = randomMake;
- Car::engine = engine[rand() % 2];
- price = 1000 * (5 + rand() % 27);
- year = 1999 + rand() % 11;
- damaged = rand() % 2;
- }
- void Client::print() {
- cout << name << "\t";
- cout << age << endl;
- }
- void Client::initialization() {
- cout << "podaj imie" << endl;
- cin >> name;
- cout << "podaj wiek" << endl;
- cin >> age;
- }
- void Workshop::addClient() {
- /*
- MemoryManagement::dynamicAllocation(myClient, 1);
- MemoryManagement::initialization(myClient, 1);
- */
- MemoryManagement::addPtrToArray(myClient, clientCount);
- //myClient[clientCount]->setName(name);
- clientCount++;
- }
- void Workshop::addCar() {
- cout << "podaj liczbe aut do dodania" << endl;
- cin >> vehicleCount;
- MemoryManagement::dynamicAllocation(myVehicle, vehicleCount);
- MemoryManagement::initialization(myVehicle, vehicleCount);
- }
- void Workshop::viewClients() {
- if (clientCount == 0) cout << "aktualnie nie mamy zadnych kontrahentow" << endl;
- for (int i = 0; i < clientCount; i++) {
- cout << i + 1 << "\t";
- myClient[i]->print();
- }
- cout << endl;
- }
- void Workshop::presentCars() {
- if (vehicleCount == 0) cout << "aktualnie nie mamy zadnych pojazdow w ofercie" << endl;
- for (int i = 0; i < vehicleCount; i++) {
- cout << i + 1 << "\t";
- myVehicle[i]->print();
- }
- }
- void Workshop::sellCar() {
- cout << "czy jestes juz w naszej bazie klientow? 0.nie 1.tak" << endl;
- int addingClient;
- cin >> addingClient;
- int current;
- if (addingClient == 0) {
- addClient();
- current = 1;
- }
- else {
- viewClients();
- cout << "podaj swoj nr ID" << endl;
- cin >> current;
- }
- if (vehicleCount == 0) {
- cout << "aktualnie nie mamy zadnych pojazdow w ofercie" << endl;
- return;
- }
- cout << "wybierz pojazd z naszej oferty\n" << endl;
- for (int i = 0; i < vehicleCount; i++) {
- cout << i + 1 << "\t";
- myVehicle[i]->print();
- }
- cout << "podaj numer pojazdu ktory Cie interesuje\n" << endl;
- int choice;
- cin >> choice;
- cout << "cena pojazdu wynosi ";
- myVehicle[choice - 1]->printPrice(); cout << "$" << endl << endl;
- cout << "czy chcesz kupic wybrany pojazd?\n 0.nie 1.tak\n" << endl;
- bool buy;
- bool retry;
- cin >> buy;
- if (buy == 1) {
- balance = balance + myVehicle[choice - 1]->getPrice();
- MemoryManagement::removePtrFromNth(myVehicle, vehicleCount, choice);
- vehicleCount--;
- cout << "balans po wykonanej transakcji " << balance << "$" << endl;
- }
- else {
- cout << "czy chcesz wybrac inny pojazd?\n 0.nie 1.tak\n" << endl;
- cin >> retry;
- if (retry == 1) {
- return sellCar();
- }
- else {
- return;
- }
- }
- }
- void Workshop::buyCar() {
- if (clientCount == 0) {
- addClient();
- int vehicleType;
- cout << "jaki rodzaj pojazdu chcesz sprzedac" << endl;
- cout << "1. auto 2. ciezarowka 3. motocykl" << endl;
- cin >> vehicleType;
- cout << "wprowadz parametry pojazdu ;" << endl;
- bool damaged;
- Car temp;
- cin >> temp;
- cout << "sprawdz dane" << endl;
- cout << temp;
- cout << "czy auto jest uszkodzone?\n 0.nie 1.tak\n" << endl;
- cin >> damaged;
- if (damaged == 1) {
- cout << "mozemy zaoferowac Ci " << temp.price / 2 << "$" << endl;
- cout << "czy chcesz sprzedac ten pojazd?\n 0.nie 1.tak\n" << endl;
- int choice = 0;
- cin >> choice;
- if (choice == 0) {
- return;
- }
- else if (choice == 1) {
- MemoryManagement::addPtrToArray(myVehicle, vehicleCount);
- switch (vehicleType) {
- case 1: {
- myVehicle[vehicleCount] = new Car();
- break;
- }
- case 2: {
- myVehicle[vehicleCount] = new Truck();
- //TODO
- break;
- }
- case 3: {
- myVehicle[vehicleCount] = new Motorcycle();
- break;
- }
- }
- vehicleCount++;
- balance = balance - temp.price / 2;
- cout << "balans po wykonanej transakcji " << balance << "$" << endl;
- return;
- }
- }
- else {
- cout << "mozemy zaoferowac Ci " << 0.8*temp.price << "$" << endl;
- cout << "czy chcesz sprzedac ten pojazd?\n 0.nie 1.tak\n" << endl;
- int choice = 0;
- cin >> choice;
- if (choice == 0) {
- return;
- }
- else if (choice == 1) {
- MemoryManagement::addPtrToArray(myVehicle, vehicleCount);
- switch (vehicleType) {
- case 1: {
- myVehicle[vehicleCount] = new Car();
- break;
- }
- case 2: {
- myVehicle[vehicleCount] = new Truck();
- break;
- }
- case 3: {
- myVehicle[vehicleCount] = new Motorcycle();
- break;
- }
- }
- vehicleCount++;
- balance = balance - 0.8*temp.price;
- cout << "balans po wykonanej transakcji " << balance << "$" << endl;
- return;
- }
- }
- return;
- }
- }
- void Workshop::repairCar() {
- Mechanic mechanic;
- for (int i = 0; i < 5; i++) {
- mechanic.repairVehicle(myVehicle[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement