Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<iomanip>
- #include<chrono>
- #include<fstream>
- #include<algorithm>
- using namespace std;
- class I_SlatkiKutak {
- public:
- I_SlatkiKutak() :
- amount{ 4 }, ime{ nullptr }, cijena{ nullptr }{}
- virtual ~I_SlatkiKutak() {
- delete[] ime; ime = nullptr;
- delete[] cijena; cijena = nullptr;
- }
- virtual void print_SlatkiKutak()const = 0;
- virtual int get_amount()const { return amount; }
- virtual string get_imeSlatkisa(const int &i)const = 0;
- virtual double get_cijenaSlatkisa(const int &i)const = 0;
- I_SlatkiKutak&operator=(const I_SlatkiKutak &that);
- protected:
- int amount;
- string *ime;
- double *cijena;
- };
- I_SlatkiKutak&I_SlatkiKutak::operator=(const I_SlatkiKutak &that) {
- if (this == &that) {
- return *this;
- }
- amount = that.amount;
- ime = new string[amount];
- copy(that.ime, that.ime + that.amount, ime);
- cijena = that.cijena;
- return *this;
- }
- class I_Drinks {
- public:
- I_Drinks() :
- amount{ 0 }, ime{ nullptr }, cijena{ nullptr }{}
- virtual ~I_Drinks() {
- delete[] ime; ime = nullptr;
- delete[] cijena; cijena = nullptr;
- }
- virtual void print_drinks()const = 0;
- virtual string get_ime_pica(const int &i)const = 0;
- virtual double get_cijena(const int &i)const = 0;
- I_Drinks&operator=(const I_Drinks &that);
- protected:
- int amount;
- string *ime;
- double *cijena;
- };
- I_Drinks&I_Drinks::operator=(const I_Drinks &that) {
- if (this == &that) {
- return *this;
- }
- amount = that.amount;
- ime = new string[amount];
- copy(that.ime, that.ime + that.amount, ime);
- cijena = that.cijena;
- return *this;
- }
- class Slatkisi:public I_SlatkiKutak {
- public:
- Slatkisi() {
- ime = new string[amount];
- cijena = new double[amount];
- ime[0] = " Palacinci "; cijena[0] = 4.50;
- ime[1] = " Waffle "; cijena[1] = 4.50;
- ime[2] = " Rafaelo Torta "; cijena[2] = 3.50;
- ime[3] = " Tiramisu "; cijena[3] = 3.50;
- }
- ~Slatkisi() {
- delete[] ime; ime = nullptr;
- delete[] cijena; cijena = nullptr;
- }
- void print_SlatkiKutak()const override {
- cout << " ----------------------------------- \n";
- cout << "| SLATKI KUTAK |\n ";
- cout << " ----------------------------------- \n";
- for (int i = 0; i < amount; i++) {
- cout << "|" << "[" << i + 1 << "] " << get_imeSlatkisa(i) << " | " << get_cijenaSlatkisa(i) << " KM " << setw(5) << "|" << endl;
- cout << " ----------------------------------- \n";
- }
- cout << "Unesite[1,2,3,4]za dodavanje na racun\n";
- cout << "-------------------------------------\n";
- cout << " Unesite 0 za povratak na MENU\n";
- cout << "-------------------------------------\n";
- }
- int get_amount()const { return amount; }
- string get_imeSlatkisa(const int &i)const override { return ime[i]; }
- double get_cijenaSlatkisa(const int &i)const override{ return cijena[i]; }
- Slatkisi&operator=(const Slatkisi &that);
- };
- Slatkisi&Slatkisi::operator=(const Slatkisi &that) {
- if (this == &that) {
- return *this;
- }
- amount = that.amount;
- ime = new string[amount];
- copy(that.ime, that.ime + that.amount, ime);
- cijena = that.cijena;
- return *this;
- }
- class AlkoholnaPica :public I_Drinks {
- public:
- AlkoholnaPica() {
- amount = 4;
- ime = new string[amount];
- cijena = new double[amount];
- ime[0] = " Heineken 0.3 "; cijena[0] = 3.50;
- ime[1] = " Desperados 0.5 "; cijena[1] = 3.50;
- ime[2] = "Trojka Vodka 0.02"; cijena[2] = 4.50;
- ime[3] = "Jack Daniels 0.02"; cijena[3] = 5.50;
- }
- ~AlkoholnaPica() {
- delete[] ime; ime = nullptr;
- delete[]cijena; cijena = nullptr;
- }
- void print_drinks()const override {
- cout << " ----------------------------------- \n";
- cout << "| ALKOHOLNA PICA |\n ";
- cout << " ----------------------------------- \n";
- for (int i = 0; i < amount; i++) {
- cout << "|" << "[" << i + 1 << "] " << get_ime_pica(i) << " | " << get_cijena(i) << " KM " << setw(5) << "|" << endl;
- cout << " ----------------------------------- \n";
- }
- cout << "Unesite[1,2,3,4]za dodavanje na racun\n";
- cout << "-------------------------------------\n";
- cout << " Unesite 0 za povratak na MENU\n";
- cout << "-------------------------------------\n";
- }
- int get_amount()const { return amount; }
- string get_ime_pica(const int &i)const override { return ime[i]; }
- double get_cijena(const int &i)const override { return cijena[i]; }
- AlkoholnaPica&operator=(const AlkoholnaPica&that);
- };
- AlkoholnaPica&AlkoholnaPica::operator=(const AlkoholnaPica &that) {
- if (this == &that) {
- return *this;
- }
- amount = that.amount;
- ime = new string[amount];
- copy(that.ime, that.ime + that.amount, ime);
- cijena = that.cijena;
- return *this;
- }
- class TopliNapici : public I_Drinks {
- public:
- TopliNapici() {
- amount = 4;
- ime = new string[amount];
- cijena = new double[amount];
- ime[0] = " Espresso "; cijena[0] = 1.50;
- ime[1] = " Cappuccino "; cijena[1] = 2.50;
- ime[2] = "Topla Cokolada"; cijena[2] = 2.50;
- ime[3] = " Caj "; cijena[3] = 1.50;
- }
- ~TopliNapici() {
- delete[] ime; ime = nullptr;
- delete[]cijena; cijena = nullptr;
- }
- void print_drinks()const override {
- cout << " ----------------------------------- \n";
- cout << "| TOPLI NAPICI |\n ";
- cout << " ----------------------------------- \n";
- for (int i = 0; i < amount; i++) {
- cout << "|" << "[" << i + 1 << "] " << get_ime_pica(i) << " | " << get_cijena(i) << " KM " << setw(5) << "|" << endl;
- cout << " ----------------------------------- \n";
- }
- cout << "Unesite[1,2,3,4]za dodavanje na racun\n";
- cout << "-------------------------------------\n";
- cout << " Unesite 0 za povratak na MENU\n";;
- cout << "-------------------------------------\n";
- }
- int get_amount()const { return amount; }
- string get_ime_pica(const int &i)const override { return ime[i]; }
- double get_cijena(const int &i)const override { return cijena[i]; }
- TopliNapici&operator=(const TopliNapici &that);
- };
- TopliNapici&TopliNapici::operator=(const TopliNapici &that) {
- if (this == &that) {
- return *this;
- }
- amount = that.amount;
- ime = new string[amount];
- copy(that.ime, that.ime + that.amount, ime);
- cijena = that.cijena;
- return *this;
- }
- class BezalkoholniNapici : public I_Drinks {
- public:
- BezalkoholniNapici() {
- amount = 4;
- ime = new string[amount];
- cijena = new double[amount];
- ime[0] = " Coca Cola "; cijena[0] = 2.50;
- ime[1] = " Fanta "; cijena[1] = 2.50;
- ime[2] = " Schweppes "; cijena[2] = 2.50;
- ime[3] = " Sprite "; cijena[3] = 2.50;
- }
- ~BezalkoholniNapici() {
- delete[] ime; ime = nullptr;
- delete[]cijena; cijena = nullptr;
- }
- void print_drinks()const override {
- cout << " ----------------------------------- \n";
- cout << "| BEZALKOHOLNA PICA |\n ";
- cout << " ----------------------------------- \n";
- for (int i = 0; i < amount; i++) {
- cout << "|" << "[" << i + 1 << "] " << get_ime_pica(i) << " | " << get_cijena(i) << " KM " << setw(5) << "|" << endl;
- cout << " ----------------------------------- \n";
- }
- cout << "Unesite[1,2,3,4]za dodavanje na racun\n";
- cout << "-------------------------------------\n";
- cout << " Unesite 0 za povratak na MENU\n";
- cout << "-------------------------------------\n";
- }
- int get_amount()const { return amount; }
- string get_ime_pica(const int &i)const override { return ime[i]; }
- double get_cijena(const int &i)const override { return cijena[i]; }
- BezalkoholniNapici&operator=(const BezalkoholniNapici &that);
- };
- BezalkoholniNapici&BezalkoholniNapici::operator=(const BezalkoholniNapici &that) {
- if (this == &that) {
- return *this;
- }
- amount = that.amount;
- ime = new string[amount];
- copy(that.ime, that.ime + that.amount, ime);
- cijena = that.cijena;
- return *this;
- }
- class Racun {
- public:
- Racun() :
- toplinapici{ nullptr }, alkoholonapica{ nullptr }, bezalkoholnapica{ nullptr }, slatkisi{ nullptr }, sadrzaj_racuna{ nullptr }, brojac{ 0 },izbor{ -1 }, ukupna_cijena{ 0 }{
- sadrzaj_racuna = new string[50];
- for (int i = 0; i < 50; i++) {
- sadrzaj_racuna[i] = "";
- }
- toplinapici = new TopliNapici;
- alkoholonapica = new AlkoholnaPica;
- bezalkoholnapica = new BezalkoholniNapici;
- slatkisi = new Slatkisi;
- }
- ~Racun() {
- delete toplinapici; toplinapici = nullptr;
- delete alkoholonapica; alkoholonapica = nullptr;
- delete bezalkoholnapica; bezalkoholnapica = nullptr;
- delete slatkisi; slatkisi = nullptr;
- delete[] sadrzaj_racuna; sadrzaj_racuna = nullptr;
- }
- string generisi_trenutno_vrijeme() {
- auto trenutno_vrijeme = chrono::system_clock::to_time_t(chrono::system_clock::now());
- return (string)ctime(&trenutno_vrijeme);
- }
- void set_Racun_TopliNapici() {
- izbor = -1;
- toplinapici->print_drinks();
- try {
- while (izbor != 0) {
- cout << "Unesite pice na racun(1,2,3,4): "; cin >> izbor;
- if (izbor == 0)
- throw 0;
- cout << "Na racun dodan: " << toplinapici->get_ime_pica(get_izbor() - 1) << endl;
- ukupna_cijena += toplinapici->get_cijena(get_izbor() - 1);
- sadrzaj_racuna[brojac] = toplinapici->get_ime_pica(get_izbor() - 1) + " " + to_string(toplinapici->get_cijena(get_izbor() - 1)) + "KM";
- brojac++;
- }
- }
- catch (...) {
- cout << "----------------------------------\n";
- cout << "Za ispis racuna odaberite opciju 5" << endl;
- cout << "----------------------------------\n";
- }
- }
- void set_Racun_AlkoholniNapici() {
- izbor = -1;
- alkoholonapica->print_drinks();
- try {
- while (izbor != 0) {
- cout << "Unesite pice na racun(1,2,3,4): "; cin >> izbor;
- if (izbor == 0)
- throw 0;
- cout << "Na racun dodan: " << alkoholonapica->get_ime_pica(get_izbor() - 1) << endl;
- ukupna_cijena += alkoholonapica->get_cijena(get_izbor() - 1);
- sadrzaj_racuna[brojac] = alkoholonapica->get_ime_pica(get_izbor() - 1) + " " + to_string(alkoholonapica->get_cijena(get_izbor() - 1)) + "KM";
- brojac++;
- }
- }
- catch (...) {
- cout << "----------------------------------\n";
- cout << "Za ispis racuna odaberite opciju 5" << endl;
- cout << "----------------------------------\n";
- }
- }
- void set_Racun_BezalkoholniNapici() {
- izbor = -1;
- bezalkoholnapica->print_drinks();
- try {
- while (izbor != 0) {
- cout << "Unesite pice na racun(1,2,3,4): "; cin >> izbor;
- if (izbor == 0)
- throw 0;
- cout << "Na racun dodan: " << bezalkoholnapica->get_ime_pica(get_izbor() - 1) << endl;
- ukupna_cijena += bezalkoholnapica->get_cijena(get_izbor() - 1);
- sadrzaj_racuna[brojac] = bezalkoholnapica->get_ime_pica(get_izbor() - 1) + " " + to_string(bezalkoholnapica->get_cijena(get_izbor() - 1)) + "KM";
- brojac++;
- }
- }
- catch (...) {
- cout << "----------------------------------\n";
- cout << "Za ispis racuna odaberite opciju 5" << endl;
- cout << "----------------------------------\n";
- }
- }
- void set_Racun_Slatkisi() {
- izbor = -1;
- slatkisi->print_SlatkiKutak();
- try {
- while (izbor != 0) {
- cout << "Unesite pice na racun(1,2,3,4): "; cin >> izbor;
- if (izbor == 0)
- throw 0;
- cout << "Na racun dodan: " <<slatkisi->get_imeSlatkisa(get_izbor() - 1) << endl;
- ukupna_cijena += slatkisi->get_cijenaSlatkisa(get_izbor() - 1);
- sadrzaj_racuna[brojac] = slatkisi->get_imeSlatkisa(get_izbor() - 1) + " " + to_string(slatkisi->get_cijenaSlatkisa(get_izbor() - 1)) + "KM";
- brojac++;
- }
- }
- catch (...) {
- cout << "----------------------------------\n";
- cout << "Za ispis racuna odaberite opciju 5" << endl;
- cout << "----------------------------------\n";
- }
- }
- void ispisi_racun() {
- if (get_ukupnaCijena() == 0) {
- cout << "------------------------------------------\n";
- cout << "Niste otkucali niti jedan artikal na racun! " << endl;
- cout << "------------------------------------------\n";
- }
- else {
- ofstream unesi_u_datoteku("racuni.txt", ios::app);
- cout << "-----------------------------------------------------\n";
- unesi_u_datoteku<< "-----------------------------------------------------\n";
- cout << " Datum izdavanja racuna: " << generisi_trenutno_vrijeme();
- unesi_u_datoteku << " Datum izdavanja racuna: "<<generisi_trenutno_vrijeme() << endl;
- cout << "-----------------------------------------------------\n";
- unesi_u_datoteku<< "-----------------------------------------------------\n";
- for (int i = 0; i < brojac; i++) {
- unesi_u_datoteku << sadrzaj_racuna[i] << endl;
- cout << setw(35) << sadrzaj_racuna[i] << endl;
- unesi_u_datoteku<< " -----------------------------------------\n";
- cout << " -----------------------------------------\n";
- }
- unesi_u_datoteku<<setw(30)<< "Racun iznosi: " << get_ukupnaCijena() << " KM" << endl;
- cout << setw(30) << "Racun iznosi: " << get_ukupnaCijena() << " KM" << endl;
- unesi_u_datoteku << " -----------------------------------------\n";
- cout << " -----------------------------------------\n";
- }
- }
- int get_izbor()const { return izbor; }
- double get_ukupnaCijena()const { return ukupna_cijena; }
- Racun&operator=(const Racun &that);
- private:
- I_Drinks *toplinapici;
- I_Drinks *alkoholonapica;
- I_Drinks *bezalkoholnapica;
- I_SlatkiKutak *slatkisi;
- string *sadrzaj_racuna;
- int brojac;
- int izbor;
- mutable double ukupna_cijena;
- };
- Racun&Racun::operator=(const Racun &that) {
- if (this == &that) {
- return *this;
- }
- toplinapici = new TopliNapici;toplinapici = that.toplinapici;
- alkoholonapica = new AlkoholnaPica;alkoholonapica = that.alkoholonapica;
- bezalkoholnapica = new BezalkoholniNapici;bezalkoholnapica = that.bezalkoholnapica;
- slatkisi = new Slatkisi; slatkisi = that.slatkisi;
- brojac = that.brojac;
- sadrzaj_racuna = new string[brojac];
- copy(that.sadrzaj_racuna,that.sadrzaj_racuna+that.brojac,sadrzaj_racuna);
- izbor = that.izbor;
- ukupna_cijena = that.ukupna_cijena;
- return *this;
- }
- struct node {
- Racun racun;
- node *next;
- };
- int menu() {
- int izbor;
- do {
- cout << "----------------------------------------\n";
- cout << " MINI BAR MENU \n";
- cout << "----------------------------------------\n";
- cout << "1) Dodaj na racun (Topli napici) \n";
- cout << "2) Dodaj na racun (Alkoholni napici)\n";
- cout << "3) Dodaj na racun (Bezalhoholni napici)\n";
- cout << "4) Dodaj na racun (Slatki Kutak)\n";
- cout << "5) ISPISI RACUN\n";
- cout << "----------------------------------------\n";
- cout << "Unesite izbor: "; cin >> izbor;
- return izbor;
- system("pause"); system("cls");
- } while (1);
- }
- class Kasa {
- public:
- Kasa():
- head{ nullptr }, tail{ nullptr }, neto{ 0 }, prosjek_po_racunu{ 0 } {
- string line;
- ifstream neto_check("neto.txt");
- int br = 0;
- while (getline(neto_check, line)) {
- br++;
- }
- neto_check.close();
- neto_check.open("neto.txt");
- if (br != 0) {
- while (getline(neto_check, line)) {
- neto = stoi(line);
- }
- }
- else {
- neto = 0;
- }
- neto_check.close();
- br = 0;
- ifstream brojRacuna_check("broj_izdatih_racuna.txt");
- while (getline(brojRacuna_check, line)) {
- br++;
- }
- brojRacuna_check.close();
- brojRacuna_check.open("broj_izdatih_racuna.txt");
- if (br != 0) {
- while (getline(brojRacuna_check, line)) {
- broj_izdatih_racuna = stoi(line);
- }
- }
- else {
- broj_izdatih_racuna = 0;
- }
- br = 0;
- ifstream cijenaPoRacunu("prosjek_po_racunu.txt");
- while (getline(cijenaPoRacunu, line)) {
- br++;
- }
- cijenaPoRacunu.close();
- cijenaPoRacunu.open("prosjek_po_racunu.txt");
- if (br != 0) {
- while (getline(cijenaPoRacunu, line)) {
- prosjek_po_racunu = stoi(line);
- }
- }
- }
- ~Kasa() {
- node *t1 = head; node *t2 = nullptr;
- while (t1 != head) {
- t2 = t1->next;
- delete t1;
- t1 = t2;
- }
- }
- void set_Novi_Racun() {
- broj_izdatih_racuna++;
- ofstream broj_izdatih_racuna("broj_izdatih_racuna.txt");
- broj_izdatih_racuna << get_broj_izdatihRacuna();
- int izbor;
- node *temp = new node;
- temp->next = nullptr;
- if (head == nullptr) {
- head = temp;
- tail = temp;
- }
- else {
- tail->next = temp;
- tail = temp;
- }
- do {
- izbor = menu();
- if (izbor < 1 || izbor>5) {
- break;
- }
- if (izbor == 1) {
- temp->racun.set_Racun_TopliNapici();
- system("pause"); system("cls");
- }
- if (izbor == 2) {
- temp->racun.set_Racun_AlkoholniNapici();
- system("pause"); system("cls");
- }
- if (izbor == 3) {
- temp->racun.set_Racun_BezalkoholniNapici();
- system("pause"); system("cls");
- }
- if (izbor == 4) {
- temp->racun.set_Racun_Slatkisi();
- system("pause"); system("cls");
- }
- if (izbor == 5) {
- try {
- throw 0;
- }
- catch (...) {
- ofstream unesi_neto("neto.txt");
- temp->racun.ispisi_racun();
- neto +=temp->racun.get_ukupnaCijena();
- unesi_neto << get_Neto();
- ofstream prosjekpoRacunu("prosjek_po_racunu.txt");
- prosjek_po_racunu=get_Neto() / get_broj_izdatihRacuna();
- prosjekpoRacunu << get_prosjekPoRacunu();
- system("pause"); system("cls");
- }
- break;
- }
- } while (1);
- }
- double get_Neto()const { return neto; }
- int get_broj_izdatihRacuna()const { return broj_izdatih_racuna; }
- double get_prosjekPoRacunu()const { return prosjek_po_racunu; }
- Kasa &operator=(const Kasa &that);
- private:
- node *head, *tail;
- mutable double neto;
- static int broj_izdatih_racuna;
- mutable double prosjek_po_racunu;
- };
- int Kasa::broj_izdatih_racuna{ 0 };
- Kasa&Kasa::operator=(const Kasa &that) {
- if (this == &that) {
- return *this;
- }
- head = new node;head = that.head;
- tail = new node; tail = that.tail;
- neto = that.neto;
- broj_izdatih_racuna = that.broj_izdatih_racuna;
- prosjek_po_racunu = that.prosjek_po_racunu;
- return *this;
- }
- int Main_Menu() {
- int izbor;
- do {
- cout << "-----------------------------------\n";
- cout << " MAIN MENU \n";
- cout << "-----------------------------------\n";
- cout << "1) Otkucaj racun\n";
- cout << "2) Ispisi broj izdazih racuna\n";
- cout << "3) Ispisi ukpnu neto zaradu\n";
- cout << "4) Ipisi prosjecnu zaradu po racunu\n";
- cout << "5) KRAJ\n";
- cout << "-----------------------------------\n";
- cout << "Unesite izbor: "; cin >> izbor;
- return izbor;
- system("pause"); system("cls");
- } while (1);
- }
- int main() {
- int IZBOR;
- Kasa kasa;
- do {
- IZBOR = Main_Menu();
- if (IZBOR < 1 || IZBOR>4) {
- break;
- }
- if (IZBOR == 1) {
- system("pause"); system("cls");
- kasa.set_Novi_Racun();
- }
- if (IZBOR == 2) {
- cout << "-----------------------------\n";
- cout << "Broj izdatih racuna: " << kasa.get_broj_izdatihRacuna() << endl;
- cout << "-----------------------------\n";
- system("pause"); system("cls");
- }
- if (IZBOR == 3) {
- cout << "------------------------------------\n";
- cout << "Ukupna zarada iznosi: " << kasa.get_Neto() << " KM"<< endl;
- cout << "------------------------------------\n";
- system("pause"); system("cls");
- }
- if (IZBOR == 4) {
- cout << "--------------------------------------------------\n";
- cout << "Prosjecna zarada po jednom racunu iznosi: " << kasa.get_prosjekPoRacunu() << " KM"<<endl;
- cout << "--------------------------------------------------\n";
- system("pause"); system("cls");
- }
- } while (1);
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment