Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- using namespace std;
- struct Animal
- {
- string kind;
- string breed;
- int age{ 0 };
- double price{0};
- };
- struct Node
- {
- Animal data;
- Node* next{nullptr};
- };
- struct Customer
- {
- string kind;
- string breed;
- int age;
- double price;
- };
- class Shelter
- {
- Node* Animals{ nullptr };
- double balance();
- unsigned freePlases { 0 };
- public:
- void InsertAnimalInList(Animal x);
- void removeAnimalFromList(Animal x);
- void decreaseFreePlases();
- void increaseFreePlases();
- int countOfAnimals() const;
- int countOfCats() const;
- int countOfDogs() const;
- double costForDay();
- double profitForDay() const;
- double Sale(Animal a);
- void printShelter() const;
- bool IsFound(Customer C) const;
- Animal GetAnimal(Customer C) const;
- double findSumCats() const;
- double findSumDogs() const;
- bool hasFreePlace() const;
- void shelterInfo() const;
- };
- double Shelter::costForDay()
- {
- double cost = 0;
- Node* current = Animals;
- for (int i = 0; i < countOfAnimals(); i++)
- {
- cost += (current->data.price * 0.02);
- };
- return cost;
- }
- //double Shelter::profitForDay() {}
- Animal readAnimal() {
- Animal animal;
- cout << "Enter data for new animal:"<<endl;
- cout << "Kind: ";
- cin >> animal.kind;
- cout << "Breed: ";
- cin.ignore();
- getline(cin, animal.breed);
- cout << "Age: ";
- cin >> animal.age;
- cout << "Price: ";
- cin >> animal.price;
- return animal;
- }
- void printAnimal(Animal animal)
- {
- cout << "Kind: " << animal.kind << endl;
- cout << "Breed: "<< animal.breed << endl;
- cout << "Age: "<< animal.age << endl;
- cout << "Price: " << animal.price << endl;
- cout << endl;
- }
- void Shelter::printShelter() const
- {
- cout << "Animals in the shelter are: " << endl;
- Node* current = Animals;
- while (current != nullptr)
- {
- printAnimal(current->data);
- current = current->next;
- }
- cout << endl;
- }
- void Shelter::InsertAnimalInList(Animal x)
- {
- Node* temp = new Node;
- temp->data = x;
- temp->next = nullptr;
- if (Animals == nullptr)
- {
- Animals = temp;
- }
- else
- {
- Node* temp1 = Animals;
- while (temp1->next != nullptr)
- {
- temp1 = temp1->next;
- }
- temp1->next = temp;
- }
- }
- void Shelter::removeAnimalFromList(Animal x)
- {
- if (Animals == nullptr)
- {
- return;
- }
- Node* current = Animals;
- Node* prev = Animals;
- while (current != nullptr)
- {
- if (x.age == current->data.age &&
- x.kind == current->data.kind &&
- x.breed == current->data.breed &&
- x.price == current->data.price)
- {
- if (current == Animals)
- {
- Animals = current->next;
- delete current;
- current = nullptr;
- }
- else
- {
- prev->next = current->next;
- delete current;
- current = nullptr;
- }
- }
- else
- {
- if (current != Animals) prev = current;
- current=current->next;
- }
- }
- }
- void Shelter::decreaseFreePlases()
- {
- freePlases--;
- }
- void Shelter::increaseFreePlases()
- {
- freePlases++;
- }
- int Shelter::countOfAnimals() const
- {
- return countOfCats() + countOfDogs();
- }
- int Shelter::countOfCats() const
- {
- int count = 0;
- Node* current = Animals;
- while (current != nullptr)
- {
- if (current->data.kind == "cat")
- {
- ++count;
- }
- current = current->next;
- }
- return count;
- }
- int Shelter::countOfDogs() const
- {
- int count = 0;
- Node* current = Animals;
- while (current != nullptr)
- {
- if (current->data.kind == "dog")
- {
- ++count;
- }
- current = current->next;
- }
- return count;
- }
- double Shelter::findSumCats() const
- {
- double sum = 0;
- Node* current = Animals;
- while (current != nullptr)
- {
- if (current->data.kind == "cat")
- {
- sum += current->data.price;
- }
- current = current->next;
- }
- return sum;
- }
- double Shelter::findSumDogs() const
- {
- double sum = 0;
- Node* current = Animals;
- while (current != nullptr)
- {
- if (current->data.kind == "dog")
- {
- sum += current->data.price;
- }
- current = current->next;
- }
- return sum;
- }
- double InsertAnimal(Animal newAnimal, Shelter shelter)
- {
- shelter.InsertAnimalInList(newAnimal);
- shelter.decreaseFreePlases();
- double cost = 0;
- if (newAnimal.kind == "cat")
- {
- cost =double (shelter.findSumCats() / shelter.countOfCats());
- }
- if (newAnimal.kind == "dog")
- {
- cost = double(shelter.findSumDogs() / shelter.countOfDogs());
- }
- return cost;
- }
- double Shelter::Sale(Animal a)
- {
- removeAnimalFromList(a);
- increaseFreePlases();
- return a.price;
- }
- Customer Requirements()
- {
- Customer C;
- cout << "Enter kind: ";
- cin.ignore();
- getline(cin,C.kind);
- if (C.kind != "cat" && C.kind != "dog")
- {
- cout << "Invalid kind!";
- exit(1);
- }
- string s;
- cout << "Do you want to enter your requirements manual or automatic? "<<endl;
- cin >> s;
- if (s == "automatic")
- {
- }
- else if (s == "manual")
- {
- cout << "Enter breed: ";
- cin.ignore();
- getline(cin,C.breed);
- cout << "Enter age: ";
- cin >> C.age;
- cout << "Enter limit of price: ";
- cin >> C.price;
- }
- else
- {
- cout << "Invalid input!"; exit(1);
- }
- return C;
- }
- bool Shelter::IsFound(Customer C) const
- {
- if (Animals == nullptr)
- {
- return false;
- }
- Node* current = Animals;
- while (current != nullptr)
- {
- if (current->data.kind == C.kind &&
- current->data.breed == C.breed &&
- current->data.age == C.age &&
- current->data.price <= C.price)
- {
- return true;
- }
- current = current->next;
- }
- return false;
- }
- Animal Shelter::GetAnimal(Customer C) const
- {
- if (Animals == nullptr)
- {
- exit(1);
- }
- Node* current = Animals;
- while (current != nullptr)
- {
- if (current->data.kind == C.kind &&
- current->data.breed == C.breed &&
- current->data.age == C.age &&
- current->data.price <= C.price)
- {
- return current->data;
- }
- current = current->next;
- }
- exit(1);
- }
- bool Shelter::hasFreePlace() const
- {
- return freePlases != 0;
- }
- void Shelter::shelterInfo() const
- {
- cout << "Free places: " << freePlases << endl;
- cout << "Animals count " << countOfAnimals() << endl;
- cout << "Cats count " << countOfCats() << endl;
- cout << "Dogs count " << countOfDogs() << endl;
- cout << "Cats sum: " << findSumCats() << endl;
- cout << "Dogs sum: " << findSumDogs() << endl;
- }
- /*
- double Shelter::balance() {
- return profitForDay() - costForDay();
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement