pjobro

bankom iv

Apr 8th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.84 KB | None | 0 0
  1. ////HEDER RACUN
  2. #pragma once
  3. #ifndef RACUN_H
  4. #define RACUN_H
  5.  
  6. #include <string>
  7.  
  8. class Racun {
  9. private:
  10.     long int broj_racuna;
  11.     double stanje;
  12.  
  13. public:
  14.     // konstruktor
  15.     Racun();
  16.  
  17.     // seteri
  18.     void set_broj_racuna(int b);
  19.     void set_stanje(double s);
  20.  
  21.     // geteri
  22.     int get_broj_racuna();
  23.     double get_stanje();
  24.  
  25.     // funkcije
  26.     void stanje_racuna();
  27. };
  28.  ////HEDER KORISNIK
  29. #endif // !RACUN_H
  30.  
  31. #ifndef KORISNIK_H
  32. #define KORSINIK_H
  33.  
  34. #include "Racun.h"
  35. #include "FileIO.h"
  36. #include <string>
  37.  
  38. class Korisnik {
  39. private:
  40.     std::string username;
  41.     std::string password;
  42.     std::string ime;
  43.     std::string prezime;
  44.     Racun racun;
  45.     FileIO baza;
  46. public:
  47.     // konstruktor
  48.     Korisnik();
  49.     ~Korisnik();
  50.  
  51.     // seteri
  52.     void set_username(std::string un);
  53.     void set_password(std::string pw);
  54.     void set_ime(std::string i);
  55.     void set_prezime(std::string p);
  56.  
  57.     // geteri
  58.     std::string get_username();
  59.     std::string get_password();
  60.     std::string get_ime();
  61.     std::string get_prezime();
  62.  
  63.     // funkcije
  64.     bool login();
  65.     void podigni_novac();
  66.     void prikazi_stanje();
  67.  
  68. };
  69.  
  70. #endif // !F
  71.  
  72. //////HEDER FILE...
  73. #pragma once
  74. #ifndef FILEIO_H
  75. #define FILEIO_H
  76.  
  77. #include <string>
  78. #include <vector>
  79. #include <array>
  80.  
  81. class FileIO {
  82. private:
  83.     std::array <std::string, 6> current;
  84.     std::vector <std::array <std::string, 6>> podaci;
  85. public:
  86.     // funkcije
  87.     bool find_and_load_data(std::string file, std::string kor_ime, std::string sifra);
  88.     void save_data(std::string file);
  89.  
  90.     // postavljanje podataka
  91.     void set_novo_stanje(double stanje);
  92.  
  93.     // dohvacanje podataka o korisniku i racunu
  94.     std::string get_un();
  95.     std::string get_pw();
  96.     std::string get_i();
  97.     std::string get_p();
  98.     int get_br_rac();
  99.     double get_st();
  100. };
  101.  
  102. #endif // !FILEIO_H
  103. ////RACUN CPP
  104. #include "stdafx.h"
  105. #include "Racun.h"
  106. #include <iostream>
  107.  
  108. Racun::Racun() {
  109. }
  110. void Racun::set_broj_racuna(int b) {
  111.     broj_racuna = b;
  112. }
  113. void Racun::set_stanje(double s) {
  114.     stanje = s;
  115. }
  116.  
  117. // geteri
  118. int Racun::get_broj_racuna() {
  119.     return broj_racuna;
  120. }
  121. double Racun::get_stanje() {
  122.     return stanje;
  123. }
  124.  
  125. // funkcije
  126. void Racun::stanje_racuna() {
  127.     std::cout << "\nNa racunu imate " << get_stanje() << " kuna.\n";
  128. }
  129. ///KORISNIK
  130. #include "stdafx.h"
  131. #include "Korisnik.h"
  132. #include "Racun.h"
  133. #include <iostream>
  134.  
  135. // konstruktor
  136. Korisnik::Korisnik() {
  137. }
  138.  
  139. Korisnik::~Korisnik() {
  140.     baza.save_data("Racuni.txt");
  141. }
  142.  
  143. // seteri
  144. void Korisnik::set_username(std::string un) {
  145.     username = un;
  146. }
  147. void Korisnik::set_password(std::string pw) {
  148.     password = pw;
  149. }
  150. void Korisnik::set_ime(std::string i) {
  151.     ime = ime;
  152. }
  153. void Korisnik::set_prezime(std::string p) {
  154.     prezime = prezime;
  155. }
  156.  
  157. // geteri
  158. std::string Korisnik::get_username() {
  159.     return username;
  160. }
  161. std::string Korisnik::get_password() {
  162.     return password;
  163. }
  164. std::string Korisnik::get_ime() {
  165.     return ime;
  166. }
  167. std::string Korisnik::get_prezime() {
  168.     return prezime;
  169. }
  170.  
  171. // funkcije
  172. bool Korisnik::login() {
  173.     std::string ime, sifra;
  174.     bool uspjeh;
  175.     std::cout << "Unesite korisnicko ime: ";
  176.     std::cin >> ime;
  177.     std::cout << "Unesite lozinku: ";
  178.     std::cin >> sifra;
  179.     uspjeh = baza.find_and_load_data("Racuni.txt", ime, sifra);
  180.     if (uspjeh) {
  181.         set_username(baza.get_un());
  182.         set_password(baza.get_pw());
  183.         set_ime(baza.get_i());
  184.         set_prezime(baza.get_p());
  185.         racun.set_broj_racuna(baza.get_br_rac());
  186.         racun.set_stanje(baza.get_st());
  187.     }
  188.     else {
  189.         std::cout << "\nUnijeli ste pogrešne podatke!\n";
  190.         system("pause");
  191.     }
  192.     return uspjeh;
  193. }
  194.  
  195. void Korisnik::podigni_novac() {
  196.     int iznos;
  197.     std::cout << "Koliko novca zelite podignuti: ";
  198.     std::cin >> iznos;
  199.     racun.set_stanje(racun.get_stanje() - iznos);
  200.     baza.set_novo_stanje(racun.get_stanje());
  201.     std::cout << "\Podigli ste " << iznos << " kuna.\n";
  202. }
  203.  
  204. void Korisnik::prikazi_stanje() {
  205.     std::cout << "Na racunu " << racun.get_broj_racuna() <<
  206.         " imate " << racun.get_stanje() << " kuna\n";
  207. }
  208. ///NESTO
  209. #include "stdafx.h"
  210. #include "FileIO.h"
  211. #include "Racun.h"
  212. #include "Korisnik.h"
  213. #include <fstream>
  214. #include <string>
  215. #include <array>
  216. #include <iostream>
  217.  
  218. bool FileIO::find_and_load_data(std::string file, std::string kor_ime, std::string sifra) {
  219.     std::ifstream input(file);
  220.     bool uspjeh = false;
  221.     std::array <std::string, 6> a;
  222.     while (!input.eof()) {
  223.         input >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5];
  224.         if (a[0] == kor_ime && a[1] == sifra) {
  225.             for (int i = 0; i < 6; i++) {
  226.                 current[i] = a[i];
  227.             }
  228.             uspjeh = true;
  229.         }
  230.         else {
  231.             podaci.push_back(a);
  232.         }
  233.     }
  234.     input.close();
  235.     return uspjeh;
  236. }
  237.  
  238. void FileIO::save_data(std::string file) {
  239.     std::ofstream output;
  240.     output.open(file, std::ios::out | std::ios::app | std::ios::trunc);
  241.     std::string za_unos;
  242.     podaci.push_back(current);
  243.     for (int i = 0; i < podaci.size(); i++) {
  244.         za_unos = podaci[i][0] + " " + podaci[i][1] + " " + podaci[i][2] + " " +
  245.             podaci[i][3] + " " + podaci[i][4] + " " + podaci[i][5] + "\n";
  246.         output << za_unos;
  247.     }
  248.     output.close();
  249. }
  250.  
  251. void FileIO::set_novo_stanje(double stanje) {
  252.     current[5] = std::to_string(stanje);
  253.     std::cout << current[5];
  254. }
  255.  
  256. std::string FileIO::get_un() {
  257.     return current[0];
  258. }
  259.  
  260. std::string FileIO::get_pw() {
  261.     return current[1];
  262. }
  263.  
  264. std::string FileIO::get_i() {
  265.     return current[2];
  266. }
  267.  
  268. std::string FileIO::get_p() {
  269.     return current[3];
  270. }
  271.  
  272. int FileIO::get_br_rac() {
  273.     return std::stoll(current[4]);
  274. }
  275.  
  276. double FileIO::get_st() {
  277.     return std::stod(current[5]);
  278. }
  279. ////ATM
  280. // ATM.cpp : Defines the entry point for the console application.
  281. //
  282.  
  283. #include "stdafx.h"
  284. #include "Korisnik.h"
  285. #include <iostream>
  286. #include <string>
  287.  
  288. using namespace std;
  289.  
  290. int main()
  291. {
  292.     system("cls");
  293.     cout << "Dobrodošli u bankomat!\n";
  294.     cout << "Unesite korisnicko ime i lozinku za prijavu.\n\n";
  295.     Korisnik kor;
  296.     if (kor.login()) {
  297.         int izbor;
  298.         do {
  299.             cout << "\n1 - pregled stanja racuna\n2 - Isplata\n0 - Izlaz\n";
  300.             cout << "Sto zelite: ";
  301.             cin >> izbor;
  302.             switch (izbor)
  303.             {
  304.             case 1:
  305.                 kor.prikazi_stanje();
  306.                 break;
  307.             case 2:
  308.                 kor.podigni_novac();
  309.                 break;
  310.             case 0:
  311.                 break;
  312.             default:
  313.                 cout << "Unijeli ste pogrešan unos!\n";
  314.                 break;
  315.             }
  316.         } while (izbor != 0);
  317.     }
  318.     return 0;
  319. }
Add Comment
Please, Sign In to add comment