Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- const int N=10; //pocet uctu
- const int M=100000; //generovani cash
- const int P=10;//urok
- const int Y=1;//pocet let
- class Ucet
- {
- private:
- static int m_Count;//aktualni pocet uctu
- int m_Urok;
- int m_CisloUctu;
- int m_Cash;
- public:
- Ucet();
- int Cislo();
- int Urok();
- void Vlozit(int x);
- void Vybrat(int x);
- int AktualniStav();
- void PripsatUrok();
- virtual ~Ucet();
- };
- int Ucet::m_Count=0;//nastaven na 0 defaultne
- class List
- {
- private:
- int m_items;//pocet items v seznamu
- struct Node
- {
- Ucet *data;
- Node *next;
- Node *prev;
- };
- Node *head;
- Node *current;
- public:
- List();
- void Uroceni();
- void Vklad();
- void Vyber();
- void Report();
- bool isEmpty();
- void Insert(Ucet *X);
- virtual ~List();
- };
- List::List()
- {
- m_items=0;
- head=current=NULL;
- }
- List::~List()
- {
- while (head!=NULL)
- {
- Node *tmp = head;
- head=head->next;
- delete tmp;
- }
- current=NULL;
- }
- bool List::isEmpty()
- {
- return head==NULL;
- }
- void List::Insert(Ucet *item)
- {
- Node *add=new Node;
- m_items++;
- add->data=item;
- add->next=NULL;
- add->prev=NULL;
- if(head == NULL)
- {
- head=add;
- }
- else
- {
- current->next=add;
- add->prev=current;
- }
- current=add;
- }
- void List::Uroceni()
- {
- Node *tmp;
- for(tmp=head;tmp!=NULL; tmp=tmp->next)
- {
- cout << "U" <<tmp->data->Cislo() <<"[" << tmp->data->AktualniStav() <<"]" << "[";
- tmp->data->PripsatUrok();
- cout << tmp->data->AktualniStav()<<"]"<<endl;
- }
- }
- void List::Vklad()
- {
- int x =rand()%1000+1;
- Node *tmp;
- for(tmp=head; tmp!=NULL; tmp=tmp->next)
- {
- cout << "V" <<tmp->data->Cislo() <<"[" << tmp->data->AktualniStav() <<"]" << "[" <<x << "]" << endl;
- tmp->data->Vlozit(x);
- }
- }
- void List::Vyber()
- {
- int x =rand()%1000+1;
- Node *tmp;
- for(tmp=head; tmp!=NULL; tmp=tmp->next)
- {
- cout << "X" <<tmp->data->Cislo() <<"[" << tmp->data->AktualniStav() <<"]" << "[" <<x << "]" << endl;
- tmp->data->Vybrat(x);
- }
- }
- void List::Report()
- {
- if (isEmpty())
- {
- cout << "list is empty" << endl;
- }
- else
- {
- cout << "---HEAD---" << endl;
- Node *tmp;
- for(tmp=head; tmp!=NULL; tmp=tmp->next)
- {
- cout << tmp->data->AktualniStav() << endl;
- }
- cout << endl;
- }
- }
- Ucet::Ucet()
- {
- m_Cash=rand()%M+1000;
- m_CisloUctu=m_Count+1;
- m_Urok=rand()%P+1;
- m_Count++;
- cout << "G" <<m_CisloUctu<<"["<< m_Urok << "]" << "[" << m_Cash << "]" << endl;
- }
- void Ucet::PripsatUrok()
- {
- int x;
- x=m_Cash/100*m_Urok;
- m_Cash+=x;
- }
- int Ucet::Urok()
- {
- return m_Urok;
- }
- int Ucet::Cislo()
- {
- return m_CisloUctu;
- }
- void Ucet::Vlozit(int x)
- {
- m_Cash+=x;
- }
- void Ucet::Vybrat(int x)
- {
- if (x<m_Cash)
- {
- m_Cash-=x;
- }
- else
- {
- cout << "nelze vybrat vice, nez je na uctu" << endl;
- }
- }
- int Ucet::AktualniStav()
- {
- return m_Cash;
- }
- Ucet::~Ucet()
- {
- }
- int main()
- {
- Ucet *p[N];//vytvorime pole N uctu
- for(int i=0;i<N;i++)
- {
- p[i]=new Ucet(); //priradime jim hodnoty
- }
- cout << endl;
- List L;//vytvorime seznam
- for(int i =0;i<N;i++)
- {
- L.Insert(p[i]);//vlozime postupne data z pole uctu do seznamu
- }
- int x=Y*12;
- while(x>=0)
- {
- if(x%2==1)
- {
- L.Vklad();
- }
- else
- {
- L.Vyber();
- }
- if (x%12==0)
- {
- L.Uroceni();
- cout << " -------- year --------" << endl;
- }
- x--;
- }
- for(int i=0;i<N;i++)
- {
- delete p[i]; //smazeme vsechny dynamicky vytvorene ucty
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement