Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- /**Utwórz klasê konto posiadaj¹c¹ dwa wewnêtrzne pola
- numer konta typu int oraz stan konta typu double
- dodaj metody dostêpu do pól wewnêtrznych klasy (set i get)
- zdefiniuj konstruktor bezargumentowy, oraz konstruktor dwuargumentowy
- inicjuj¹cy obiekt numerem konta i stanem konta. Zdefiniuj metodê przelej(double x)
- która zwiêksza stan konta o x
- */
- class konto{
- public:
- konto(){}
- konto (int n, double s){numer=n; stan=s;}
- void setNumer(int n){numer=n;}
- int getNumer (){return numer;}
- void setStan(double s){stan=s;}
- double getStan(){return stan;}
- void przelej(double x){stan+=x;}
- konto operator +(konto &v){
- return konto (this->numer,this->stan+v.stan);
- }
- private:
- int numer;
- double stan;
- };
- /** zdefiniuj operator + w ten sposób aby tworzył konto o stanie równym sumie stanów kont
- i numerze pierwszego konta */
- int main(){
- /**stwórz dwa konta: 123456434 o stanie 535.12z³ oraz 876543211 o stanie 212.45z³
- wyœwietl numer i stan ka¿dego konta, na konto 123456434 przelej 750z³ a z konta
- 876543211 zabierz 35.20z³. Wyœwietl numer i stan ka¿dego konta.Stwórz konto k3 wykonaj
- k3=k1+k2. Wyświetl stany kont.
- */
- konto k1 (123456434, 535.12), k2(876543211,212.45),k3;
- cout<<k1.getNumer()<<" "<<k1.getStan()<<"PLN"<<endl;
- cout<<k2.getNumer()<<" "<<k2.getStan()<<"PLN"<<endl;
- k1.przelej(750);
- k2.przelej(-35.2);
- cout<<k1.getNumer()<<" "<<k1.getStan()<<"PLN"<<endl;
- cout<<k2.getNumer()<<" "<<k2.getStan()<<"PLN"<<endl;
- cout<<"****************************************"<<endl;
- k3=k1+k2;
- cout<<k1.getNumer()<<" "<<k1.getStan()<<"PLN"<<endl;
- cout<<k2.getNumer()<<" "<<k2.getStan()<<"PLN"<<endl;
- cout<<k3.getNumer()<<" "<<k3.getStan()<<"PLN"<<endl;
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement