Professional Documents
Culture Documents
Objektno-Orjentisano Programiranje Zadaca 1 (C ++)
Objektno-Orjentisano Programiranje Zadaca 1 (C ++)
Elektrotehnika
Informatika
OBJEKTNO-ORJENTISANO PROGRAMIRANJE
ZADAA 1
Asistent:
Adnan Ramaki, mr.ra. i inf.
Student:
Hasan Bapi 748
Biha, Decembar 2014.
#include<iostream>
#include<fstream>
#include<string>
#include<stdlib.h>
using namespace std;
class Banka{
public:
bool Administrator1(string&);
bool Administrator2(string&);
void IspisKlijenata();
void UnosKlijenta();
int RedniBroj();
int BrojKlijenta(string&);
int BrojKlijentaPoImenu(string&);
int BrojKlijentaPoRacunu(string&);
void BrisiKlijenta1();
void BrisiKlijenta2();
bool Klijent1(string&);
bool Klijent2(string&);
void StanjeRacuna(string&);
void PolaganjeDepozita(string&);
void PodizanjeNovca(string&);
};
bool Banka::Administrator1(string & username){
fstream d;
string s[4];
d.open("admin.txt", ios_base::in);
while(d.eof()!=true)
{
}}
return false;
d.close(); }
bool Banka::Administrator2(string & password){
fstream d;
string s[4];
d.open("admin.txt", ios_base::in);
while(d.eof()!=true){
for(int i=0; i<4; i++){
getline(d,s[i]);
if(s[i]==password){
return true;}}
return false; }
d.close(); }
void Banka::IspisKlijenata(){
fstream f;
string linija[8];
int br=0;
f.open("klijenti.txt", ios_base::in);
while(!f.eof()){
for(int i=0; i<8; i++){
getline(f, linija[i]);
if(i!=6 && i!=7){
cout<<linija[i]<<" "; }}
cout<<endl; }
f.close(); }
int Banka::RedniBroj(){
fstream d;
string s[8];
int br=0;
int rbr;
d.open("klijenti.txt", ios_base::in);
while(d.eof()!=true) {
for(int i=0; i<8; i++){
getline(d,s[i]),
br++; }}
rbr= atoi(s[0].c_str());
return rbr; }
int Banka::BrojKlijenta(string &username){
fstream d;
string s[8];
int vrati;
d.open("klijenti.txt", ios_base::in);
while(d.eof()!=true){
for(int i=0; i<8; i++){
getline(d,s[i]);
if(s[i]==username){
vrati= atoi(s[0].c_str());
return vrati;}}}}
int Banka::BrojKlijentaPoImenu(string &Ime){
fstream d;
string s[8];
int vrati;
d.open("klijenti.txt", ios_base::in);
while(d.eof()!=true){
d.open("klijenti.txt",ios_base::out|ios_base::app);
d<<endl;
d<<a<<".";
cout<<"Unesite ime"<<endl;
cin>>Ime;
d<<endl;
d<<Ime;
cout<<"Unesite prezime"<<endl;
cin>>Prezime;
d<<endl;
d<<Prezime;
cout<<"Unesite adresu bez kucnog broja"<<endl;
cin>>Adresa;
cout<<"Unesite kucni broj"<<endl;
cin>>broj;
d<<endl;
d<<Adresa<<" "<<broj<<".";
cout<<"Unesite broj racuna"<<endl;
cin>>BrojRacuna;
d<<endl;
d<<BrojRacuna;
cout<<"Unesite stanje na racunu"<<endl;
cin>>StanjeNaRacunu;
d<<endl;
d<<StanjeNaRacunu;
cout<<"Unesite korisnicko ime"<<endl;
cin>>KorisnickoIme;
d<<endl;
d<<KorisnickoIme;
cout<<"Unesite sifru"<<endl;
cin>>sifra;
d<<endl;
d<<sifra;
d.close(); }
void Banka::BrisiKlijenta1(){
fstream d;
string Ime;
string st;
int zastava=0;
Banka b;
F:
cout<<endl;
string s1[br];
d.open("klijenti.txt", ios_base::in);
int i=0;
while(d.eof()!=true){
getline(d,s1[i]);
i++; }
d.close();
for(int i=0; i<br; i++) {
if(i==broj-1){
for(int j=(broj-1)*8; j<broj*8; j++){
s1[j].clear(); }}}
string s3="";
int n=1;
char string[10];
for(int i=0; i<br; i=i+8){
if(s1[i]!=s3){
s1[i].clear();
itoa(n,string,10);
s1[i]=string;
n=atoi(s1[i].c_str());
n++; }}
d.open("klijenti.txt", ios_base::out| ios_base::trunc);
for(int i=0; i<br-1; i++){
if(s1[i]!=s3){
d<<s1[i]<<endl; }}
d<<s1[br-1];
d.close(); }
else{
cout<<"Unijeli ste pogresno ime.Pokusajte ponovo!"<<endl;
goto F;}}
void Banka::BrisiKlijenta2(){
fstream d;
string BrojRacuna;
string st;
int zastava=0;
Banka b;
T:
cout<<endl;
getline(d,s1[i]);
i++; }
d.close();
for(int i=0; i<br; i++){
if(i==broj-1){
for(int j=(broj-1)*8; j<broj*8; j++){
s1[j].clear(); }}}
string s3="";
int n=1;
char string[10];
for(int i=0; i<br; i=i+8){
if(s1[i]!=s3){
s1[i].clear();
itoa(n,string,10);
s1[i]=string;
n=atoi(s1[i].c_str());
n++; }}
d.open("klijenti.txt", ios_base::out| ios_base::trunc);
for(int i=0; i<br-1; i++){
if(s1[i]!=s3){
d<<s1[i]<<endl; }}
d<<s1[br-1];
d.close(); }
else{
cout<<"Unijeli ste pogresan broj racuna.Pokusajte ponovo!"<<endl;
goto T; }}
bool Banka::Klijent1(string & username){
fstream d;
string s[8];
d.open("klijenti.txt",ios_base::in);
while(d.eof()!=true){
for(int i=0; i<8; i++){
getline(d,s[i]);
if(s[i]==username){
return true; }}}
return false; }
bool Banka::Klijent2(string & password){
fstream d;
string s[8];
d.open("klijenti.txt",ios_base::in);
while(d.eof()!=true){
for(int i=0; i<8; i++){
getline(d,s[i]);
if(s[i]==password){
return true; }}}
return false; }
void Banka::StanjeRacuna(string & username){
fstream d;
string s[8];
d.open("klijenti.txt", ios_base::in);
while(d.eof()!=true){
for(int i=0; i<8; i++){
getline(d,s[i]);
if(s[i]==username){
cout<<"Gospodine "<<s[1]<<", Vase stanje na racunu je : "<<s[5]<<endl;}}}}
void Banka::PolaganjeDepozita(string& username){
fstream d;
int iznos;
int b;
cout<<"Unesite vrijednost novca koju zelite poloziti na racun:"<<endl;
cin>>iznos;
int br=0;
string s[8];
d.open("klijenti.txt", ios_base::in);
while(d.eof()!=true){
for(int i=0; i<8; i++){
getline(d,s[i]);
if(s[i]==username){
b= atoi(s[5].c_str()); }
br++; }}
d.close();
string s1[br];
Banka c;
cout<<"Novi iznos na racunu je : " << iznos+b<<endl;
int k=iznos+b;
char strg [10];
itoa(k,strg,10);
int i=0;
d.open("klijenti.txt",ios_base::in);
while(d.eof()!=true){
getline(d,s1[i]);
i++; }
d.close();
int broj=c.BrojKlijenta(username);
for(int j=0; j<br; j++){
if(j==((broj*8)-3)){
s1[j].clear();
s1[j]=strg; }}
d.open("klijenti.txt", ios_base::out|ios_base::trunc);
for(int i=0; i<br-1; i++){
d<<s1[i]<<"\n";}
d<<s1[br-1];
d.close();}
void Banka::PodizanjeNovca(string &username){
fstream d;
cout<<endl;
E:
cout<<"Unesite iznos koji zelite podignuti sa racuna:"<<endl;
int iznos;
cin>>iznos;
int br=0;
int b;
string s[8];
d.open("klijenti.txt", ios_base::in);
while(d.eof()!=true){
for(int i=0; i<8; i++){
getline(d,s[i]);
if(s[i]==username){
b= atoi(s[5].c_str()); }
br++;
}}
d.close();
Banka c;
if(iznos<b){
int ostatak=b-iznos;
cout<<"Novi iznos na racunu je : " << ostatak<<endl;
char strg [10];
string s1[br];
itoa(ostatak,strg,10);
int i=0;
d.open("klijenti.txt",ios_base::in);
while(d.eof()!=true){
getline(d,s1[i]);
i++; }
d.close();
int broj=c.BrojKlijenta(username);
for(int j=0; j<br; j++){
if(j==((broj*8)-3)){
s1[j].clear();
s1[j]=strg; }}
d.open("klijenti.txt", ios_base::out|ios_base::trunc);
for(int i=0; i<br-1; i++){
d<<s1[i]<<"\n"; }
d<<s1[br-1];
d.close(); }
else{
cout<<"Molimo smanjite cifru!"<<endl;
goto E;}}
int main(){
Banka b;
int odgovor;
int odgovor1;
string username;
string password;
M:
cout<<endl;
cout<<endl;
cout<<endl;
if(a==1){
goto B; }}
else if(odgovor1==2){
cout<<endl;
b.UnosKlijenta();
cout<<endl;
cout<<"Uspjesno ste dodali novog klijenta!"<<endl;
cout<<"Za povratak nazad pritisnute 1 "<<endl;
int a;
cin>>a;
if(a==1){
goto B;}}
else if(odgovor1==3){
cout<<endl;
cout<<"Da li zelite da izbrisete klijenta po:"<<endl;
cout<<"1. imenu"<<endl;
cout<<"2. broju racuna"<<endl;
int od;
cin>>od;
if(od==1){
b.BrisiKlijenta1();
cout<<" Uspjesno ste obrisali klijenta!"<<endl;
cout<<"Za povratak nazad pritisnute 1 "<<endl;
int a;
cin>>a;
if(a==1){
goto B;}}
else if(od==2){
b.BrisiKlijenta2();
cout<<endl;
b.StanjeRacuna(username);
cout<<endl;
cout<<"Za povratak nazad pritisnute 1 "<<endl;
int a;
cin>>a;
if(a==1){
goto D;}}
else if(odgovor1==2){
cout<<endl;
b.StanjeRacuna(username);
cout<<endl;
b.PolaganjeDepozita(username);
cout<<endl;
cout<<"Za povratak nazad pritisnute 1 "<<endl;
int a;
cin>>a;
if(a==1){
goto D;}}
else if(odgovor1==3){
cout<<endl;
b.StanjeRacuna(username);
cout<<endl;
b.PodizanjeNovca(username);
cout<<endl;
cout<<"Za povratak nazad pritisnute 1 "<<endl;
int a;
cin>>a;
if(a==1){
goto D;}}
else{
cout<<endl;
goto M; }}
else{
cout<<endl;
cout<<"Pogresni podaci. Pokusajte ponovo!"<<endl;
goto C; }}
else{
return 0; }}