System zleceń - kopia
This commit is contained in:
39
animals.cpp
Normal file
39
animals.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "animals.h"
|
||||
|
||||
Animal::Animal(std::string name_input, int age_input, bool isHealthy_input, bool isFed_input, int size_input)
|
||||
: name(name_input), age(age_input), size(size_input), healthStatus(isHealthy_input, isFed_input) {}
|
||||
|
||||
|
||||
Animal::HealthStatus::HealthStatus(bool healthy, bool fed) : isHealthy(healthy), isFed(fed) {}
|
||||
|
||||
|
||||
void Animal::HealthStatus::printHealthStatus() const {
|
||||
std::cout << "Zdrowy: " << (isHealthy ? "Zdrowy" : "Chory")
|
||||
<< "\nNajedzony?: " << (isFed ? "Tak" : "Nie") << "\n";
|
||||
}
|
||||
|
||||
std::string Animal::getName() const { return name; }
|
||||
int Animal::getAge() const { return age; }
|
||||
bool Animal::getHealthState() const { return healthStatus.isHealthy; }
|
||||
bool Animal::getIsFed() const { return healthStatus.isFed; }
|
||||
|
||||
//szczegoly zwierzakow
|
||||
void Animal::print() const {
|
||||
std::cout << "Imie: " << name << "\nWiek: " << age
|
||||
<< "\nRozmiar: " << size << " cm\n";
|
||||
healthStatus.printHealthStatus();
|
||||
}
|
||||
|
||||
Lion::Lion(std::string name_input, int age_input, bool isHealthy_input, bool isFed_input, int size_input)
|
||||
: Animal(name_input, age_input, isHealthy_input, isFed_input, size_input) {}
|
||||
|
||||
void Lion::voice() {
|
||||
std::cout << name << " Raaaaaarrr!\n";
|
||||
}
|
||||
|
||||
Snake::Snake(std::string name_input, int age_input, bool isHealthy_input, bool isFed_input, int size_input)
|
||||
: Animal(name_input, age_input, isHealthy_input, isFed_input, size_input) {}
|
||||
|
||||
void Snake::voice() {
|
||||
std::cout << name << " Sssssssss!\n";
|
||||
}
|
||||
68
animals.h
Normal file
68
animals.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class Animal {
|
||||
protected:
|
||||
std::string name;
|
||||
int age;
|
||||
int size;
|
||||
|
||||
public:
|
||||
// Nested class to represent health-related attributes
|
||||
class HealthStatus {
|
||||
public:
|
||||
bool isHealthy;
|
||||
bool isFed;
|
||||
|
||||
// Constructor to initialize health status
|
||||
HealthStatus(bool healthy = true, bool fed = true);
|
||||
|
||||
// Method to print health status
|
||||
void printHealthStatus() const;
|
||||
};
|
||||
|
||||
// Instance of HealthStatus to track an animal's health
|
||||
HealthStatus healthStatus;
|
||||
|
||||
// Constructor for Animal class
|
||||
Animal(std::string name_input, int age_input, bool isHealthy_input, bool isFed_input, int size_input);
|
||||
|
||||
virtual ~Animal() = default;
|
||||
|
||||
// Getter methods
|
||||
std::string getName() const;
|
||||
int getAge() const;
|
||||
bool getHealthState() const;
|
||||
bool getIsFed() const;
|
||||
|
||||
// Method to print the animal's details
|
||||
void print() const;
|
||||
|
||||
// Pure virtual method for voice, to be implemented by derived classes
|
||||
virtual void voice() = 0;
|
||||
};
|
||||
|
||||
class Lion : public Animal {
|
||||
public:
|
||||
Lion(std::string name_input, int age_input, bool isHealthy_input = true, bool isFed_input = true, int size_input = 100);
|
||||
|
||||
void voice() override;
|
||||
~Lion() override = default;
|
||||
};
|
||||
|
||||
|
||||
class Snake : public Animal {
|
||||
public:
|
||||
Snake(std::string name_input, int age_input, bool isHealthy_input = true, bool isFed_input = true, int size_input = 50);
|
||||
|
||||
void voice() override;
|
||||
~Snake() override = default;
|
||||
};
|
||||
|
||||
1
compile.sh
Executable file
1
compile.sh
Executable file
@@ -0,0 +1 @@
|
||||
g++ main.cpp user.cpp zlecenie.cpp ticket.cpp animals.cpp
|
||||
441
main.cpp
Normal file
441
main.cpp
Normal file
@@ -0,0 +1,441 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "user.h"
|
||||
#include "zlecenie.h"
|
||||
#include "ticket.h"
|
||||
#include "animals.h"
|
||||
#include <iomanip>
|
||||
//#include "ui.h"
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
using std::string;
|
||||
using std::endl;
|
||||
using std::vector;
|
||||
|
||||
void AddUser(std::vector<User>& users_list, string login,string password, string name, string surname, int access_level){
|
||||
users_list.push_back(User(login,password,name,surname,access_level));
|
||||
|
||||
}
|
||||
// void AddZlecenie(std::vector<Zlecenie>& zlecenia,int id,string nazwa, string opis, string przypisany, int access_level){
|
||||
// zlecenia.push_back(Zlecenie(id,nazwa,opis,przypisany));
|
||||
// }
|
||||
void Clear()
|
||||
{
|
||||
#if defined _WIN32
|
||||
system("cls");
|
||||
|
||||
#elif defined (__LINUX__) || defined(__gnu_linux__) || defined(__linux__)
|
||||
system("clear");
|
||||
|
||||
#elif defined (__APPLE__)
|
||||
system("clear");
|
||||
#endif
|
||||
}
|
||||
void Pause(){
|
||||
cin.ignore();
|
||||
do
|
||||
{
|
||||
cout << '\n' << "Zrobione, Nacisnij klawisz aby kontynuowac";
|
||||
} while (cin.get() != '\n');
|
||||
Clear();
|
||||
}
|
||||
void welcome(User* user){
|
||||
|
||||
cout<<"Zalogowano jako: "<<user->GetName()<<" "<<user->GetSurname()<<"\n";
|
||||
}
|
||||
void newticket(){
|
||||
int typ = 0;
|
||||
cout<<"----------------- Kupno Biletu -------------------------\n";
|
||||
cout<<"\nwybierz jaki bilet chcesz kupic";
|
||||
cout<<"\n1. Zwykly";
|
||||
cout<<"\n2. Ulgowy\n";
|
||||
cout<<": ";
|
||||
cin>>typ;
|
||||
cout<<"\n------ Oto dane twojego biletu, zapamietaj je -----------\n\n";
|
||||
Ticket bilet(typ);
|
||||
bilet.ticketInfo();
|
||||
cout<<"\n---------------------------------------------------------\n";
|
||||
|
||||
}
|
||||
void checkticket(string id){
|
||||
Ticket bilet(id);
|
||||
bilet.ticketValidityCheck();
|
||||
}
|
||||
void ticketchcecked(){
|
||||
string id;
|
||||
cout<<"Podaj id biletu: ";
|
||||
cin>>id;
|
||||
cout<<"\n";
|
||||
Ticket bilet(id);
|
||||
bilet.ticketUse();
|
||||
}
|
||||
|
||||
User* authenticate(vector <User>& user_list,const string& login, const string& password){
|
||||
for(auto& user : user_list){
|
||||
if(user.authenticate(login,password)){
|
||||
return &user;}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CreateUserForm(int powerlevel,std::vector<User>& lista){ //Funkcja dodaje formularz do tworzenia użytkowników
|
||||
if(powerlevel<2){cout<<"Nie masz wystarczających uprawnień do tej operacji !\n";}
|
||||
else {
|
||||
string login,password,name,surname;
|
||||
int newpowerlevel;
|
||||
cout<<"Podaj imie nowego użytwkownika: ";
|
||||
cin>>name;
|
||||
cout<<"Podaj nazwisko nowego użytwkownika: ";
|
||||
cin>>surname;
|
||||
bool exist = true;
|
||||
do{
|
||||
cout<<"Podaj login nowego użytwkownika: ";
|
||||
cin>>login;
|
||||
|
||||
for(auto& user : lista){
|
||||
exist = user.checkifloginexist(login);
|
||||
if(exist) break; //jesli uzytkownik istnieje to przerywa szukanie go w pliku
|
||||
}
|
||||
if(exist) cout<<"użytkowni o podanej nazwie istnieje, musisz podać inną nazwę";
|
||||
}while(exist);
|
||||
|
||||
|
||||
cout<<"Podaj haslo nowego użytwkownika: "; //do dopisania - sprawdzenie poprawnosci hasla, gwiazdki zamiast znaczkow
|
||||
cin>>password;
|
||||
if(powerlevel==2){newpowerlevel=2;} //jeśli użytkownika tworzy ;,,gość - użytkownik służacy do tworzenia użytkownikow
|
||||
else{
|
||||
cout<<"\nWybierz poziom uprawnien nowego użytwkownika: ";
|
||||
cin>>newpowerlevel;
|
||||
while(newpowerlevel>powerlevel or newpowerlevel<1){ //sprawdzenie czy użytkownik bedący moderatorem nei chce stworzyć użytkownika administatora
|
||||
cout<<"\nTo nie jest poprawny poziom uprawnień, możesz jedynie wybrać zakres od 1 do "<< powerlevel <<"\nPodaj ponownie: ";
|
||||
cin>>newpowerlevel;
|
||||
}
|
||||
}
|
||||
AddUser(lista,login,password,name,surname,newpowerlevel);
|
||||
cout<<"dodano użytkownika\n";
|
||||
}
|
||||
}
|
||||
|
||||
/*ten fragment moglby byc napisany z uzyciem wskaznikow i nawet byloby to zalecane ale nnie znalazlem jesszcze sposobu aby to zdzialalo z auto*/
|
||||
|
||||
string listusers(const vector<User>& user_list){
|
||||
cout<<"\n----------------\n";
|
||||
int i=0;
|
||||
for(auto user:user_list){
|
||||
cout<<i++<<". "<<user.GetName()<<" "<<user.GetSurname()<<endl;
|
||||
}
|
||||
cout<<"\n----------------\n";
|
||||
cout<<"podaj numer użytkownika:";
|
||||
i=0;
|
||||
int numer;
|
||||
cin>>numer;
|
||||
for(auto user:user_list){
|
||||
if(i==numer) return user.GetLogin();
|
||||
i++;
|
||||
}
|
||||
|
||||
return "nic";
|
||||
}
|
||||
void saveZlecenia(const vector<Zlecenie>& zlecenie_list,const string& filename){
|
||||
std::ofstream outfile(filename);
|
||||
if(outfile.is_open()){
|
||||
for (auto zlecenie : zlecenie_list){ //dla kazdego uzytkownika w liscie
|
||||
zlecenie.saveToFile(outfile);
|
||||
}
|
||||
outfile.close();
|
||||
cout << "Zlecenia zapisane do pliku!" << endl;
|
||||
}
|
||||
else {
|
||||
cout << "Błąd podczas otwierania pliku do zapisu!" << endl;
|
||||
}
|
||||
|
||||
}
|
||||
void NewZlecenie(const vector<User>& user_list,User* user,vector<Zlecenie>zlecenie_list,int id){
|
||||
if(user->GetAccessLevel()<3) {
|
||||
cout<<"Nie masz wystarczajacych uprawnien"; //prawdopodobnie sie nigdy nie wykona
|
||||
return;
|
||||
|
||||
}
|
||||
string nazwa,opis,przypisany;
|
||||
cout<<"Wpisz nazwe nowego zlecenia: ";
|
||||
cin.ignore();
|
||||
std::getline(cin,nazwa);
|
||||
cout<<"Podaj opis nowego zlecenia: ";
|
||||
std::getline(cin,opis);
|
||||
cout<<"Wybierz kogo chcesz przypisac do zlecenia: ";
|
||||
przypisany = listusers(user_list);
|
||||
zlecenie_list.push_back(Zlecenie(id,nazwa,opis,przypisany));
|
||||
saveZlecenia(zlecenie_list,"zlecenia.txt");
|
||||
}
|
||||
|
||||
|
||||
void saveUsers(const vector <User>& user_list,const string& filename){
|
||||
std::ofstream outfile(filename);
|
||||
if(outfile.is_open()){
|
||||
for (auto user : user_list){ //dla kazdego uzytkownika w liscie
|
||||
user.saveToFile(outfile);
|
||||
}
|
||||
outfile.close();
|
||||
cout << "Użytkownicy zapisani do pliku!" << endl;
|
||||
}
|
||||
else {
|
||||
cout << "Błąd podczas otwierania pliku do zapisu!" << endl;
|
||||
}
|
||||
|
||||
}
|
||||
bool loadUsers(std::vector<User>& user_list, const std::string& filename) {
|
||||
std::ifstream inFile(filename);
|
||||
if (inFile.is_open()) {
|
||||
try {
|
||||
while (true) {
|
||||
user_list.push_back(User::loadFromFile(inFile));
|
||||
}
|
||||
} catch (const std::runtime_error& e) {
|
||||
// Wyświetl informację o błędzie, jeśli odczyt się nie powiedzie
|
||||
if (!inFile.eof()) {
|
||||
std::cerr << "Błąd odczytu użytkownika: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
inFile.close();
|
||||
return true;
|
||||
} else {
|
||||
std::cout << "Błąd odczytu, plik nie istnieje itp." << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool loadZlecenia(std::vector<Zlecenie>& zlecenie_list, const std::string& filename) { //skopiowane z users
|
||||
std::ifstream inFile(filename);
|
||||
if (inFile.is_open()) {
|
||||
try {
|
||||
while (true) {
|
||||
zlecenie_list.push_back(Zlecenie::loadFromFile(inFile));
|
||||
}
|
||||
} catch (const std::runtime_error& e) {
|
||||
// Wyświetl informację o błędzie, jeśli odczyt się nie powiedzie
|
||||
if (!inFile.eof()) {
|
||||
std::cerr << "Błąd odczytu użytkownika: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
inFile.close();
|
||||
return true;
|
||||
} else {
|
||||
std::cout << "Błąd odczytu, plik nie istnieje itp." << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void animals_sound(vector<Animal*>& animals){
|
||||
for (const auto& animal : animals) {
|
||||
animal->voice(); // Wywołanie polimorficzne
|
||||
}
|
||||
}
|
||||
|
||||
void ShowZleceniafromuser(vector<Zlecenie>& zlecenie_list, User* user){
|
||||
zlecenie_list.clear();
|
||||
if(loadZlecenia(zlecenie_list, "zlecenia.txt")){ cout<<"";}
|
||||
int input=-2;
|
||||
while(input!=-1){
|
||||
cout<<"\n-----Twoje zlecenia------\n";
|
||||
int i=0;
|
||||
cout << std::left << std::setw(5) << "Nr" << " | " << std::setw(20) << "Nazwa" << " | " << "ID" << endl;
|
||||
cout << string(40, '-') << endl;
|
||||
for(auto zlecenie: zlecenie_list){
|
||||
if(zlecenie.GetPrzypisany()== user->GetLogin()){
|
||||
cout << std::left << std::setw(5) << i++ << " | " << std::setw(20) << zlecenie.GetNazwa() << " | " << zlecenie.GetId() << endl;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
cout<<"\n-------------------------";
|
||||
cout<<"\nWpisz numer zlecenia aby zobaczyc zawartosc lub -1 aby wyjsc";
|
||||
cin>>input;
|
||||
i=0;
|
||||
for(auto zlecenie: zlecenie_list){
|
||||
if(zlecenie.GetPrzypisany()== user->GetLogin()){if(input==i){
|
||||
Clear();
|
||||
cout << std::left << std::setw(5) << i++ << " | " << std::setw(20) << zlecenie.GetNazwa() << " | " << zlecenie.GetId() << endl;
|
||||
cout<<"----------------------\n";
|
||||
cout<<zlecenie.GetOpis();
|
||||
cout<<"\n----------------------\n";
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
}
|
||||
void ShowZleceniaall(vector<Zlecenie>& zlecenie_list){
|
||||
zlecenie_list.clear();
|
||||
if(loadZlecenia(zlecenie_list, "zlecenia.txt")){ cout<<"";}
|
||||
int input=-2;
|
||||
while(input!=-1){
|
||||
cout<<"\n-----Wszystkie zlecenia------\n";
|
||||
int i=0;
|
||||
cout << std::left << std::setw(5) << "Nr" << " | " << std::setw(25) << "Nazwa" << " | " << "ID" <<" | " << "Przypisany Uzytkownik" << endl;
|
||||
cout << string(40, '-') << endl;
|
||||
for(auto zlecenie: zlecenie_list){
|
||||
cout << std::left << std::setw(5) << i++ << " | " << std::setw(25) << zlecenie.GetNazwa() << " | " << zlecenie.GetId()<<" | " << zlecenie.GetPrzypisany() << endl;
|
||||
|
||||
|
||||
}
|
||||
cout<<"\n-------------------------";
|
||||
cout<<"\nWpisz numer zlecenia aby zobaczyc zawartosc lub -1 aby wyjsc";
|
||||
cin>>input;
|
||||
i=0;
|
||||
for(auto zlecenie: zlecenie_list){
|
||||
if(input==i){
|
||||
Clear();
|
||||
cout << std::left << std::setw(5) << "Nr" << " | " << std::setw(25) << "Nazwa" << " | " << "ID" <<" | " << "Przypisany Uzytkownik" << endl;
|
||||
cout << std::left << std::setw(5) << i++ << " | " << std::setw(25) << zlecenie.GetNazwa() << " | " << zlecenie.GetId()<< zlecenie.GetId()<<" | " << zlecenie.GetPrzypisany() << endl;
|
||||
cout<<"----------------------\n";
|
||||
cout<<zlecenie.GetOpis();
|
||||
cout<<"\n----------------------\n";
|
||||
}
|
||||
i++;
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
}
|
||||
void displayHealthStatus(const std::vector<Animal*>& animals) {
|
||||
std::cout << "Stan zdrowia wszystkich zwierzat:\n";
|
||||
for (const auto& animal : animals) {
|
||||
std::cout << "Zwoerze:: " << animal->getName() << "\n";
|
||||
animal->healthStatus.printHealthStatus();
|
||||
std::cout << "-----------------------\n";
|
||||
}
|
||||
}
|
||||
/* access_level jest tym co określa uprawnienia do funkcji progtramu danego użytkownika
|
||||
* 0 - nic, nie uzywa sie
|
||||
* 1 - auto konto goscia
|
||||
* 2 - użytkownik z zewnatrz, , posiadajacy swoje konto
|
||||
* 3 - pracownik, może on rowniez kupic bilet, a także wyświetlić zlecenia które zostały mu przypisane
|
||||
* 4 zarządca - może dodawać zlecenia i tworzyć nowych użytkowników(maksynalnie zarządców)
|
||||
* 5. Administrator - może wszystko, jego konto jest tworzone przy pierwszym uruchomieniu programu
|
||||
*/
|
||||
int main(){
|
||||
string login;
|
||||
string password;
|
||||
vector<User> user_list;
|
||||
vector<Zlecenie> zlecenie_list;
|
||||
vector<Animal*> animals;
|
||||
animals.push_back(new Lion("Leo", 5));
|
||||
animals.push_back(new Snake("Kaa", 3));
|
||||
animals.push_back(new Lion("Simba", 2));
|
||||
animals.push_back(new Snake("Nagini", 7));
|
||||
|
||||
//Animal zwierze;
|
||||
int wybor = -1;
|
||||
if(!loadUsers(user_list,"users.txt")){ //odpala tworzenie nowego użytkownika jeśli ten nie istnieje
|
||||
cout<<"Witaj, ten formularz pozwoli ci dodać administratora systemu i przygotować go do pracy";
|
||||
CreateUserForm(5,user_list);
|
||||
saveUsers(user_list, "users.txt");
|
||||
}
|
||||
int id = 0;
|
||||
if(loadZlecenia(zlecenie_list, "zlecenia.txt")){ cout<<"";
|
||||
id=zlecenie_list.back().GetId();}
|
||||
do{
|
||||
User* loggeduser = nullptr;
|
||||
AddUser(user_list,"gosc","ewtweugwehh","Gosc"," ",1);
|
||||
do
|
||||
{
|
||||
cout<<"System zarzadzania Zoo v1.0, Jesli jestes gosciem naszego zoo wpisz zoo " << endl <<"login: ";
|
||||
cin >> login;
|
||||
if(login=="gosc"){
|
||||
loggeduser = authenticate(user_list,"gosc","ewtweugwehh");
|
||||
}else{
|
||||
|
||||
|
||||
cout<<"podaj hasło: ";
|
||||
cin >> password;
|
||||
loggeduser = authenticate(user_list,login,password);} //po sprawdzeniu poprawnosci danych przypisuje uzytkownika do wskaznika
|
||||
if(!loggeduser) cout<<"Bledne dane, sprobuj jeszcze raz";
|
||||
}while(!loggeduser);
|
||||
Clear();
|
||||
do{
|
||||
welcome(loggeduser);
|
||||
//clear screen
|
||||
if(loggeduser->GetAccessLevel()>=1){
|
||||
cout<<"\n---- Wybierz funkcje programu: -----\n";
|
||||
cout<<"2. Kup bilet\n";
|
||||
|
||||
cout<<"3. Dla dzieci : Sprawdz jakie dzwieki wydaje jakie zwierze !\n";}
|
||||
if(loggeduser->GetAccessLevel()>3)
|
||||
{
|
||||
|
||||
cout<<"4. Wyswietl swoje zlecenia:\n";
|
||||
cout<<"5. Dodaj zlecenie\n";
|
||||
cout<<"6. Dodaj uzytkownika\n";
|
||||
cout<<"7. Skasuj bilet(kasa)\n";
|
||||
cout<<"8. Sprawdz stan zwierzat\n";
|
||||
}
|
||||
if(loggeduser->GetAccessLevel()>4){
|
||||
cout<<"9. Wyswietl wszystkie zlecenia\n\n";
|
||||
}
|
||||
cout<<"\n----------- System ----------- : \n";
|
||||
cout<<"1.Zmien użytkownika\n";
|
||||
cout<<"0. Wyjdz z programu\n";
|
||||
cout<<"Podaj numer: \n";
|
||||
|
||||
|
||||
|
||||
cin>>wybor;
|
||||
Clear();
|
||||
switch(wybor){
|
||||
case 2:{
|
||||
newticket();
|
||||
break;}
|
||||
|
||||
case 3:{
|
||||
|
||||
animals_sound(animals);
|
||||
break;}
|
||||
|
||||
}
|
||||
if(loggeduser->GetAccessLevel()>3){
|
||||
switch(wybor){
|
||||
case 4:{
|
||||
ShowZleceniafromuser(zlecenie_list,loggeduser);
|
||||
break;}
|
||||
case 5:{
|
||||
id++;
|
||||
NewZlecenie(user_list,loggeduser,zlecenie_list,id);
|
||||
break;}
|
||||
case 6:{
|
||||
CreateUserForm(loggeduser->GetAccessLevel(),user_list);
|
||||
saveUsers(user_list, "users.txt");
|
||||
break;}
|
||||
case 7:{
|
||||
ticketchcecked();;
|
||||
break;}
|
||||
case 8:{
|
||||
displayHealthStatus(animals);
|
||||
break;}
|
||||
default: break;
|
||||
}
|
||||
|
||||
}
|
||||
if(loggeduser->GetAccessLevel()>4){
|
||||
switch(wybor){
|
||||
case 9:{
|
||||
ShowZleceniaall(zlecenie_list);
|
||||
break;}
|
||||
default: break;
|
||||
|
||||
|
||||
}
|
||||
Pause();
|
||||
cout<<"\n\n";
|
||||
}
|
||||
//kup bilet
|
||||
}while(wybor!=0 && wybor!=1);
|
||||
}while(wybor!=0);
|
||||
|
||||
for (auto& animal : animals) {
|
||||
delete animal;
|
||||
}
|
||||
|
||||
animals.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
153
ticket.cpp
Normal file
153
ticket.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include "ticket.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
//Funkcja generująca losowe id dla biletu
|
||||
std::string generateRandomString(unsigned int length) {
|
||||
const std::string characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
std::string randomString;
|
||||
|
||||
// Inicjalizacja generatora liczb losowych z wykorzystaniem czasu
|
||||
std::mt19937 generator(static_cast<unsigned int>(std::time(0)));
|
||||
std::uniform_int_distribution<int> distribution(0, characters.size() - 1);
|
||||
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
randomString += characters[distribution(generator)];
|
||||
}
|
||||
return randomString;
|
||||
}
|
||||
|
||||
|
||||
Ticket::Ticket(int ticket_type){
|
||||
this -> id = generateRandomString(10);
|
||||
this-> ticket_type = ticket_type;
|
||||
this -> is_valid = true;
|
||||
this -> buy_date = static_cast<int>(time(nullptr));
|
||||
this -> expire_date = static_cast<int>(time(nullptr)) + 2678400;
|
||||
this -> use_date = -1;
|
||||
ticketDatabaseAdd();
|
||||
|
||||
};
|
||||
Ticket::Ticket(std::string id_input){
|
||||
std::string line;
|
||||
std::fstream file("tickets.txt");
|
||||
while(std::getline(file,line)){
|
||||
std::istringstream iss(line);
|
||||
std::string id;
|
||||
if (iss >> id){
|
||||
if (id == id_input){
|
||||
int ticket_type;
|
||||
bool is_valid;
|
||||
time_t expire_date,buy_date,use_date;
|
||||
if(iss >> ticket_type >> is_valid >> buy_date >> expire_date >> use_date)
|
||||
{
|
||||
this -> id = id;
|
||||
this-> ticket_type = ticket_type;
|
||||
this -> is_valid = is_valid;
|
||||
this -> buy_date = buy_date;
|
||||
this -> expire_date = expire_date;
|
||||
this -> use_date = use_date;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->line_in_file ++;
|
||||
}
|
||||
}
|
||||
|
||||
void Ticket::ticketDatabaseAdd() {
|
||||
std::fstream file("tickets.txt", std::ios::app);
|
||||
if (file.tellg() !=0) {
|
||||
file<<"\n";
|
||||
}
|
||||
file <<id <<" "<<ticket_type << " "<<is_valid << " "<<buy_date<<" "<<expire_date<<" "<<use_date;
|
||||
lineChecker(id);
|
||||
|
||||
}
|
||||
|
||||
void Ticket::lineChecker(std::string id_input) {
|
||||
std::fstream file("tickets.txt");
|
||||
std::string line;
|
||||
while(std::getline(file,line)){
|
||||
std::istringstream iss(line);
|
||||
std::string id;
|
||||
if (iss >> id){
|
||||
if (id == id_input){
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->line_in_file ++;
|
||||
}
|
||||
}
|
||||
void Ticket::ticketDatabaseUpdate() {
|
||||
int counter = 0;
|
||||
std::string line;
|
||||
std::fstream file("tickets.txt");
|
||||
std::fstream temp_file("tickets_temp.txt", std::ios::out |std::ios::app);
|
||||
while (std::getline(file,line)) {
|
||||
if (temp_file.tellg() !=0) {
|
||||
temp_file<<"\n";
|
||||
}
|
||||
if (counter == line_in_file) {
|
||||
temp_file <<id <<" "<<ticket_type << " "<<is_valid << " "<<buy_date<<" "<<expire_date<<" "<<use_date;
|
||||
}
|
||||
else {
|
||||
temp_file <<line;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
remove("tickets.txt");
|
||||
std::rename("tickets_temp.txt","tickets.txt");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Ticket::ticketInfo(){
|
||||
std::string ticket_type_name;
|
||||
if(this-> ticket_type == 0){
|
||||
ticket_type_name = "normalny";
|
||||
}
|
||||
if(this-> ticket_type == 1){
|
||||
ticket_type_name = "ulgowy";
|
||||
}
|
||||
std::cout << "Id biletu: "<<this ->id <<"\n";
|
||||
std::cout << "Typ biletu: "<<ticket_type_name << "(" << this ->ticket_type << ")"<<"\n";
|
||||
std::cout << "Ważny: "<<this ->is_valid <<"\n";
|
||||
std::cout << "Data_zakupu: "<<std::put_time(std::localtime(&this -> buy_date), "%Y-%m-%d %H:%M:%S")<<"\n";
|
||||
std::cout << "Data_wygaśnięcia: "<<std::put_time(std::localtime(&this -> expire_date), "%Y-%m-%d %H:%M:%S") <<"\n";
|
||||
if (this->use_date != -1) {
|
||||
std::cout << "Data_wykorzystania: "<<std::put_time(std::localtime(&this -> use_date), "%Y-%m-%d %H:%M:%S") <<"\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Sprawdzenie ważności biletu
|
||||
bool Ticket::ticketValidityCheck(){
|
||||
if (!is_valid or expire_date < static_cast<int>(time(nullptr))) {
|
||||
is_valid = false;
|
||||
ticketDatabaseUpdate();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Metoda służąca do "kasowania biletu" i aktualizacji danych w pliku z biletami
|
||||
void Ticket::ticketUse() {
|
||||
if (ticketValidityCheck()) {
|
||||
is_valid = false;
|
||||
use_date = static_cast<int>(time(nullptr));
|
||||
ticketDatabaseUpdate();
|
||||
std::cout <<"Bilet został wykorzystany pomyślnie."<<std::endl;
|
||||
}
|
||||
else {
|
||||
std::cout << "Ten bilet nie może zostać użyty, gdyż jest już wykorzystany lub wygasł."<<std::endl;
|
||||
}
|
||||
}
|
||||
28
ticket.h
Normal file
28
ticket.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <chrono>
|
||||
|
||||
class Ticket {
|
||||
private:
|
||||
std::string id;
|
||||
int ticket_type;
|
||||
int line_in_file = 0;
|
||||
time_t buy_date;
|
||||
time_t expire_date;
|
||||
time_t use_date;
|
||||
bool is_valid;
|
||||
void ticketDatabaseAdd();
|
||||
void lineChecker(std::string id_input);
|
||||
void ticketDatabaseUpdate();
|
||||
|
||||
|
||||
public:
|
||||
explicit Ticket(int ticket_type);
|
||||
explicit Ticket(std::string id_input);
|
||||
void ticketInfo();
|
||||
bool ticketValidityCheck();
|
||||
void ticketUse();
|
||||
|
||||
};
|
||||
15
tickets.txt
Normal file
15
tickets.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
ppMTe0YN7C 1 1 1739446162 1736767762
|
||||
Qf66HgDoeU 1 1 1740146060 1737467660
|
||||
fCyXBHc7lF 1 1 1740146118 1737467718
|
||||
cIhaRjY74O 1 1 1740146147 1737467747
|
||||
xhNctA3Q6n 1 1 1740146186 1737467786
|
||||
WsXtqlRMJA 1 1 1740146213 1737467813
|
||||
qNXuxTtez5 1 1 1740146258 1737467858
|
||||
xpcHJCmpFv 1 1 1740146696 1737468296
|
||||
MBx1PGkxCo 1 1 1740146734 1737468334
|
||||
GkGBuNEryP 1 0 1737469516 1740147916 1737469531
|
||||
pZ7eULyaA4 1 1 1737471510 1740149910 -1
|
||||
a5OqnGseOt 3 1 1737471593 1740149993 -1
|
||||
XDNVDmYxQa 2 1 1737474922 1740153322 -1
|
||||
iEdW7ANbgI 1 1 1737475040 1740153440 -1
|
||||
JtqiJ1Gpj9 2 1 1737478277 1740156677 -1
|
||||
67
ui.cpp
Normal file
67
ui.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
// SPDX-FileCopyrightText: 2025 Krzysztof <email>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include "ui.h"
|
||||
#include <ncurses.h>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
Ui::Ui() {
|
||||
initscr();
|
||||
noecho();
|
||||
cbreak();
|
||||
curs_set(1); // Pokaż kursor
|
||||
}
|
||||
|
||||
// Destruktor: zakończenie pracy z ncurses
|
||||
Ui::~Ui() {
|
||||
endwin();
|
||||
}
|
||||
|
||||
// Rysowanie interfejsu logowania
|
||||
void Ui::draw_ui(WINDOW *win, int width) const {
|
||||
box(win, 0, 0);
|
||||
mvwprintw(win, 2, (width - std::strlen("Login:")) / 2, "Login:");
|
||||
mvwprintw(win, 4, (width - std::strlen("Password:")) / 2, "Password:");
|
||||
mvwprintw(win, 7, (width - std::strlen("[Press ENTER to submit]")) / 2, "[Press ENTER to submit]");
|
||||
wrefresh(win);
|
||||
}
|
||||
|
||||
// Obsługa wprowadzania danych
|
||||
void Ui::handle_input() const {
|
||||
int height, width;
|
||||
getmaxyx(stdscr, height, width);
|
||||
|
||||
int win_width = 40;
|
||||
int win_height = 10;
|
||||
int start_y = (height - win_height) / 2;
|
||||
int start_x = (width - win_width) / 2;
|
||||
|
||||
// Tworzenie okna
|
||||
WINDOW *win = newwin(win_height, win_width, start_y, start_x);
|
||||
keypad(win, TRUE);
|
||||
|
||||
// Rysowanie interfejsu
|
||||
draw_ui(win, win_width);
|
||||
|
||||
// Pola do przechowywania wprowadzonych danych
|
||||
char login[30] = {0};
|
||||
char password[30] = {0};
|
||||
|
||||
// Obsługa wprowadzania danych
|
||||
mvwgetnstr(win, 3, (win_width - 30) / 2, login, sizeof(login) - 1); // Wprowadzenie loginu
|
||||
mvwgetnstr(win, 5, (win_width - 30) / 2, password, sizeof(password) - 1); // Wprowadzenie hasła
|
||||
|
||||
// Czyszczenie ekranu i wyświetlenie wyników
|
||||
clear();
|
||||
mvprintw(height / 2 - 1, (width - std::strlen("Submitted Data")) / 2, "Submitted Data");
|
||||
mvprintw(height / 2, (width - std::strlen("Login: ")) / 2, "Login: %s", login);
|
||||
mvprintw(height / 2 + 1, (width - std::strlen("Password: ")) / 2, "Password: %s", password);
|
||||
mvprintw(height / 2 + 3, (width - std::strlen("[Press any key to exit]")) / 2, "[Press any key to exit]");
|
||||
refresh();
|
||||
|
||||
// Oczekiwanie na klawisz
|
||||
getch();
|
||||
|
||||
// Sprzątanie
|
||||
delwin(win);
|
||||
}
|
||||
72
user.cpp
Normal file
72
user.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
// SPDX-FileCopyrightText: 2024 Krzysztof <email>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include "user.h"
|
||||
User::User(std::string login, std::string password, std::string name, std::string surname, int access_level)
|
||||
: login(login), password(password), name(name), surname(surname), access_level(access_level) {}
|
||||
|
||||
/* --- To samo co w jednej linii tylko bardziej czytelnie ---
|
||||
{
|
||||
this->login = login;
|
||||
this->name = name;
|
||||
this ->surname = surname;
|
||||
this ->access_level = access_level;
|
||||
this ->password = password;
|
||||
}
|
||||
|
||||
*/
|
||||
void User::wyswietl() const {
|
||||
std::cout << "login : " << login << ", Imie: " << name << ", Nazwisko: " << surname << std::endl;
|
||||
}
|
||||
|
||||
std::string User::GetLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
std::string User::GetName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string User::GetSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
int User::GetAccessLevel() {
|
||||
return access_level;
|
||||
}
|
||||
void User::saveToFile(std::ofstream& outFile) {
|
||||
outFile << login << '\n';
|
||||
outFile << password << '\n';
|
||||
outFile << name << '\n';
|
||||
outFile << surname << '\n';
|
||||
outFile << access_level << '\n';
|
||||
}
|
||||
User User::loadFromFile(std::ifstream& sourcefile) {
|
||||
std::string login, password, name, surname;
|
||||
int access_level;
|
||||
|
||||
// Sprawdz odczyt linii, aby upewnic sie, ze nie docieramy do konca pliku
|
||||
if (!std::getline(sourcefile, login)) {
|
||||
throw std::runtime_error("Nieudany odczyt loginu");
|
||||
}
|
||||
if (!std::getline(sourcefile, password)) {
|
||||
throw std::runtime_error("Nieudany odczyt hasla");
|
||||
}
|
||||
if (!std::getline(sourcefile, name)) {
|
||||
throw std::runtime_error("Nieudany odczyt imienia");
|
||||
}
|
||||
if (!std::getline(sourcefile, surname)) {
|
||||
throw std::runtime_error("Nieudany odczyt nazwiska");
|
||||
}
|
||||
if (!(sourcefile >> access_level)) {
|
||||
throw std::runtime_error("Nieudany odczyt poziomu dostepu");
|
||||
}
|
||||
sourcefile.ignore(); // Pomija znak nowej linii po odczycie liczby
|
||||
|
||||
return User(login, password, name, surname, access_level);
|
||||
}
|
||||
bool User::authenticate(const std::string& login, const std::string& password)const{
|
||||
return this->login == login && this->password == password;
|
||||
|
||||
|
||||
}
|
||||
42
user.h
Normal file
42
user.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// SPDX-FileCopyrightText: 2024 Krzysztof <email>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#ifndef USER_H
|
||||
#define USER_H
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
/**
|
||||
* @todo write docs
|
||||
*/
|
||||
class User
|
||||
{
|
||||
private: //wlasciwosci uzytkownikow
|
||||
std::string login;
|
||||
std::string password;
|
||||
std::string name;
|
||||
std::string surname;
|
||||
int access_level;
|
||||
|
||||
public:
|
||||
User(std::string login, std::string password, std::string name, std::string surname, int access_level);
|
||||
|
||||
void wyswietl() const;
|
||||
|
||||
// Getters
|
||||
std::string GetLogin();
|
||||
std::string GetName();
|
||||
std::string GetSurname();
|
||||
int GetAccessLevel();
|
||||
//ustawienia zapisywania do pliku
|
||||
void saveToFile(std::ofstream& outFile);
|
||||
static User loadFromFile(std::ifstream& sourcefile);
|
||||
bool authenticate(const std::string& login, const std::string& password) const; //funkcja do logowania
|
||||
inline bool checkifloginexist(const std::string& login){
|
||||
return this->login == login;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // USER_H
|
||||
45
users.txt
Normal file
45
users.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
jan
|
||||
1234
|
||||
Jan
|
||||
Kowalski
|
||||
5
|
||||
tom
|
||||
1234
|
||||
tomasz
|
||||
inne
|
||||
4
|
||||
sebix
|
||||
1234
|
||||
sebA
|
||||
inny
|
||||
2
|
||||
gosc
|
||||
ewtweugwehh
|
||||
Gosc
|
||||
|
||||
2
|
||||
janek
|
||||
1234
|
||||
Jan
|
||||
Kowalski
|
||||
1
|
||||
gosc
|
||||
ewtweugwehh
|
||||
Gosc
|
||||
|
||||
1
|
||||
adr
|
||||
1234
|
||||
Adrian
|
||||
Milowski
|
||||
2
|
||||
gosc
|
||||
ewtweugwehh
|
||||
Gosc
|
||||
|
||||
1
|
||||
mama
|
||||
1234
|
||||
jan
|
||||
jan
|
||||
5
|
||||
60
zlecenia.txt
Normal file
60
zlecenia.txt
Normal file
@@ -0,0 +1,60 @@
|
||||
1
|
||||
test asda fasf
|
||||
test asf af asf asfu hauisfuasyuifas sh foasuh oasuo hu
|
||||
jan
|
||||
2
|
||||
inne
|
||||
etwijgwe
|
||||
jan
|
||||
3
|
||||
inne
|
||||
etwijgwe
|
||||
jan
|
||||
4
|
||||
inne
|
||||
etwijgwe
|
||||
jan
|
||||
5
|
||||
inne
|
||||
etwijgwe
|
||||
jan
|
||||
6
|
||||
inne
|
||||
etwijgwe
|
||||
jan
|
||||
7
|
||||
etst
|
||||
tesg
|
||||
nic
|
||||
8
|
||||
tewht we ttw etw
|
||||
opweutw gw eew bhweo we owe
|
||||
nic
|
||||
9
|
||||
Nowe zlecenie
|
||||
Trzeba wyczyścić klatke słonia
|
||||
jan
|
||||
10
|
||||
Inne zlecenie
|
||||
Jeszcze inne zlecenie
|
||||
nic
|
||||
11
|
||||
Kolejne przykladowe zlecenie
|
||||
test
|
||||
tom
|
||||
12
|
||||
Czyszczenie malp
|
||||
zlecenie polega na czyszczeniu malp
|
||||
janek
|
||||
13
|
||||
mycie lwow
|
||||
umyc wszystkie lwy w klatce
|
||||
jan
|
||||
14
|
||||
mycie nietoperzy
|
||||
inne
|
||||
jan
|
||||
15
|
||||
mycie rzufi
|
||||
nogi tez
|
||||
jan
|
||||
46
zlecenie.cpp
Normal file
46
zlecenie.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "zlecenie.h"
|
||||
|
||||
Zlecenie::Zlecenie(int id, std::string nazwa, std::string opis, std::string przypisany)
|
||||
: id(id), nazwa(nazwa), opis(opis), przypisany(przypisany) {}
|
||||
|
||||
int Zlecenie::GetId() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
std::string Zlecenie::GetNazwa() const {
|
||||
return nazwa;
|
||||
}
|
||||
|
||||
std::string Zlecenie::GetOpis() const {
|
||||
return opis;
|
||||
}
|
||||
|
||||
std::string Zlecenie::GetPrzypisany() const {
|
||||
return przypisany;
|
||||
}
|
||||
|
||||
void Zlecenie::saveToFile(std::ofstream& outFile) const {
|
||||
outFile << id << '\n';
|
||||
outFile << nazwa << '\n';
|
||||
outFile << opis << '\n';
|
||||
outFile << przypisany << '\n';
|
||||
}
|
||||
|
||||
Zlecenie Zlecenie::loadFromFile(std::ifstream& sourcefile) {
|
||||
std::string nazwa, opis, przypisany;
|
||||
int id;
|
||||
if (!(sourcefile >> id)) {
|
||||
throw std::runtime_error("Nieudany odczyt ID");
|
||||
}
|
||||
sourcefile.ignore(); // Ignoruj znak nowej linii po ID
|
||||
if (!std::getline(sourcefile, nazwa)) {
|
||||
throw std::runtime_error("Nieudany odczyt nazwy");
|
||||
}
|
||||
if (!std::getline(sourcefile, opis)) {
|
||||
throw std::runtime_error("Nieudany odczyt opisu");
|
||||
}
|
||||
if (!std::getline(sourcefile, przypisany)) {
|
||||
throw std::runtime_error("Nieudany odczyt przypisanego użytkownika");
|
||||
}
|
||||
return Zlecenie(id, nazwa, opis, przypisany);
|
||||
}
|
||||
27
zlecenie.h
Normal file
27
zlecenie.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef ZLECENIE_H
|
||||
#define ZLECENIE_H
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
|
||||
class Zlecenie {
|
||||
public:
|
||||
Zlecenie(int id, std::string nazwa, std::string opis, std::string przypisany);
|
||||
|
||||
int GetId() const;
|
||||
std::string GetNazwa() const;
|
||||
std::string GetOpis() const;
|
||||
std::string GetPrzypisany() const;
|
||||
|
||||
void saveToFile(std::ofstream& outFile) const;
|
||||
static Zlecenie loadFromFile(std::ifstream& sourcefile);
|
||||
|
||||
private:
|
||||
int id;
|
||||
std::string nazwa;
|
||||
std::string opis;
|
||||
std::string przypisany;
|
||||
};
|
||||
|
||||
#endif // ZLECENIE_H
|
||||
Reference in New Issue
Block a user