Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- /*class K1{
- string* p1;
- public:
- K1():p1(new string [2]){
- p1[0]="Nie podano";
- p1[1]="nie Podano";
- }
- K1(const string& a,const string& b):p1(new string [2]){
- p1[0]=a;
- p1[1]=b;
- }
- K1(const K1& obj):p1(new string [2]){
- p1[0]=obj.p1[0];
- p1[1]=obj.p1[1];
- }
- ~K1() {delete [] p1;}
- friend ostream& operator <<(ostream& out, const K1& obj);
- string& operator [](int id){
- return p1[id];
- }
- K1 operator =(const K1& obj){// DO ZAPAMIĘTANIA
- p1=new string [2];
- p1[0]=obj.p1[0];
- p1[1]=obj.p1[1];
- return *this;
- };
- };
- ostream& operator <<(ostream& out, const K1& obj){
- return out<<obj.p1[0]<<"| |"<<obj.p1[1]<<"| |";
- }
- class K2{
- K1 p1;
- double p2;
- public:
- K2():p1(),p2(0){};
- K2(const string& a,const string& b,double c):p1(a,b),p2(c){};
- K2(const K2& obj):p1(obj.p1),p2(obj.p2){};
- friend ostream& operator <<(ostream& out, const K2& obj);
- K2 operator =(const K2& obj){
- p1=obj.p1;
- p2=obj.p2;
- return *this;
- }
- friend K2 operator -(const K2& obj,double val);
- friend istream& operator>>(istream& in,K2& obj);
- void operator +=(const int & val){
- this->p2+=val;
- }
- };
- ostream& operator <<(ostream& out, const K2& obj){
- return out<<obj.p1<<"| |"<<obj.p2<<"| |";
- }
- istream& operator>>(istream& in,K2& obj){
- in>>obj.p1[0];
- in>>obj.p1[1];
- in>>obj.p2;
- return in;
- }
- K2 operator -(const K2& obj,const double val){// DO ZAPAMIĘTANIA
- K2 newObj=K2(obj);
- newObj.p2-=val;
- return newObj;
- }
- int main()
- {
- K2 ob1,ob2;
- const K2 * wsk1= new K2("kawa","z mlekiem",4.50);
- const K2 ob3(*wsk1);
- delete wsk1;
- wsk1=0;
- const K2 * wsk2 = new K2(ob3);
- ob2=*wsk2;
- cout<< ob1<<endl<<*wsk2;
- delete wsk2;
- wsk2=0;
- cout<<ob2;
- cout<<endl<<ob2-1.25;
- K2 txt[4];
- ifstream plik("dane.txt");
- for(int i=0;i<4;i++){
- plik>>txt[i];
- }
- plik.close();
- for(int i=0;i<4;i++){
- txt[i]+=1;
- cout<<txt[i];
- }
- return 0;
- }*/
- class K1{
- string* p1;
- public:
- K1():p1(new string){
- *p1="Nie podano";
- };
- K1(const string& a):p1(new string){
- *p1=a;}
- K1(const K1& obj){
- p1=new string;
- *p1=obj.p1[0];
- }
- K1 operator=(const K1& obj){
- p1=new string;
- *p1=obj.p1[0];
- return *this;
- }
- friend ostream& operator<<(ostream& out,const K1& obj);
- ~K1(){delete p1;}
- };
- ostream& operator<<(ostream& out,const K1& obj){
- return out<<obj.p1[0];
- }
- class K2{
- K1 txt[2];
- int w1;
- public:
- K2(){
- txt[0];
- txt[1];
- w1=0;
- }
- K2(const string& a,const string& b,int c):w1(c){
- txt[0]=a;
- txt[1]=b;
- };
- K2(const K2& obj){
- txt[0]=obj.txt[0];
- txt[1]=obj.txt[1];
- w1=obj.w1;
- }
- friend istream& operator>>(istream& in,K2& obj);
- friend ostream& operator<<(ostream& out,const K2& obj);
- friend K2 operator +(const K2& obj,const int& val);
- K2 operator =(const K2& obj){
- txt[0]=obj.txt[0];
- txt[1]=obj.txt[1];
- w1=obj.w1;
- }
- void operator+=(const int& val){
- this->w1+=val;
- }
- };
- K2 operator +(const K2& obj,const int& val){
- K2 newObj=obj;
- newObj.w1+=val;
- return newObj;
- }
- ostream& operator<<(ostream& out,const K2& obj){
- return out<<obj.txt[0]<<" "<<obj.txt[1]<<" "<<obj.w1;
- }
- istream& operator>>(istream& in,K2& obj){
- string a,b;
- in>>a;
- obj.txt[0]=a;
- in>>b;
- obj.txt[1]=b;
- in>>obj.w1;
- return in;
- }
- int main(){
- K2 ob1,ob2;
- const K2 * wsk1 = new K2("Ala","Koala",15);
- const K2 ob3(*wsk1);
- delete wsk1;
- wsk1=0;
- const K2 *wsk2 = new K2(ob3);
- ob2=*wsk2;
- delete wsk2;
- wsk2=0;
- cout<<ob2;
- cout<<ob2+10;
- K2 tab[4];
- ifstream plik("data.txt");
- for(int i=0;i<4;i++){
- plik>>tab[i];
- }
- plik.close();
- for(int i=0;i<4;i++){
- tab[i]+=1;
- cout<<tab[i]<<endl;
- }
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement