Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////HEDER RACUN
- #pragma once
- #ifndef RACUN_H
- #define RACUN_H
- #include <string>
- class Racun {
- private:
- long int broj_racuna;
- double stanje;
- public:
- // konstruktor
- Racun();
- // seteri
- void set_broj_racuna(int b);
- void set_stanje(double s);
- // geteri
- int get_broj_racuna();
- double get_stanje();
- // funkcije
- void stanje_racuna();
- };
- ////HEDER KORISNIK
- #endif // !RACUN_H
- #ifndef KORISNIK_H
- #define KORSINIK_H
- #include "Racun.h"
- #include "FileIO.h"
- #include <string>
- class Korisnik {
- private:
- std::string username;
- std::string password;
- std::string ime;
- std::string prezime;
- Racun racun;
- FileIO baza;
- public:
- // konstruktor
- Korisnik();
- ~Korisnik();
- // seteri
- void set_username(std::string un);
- void set_password(std::string pw);
- void set_ime(std::string i);
- void set_prezime(std::string p);
- // geteri
- std::string get_username();
- std::string get_password();
- std::string get_ime();
- std::string get_prezime();
- // funkcije
- bool login();
- void podigni_novac();
- void prikazi_stanje();
- };
- #endif // !F
- //////HEDER FILE...
- #pragma once
- #ifndef FILEIO_H
- #define FILEIO_H
- #include <string>
- #include <vector>
- #include <array>
- class FileIO {
- private:
- std::array <std::string, 6> current;
- std::vector <std::array <std::string, 6>> podaci;
- public:
- // funkcije
- bool find_and_load_data(std::string file, std::string kor_ime, std::string sifra);
- void save_data(std::string file);
- // postavljanje podataka
- void set_novo_stanje(double stanje);
- // dohvacanje podataka o korisniku i racunu
- std::string get_un();
- std::string get_pw();
- std::string get_i();
- std::string get_p();
- int get_br_rac();
- double get_st();
- };
- #endif // !FILEIO_H
- ////RACUN CPP
- #include "stdafx.h"
- #include "Racun.h"
- #include <iostream>
- Racun::Racun() {
- }
- void Racun::set_broj_racuna(int b) {
- broj_racuna = b;
- }
- void Racun::set_stanje(double s) {
- stanje = s;
- }
- // geteri
- int Racun::get_broj_racuna() {
- return broj_racuna;
- }
- double Racun::get_stanje() {
- return stanje;
- }
- // funkcije
- void Racun::stanje_racuna() {
- std::cout << "\nNa racunu imate " << get_stanje() << " kuna.\n";
- }
- ///KORISNIK
- #include "stdafx.h"
- #include "Korisnik.h"
- #include "Racun.h"
- #include <iostream>
- // konstruktor
- Korisnik::Korisnik() {
- }
- Korisnik::~Korisnik() {
- baza.save_data("Racuni.txt");
- }
- // seteri
- void Korisnik::set_username(std::string un) {
- username = un;
- }
- void Korisnik::set_password(std::string pw) {
- password = pw;
- }
- void Korisnik::set_ime(std::string i) {
- ime = ime;
- }
- void Korisnik::set_prezime(std::string p) {
- prezime = prezime;
- }
- // geteri
- std::string Korisnik::get_username() {
- return username;
- }
- std::string Korisnik::get_password() {
- return password;
- }
- std::string Korisnik::get_ime() {
- return ime;
- }
- std::string Korisnik::get_prezime() {
- return prezime;
- }
- // funkcije
- bool Korisnik::login() {
- std::string ime, sifra;
- bool uspjeh;
- std::cout << "Unesite korisnicko ime: ";
- std::cin >> ime;
- std::cout << "Unesite lozinku: ";
- std::cin >> sifra;
- uspjeh = baza.find_and_load_data("Racuni.txt", ime, sifra);
- if (uspjeh) {
- set_username(baza.get_un());
- set_password(baza.get_pw());
- set_ime(baza.get_i());
- set_prezime(baza.get_p());
- racun.set_broj_racuna(baza.get_br_rac());
- racun.set_stanje(baza.get_st());
- }
- else {
- std::cout << "\nUnijeli ste pogrešne podatke!\n";
- system("pause");
- }
- return uspjeh;
- }
- void Korisnik::podigni_novac() {
- int iznos;
- std::cout << "Koliko novca zelite podignuti: ";
- std::cin >> iznos;
- racun.set_stanje(racun.get_stanje() - iznos);
- baza.set_novo_stanje(racun.get_stanje());
- std::cout << "\Podigli ste " << iznos << " kuna.\n";
- }
- void Korisnik::prikazi_stanje() {
- std::cout << "Na racunu " << racun.get_broj_racuna() <<
- " imate " << racun.get_stanje() << " kuna\n";
- }
- ///NESTO
- #include "stdafx.h"
- #include "FileIO.h"
- #include "Racun.h"
- #include "Korisnik.h"
- #include <fstream>
- #include <string>
- #include <array>
- #include <iostream>
- bool FileIO::find_and_load_data(std::string file, std::string kor_ime, std::string sifra) {
- std::ifstream input(file);
- bool uspjeh = false;
- std::array <std::string, 6> a;
- while (!input.eof()) {
- input >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5];
- if (a[0] == kor_ime && a[1] == sifra) {
- for (int i = 0; i < 6; i++) {
- current[i] = a[i];
- }
- uspjeh = true;
- }
- else {
- podaci.push_back(a);
- }
- }
- input.close();
- return uspjeh;
- }
- void FileIO::save_data(std::string file) {
- std::ofstream output;
- output.open(file, std::ios::out | std::ios::app | std::ios::trunc);
- std::string za_unos;
- podaci.push_back(current);
- for (int i = 0; i < podaci.size(); i++) {
- za_unos = podaci[i][0] + " " + podaci[i][1] + " " + podaci[i][2] + " " +
- podaci[i][3] + " " + podaci[i][4] + " " + podaci[i][5] + "\n";
- output << za_unos;
- }
- output.close();
- }
- void FileIO::set_novo_stanje(double stanje) {
- current[5] = std::to_string(stanje);
- std::cout << current[5];
- }
- std::string FileIO::get_un() {
- return current[0];
- }
- std::string FileIO::get_pw() {
- return current[1];
- }
- std::string FileIO::get_i() {
- return current[2];
- }
- std::string FileIO::get_p() {
- return current[3];
- }
- int FileIO::get_br_rac() {
- return std::stoll(current[4]);
- }
- double FileIO::get_st() {
- return std::stod(current[5]);
- }
- ////ATM
- // ATM.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "Korisnik.h"
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- system("cls");
- cout << "Dobrodošli u bankomat!\n";
- cout << "Unesite korisnicko ime i lozinku za prijavu.\n\n";
- Korisnik kor;
- if (kor.login()) {
- int izbor;
- do {
- cout << "\n1 - pregled stanja racuna\n2 - Isplata\n0 - Izlaz\n";
- cout << "Sto zelite: ";
- cin >> izbor;
- switch (izbor)
- {
- case 1:
- kor.prikazi_stanje();
- break;
- case 2:
- kor.podigni_novac();
- break;
- case 0:
- break;
- default:
- cout << "Unijeli ste pogrešan unos!\n";
- break;
- }
- } while (izbor != 0);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment