- •Практичне заняття 8 Теоретична частина
- •Завдання
- •Int main()
- •Void push(int var)
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Лабораторне заняття 9 Теоретична частина
- •Зміст завдання
- •Лабораторне заняття 10 Теоретична частина
- •Практичне заняття 9 Теоретична частина
- •Завдання
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Практичне заняття 10-11 Теоретична частина
- •Завдання
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Лабораторне заняття 11-12 Теоретична частина
- •Завдання 1
- •Завдання 2
- •Завдання 3
- •Int main()
- •Практичне заняття 12-13 Теоретична частина
- •Завдання
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Лабораторне заняття 13 Теоретична частина
- •Завдання 1
- •Int main()
- •Завдання 2
- •Практичне заняття 14 Теоретична частина
- •Завдання
- •Int main()
- •Int main()
- •Лабораторне заняття 14 Теоретична частина
- •Завдання
Int main()
{clrscr();
alpha a1(37);
alpha a2;
a2=a1; //Запуск перезавантаженого =
cout<<”\na2=”;a2.display();
alpha a3(a1); //запуск конструктора копіювання
//alpha a3=a1; //еквівалентне визначення а3
cout<<”\na3=”;a3.display();
cout<<endl;
bioskey(0);
return 0;
}
Програма 22.16
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
#include<string.h>
/////////////////
class strCount
{private:
int count;
char* str;
friend class String;
strCount(char* s)
{int length=strlen(s);
str=new char[length+1];
strcpy(str,s);
count=1;
}
~strCount()
{delete[] str;}
};
/////////////////
class String
{private:
strCount* psc;
public:
String()//конструктор без аргументів
{psc=new strCount("NULL");}
//-------
String(char* s)//конструктор з 1 аргументом
{psc=new strCount(s);}
//-----------
String(String& S) //конструктор копіювання
{psc=S.psc;
(psc->count)++;}
//----------
~String() //деструктор
{if(psc->count==1)
delete psc;
else
(psc->count)--;
}
//----------
void display()
{cout<<psc->str;
cout<<" (addr="<<psc<<")"; //виведення адреси
}
//-----------
void operator=(String& S)
{if(psc->count==1)
delete psc;
else
(psc->count)--;
psc=S.psc;
(psc->count)++;
}
};
//////////////
Int main()
{clrscr();
String s3="Яка-небудь пробна фраза";
cout<<"\ns3=";s3.display();
String s1;
s1=s3;
cout<<"\ns1=";s1.display();
String s2(s3);
cout<<"\ns2=";s2.display();
cout<<endl;
bioskey(0);
return 0;
}
Програма 22.17
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
class where
{private:
char chararray[10];
public:
void reveal()
{cout<<"\nАдреса обєкту "<<this;}
};
///////////////
Int main()
{clrscr();
where w1,w2,w3;
w1.reveal();
w2.reveal();
w3.reveal();
cout<<endl;
bioskey(0);
return 0;
}
Програма 22.18
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
class what
{private:
int alpha;
public:
void tester()
{this->alpha=11;
cout<<this->alpha;
}
};
/////////////
Int main()
{clrscr();
what w;
w.tester();
cout<<endl;
bioskey(0);
return 0;
}
Програма 22.19
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
///////////////
class alpha
{private:
int data;
public:
alpha()
{ }
alpha(int d)
{data=d;}
alpha& operator=(alpha& a)
{data=a.data;
cout<<”\nЗапущений оператор присвоювання”;
return *this;
}
void display()
{cout<<data;}
};
////////////////
Int main()
{clrscr();
alpha a1(37);
alpha a2,a3;
a3=a2=a1; //перезавантажений = двічі
cout<<”\na2=”;a2.display();
cout<<”\na3=”;a3.display();
cout<<endl;
bioskey(0);
return 0;
}
Програма 22.20
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
#include<string.h>
/////////////////
class strCount
{private:
int count;
char* str;
friend class String;
strCount(char* s)
{int length=strlen(s);
str=new char[length+1];
strcpy(str,s);
count=1;
}
~strCount()
{delete[] str;}
};
/////////////////
class String
{private:
strCount* psc;
public:
String()//конструктор без аргументів
{psc=new strCount(“NULL”);}
//-------
String(char* s)//конструктор з 1 аргументом
{psc=new strCount(s);}
//-----------
String(String& S) //конструктор копіювання
{psc=S.psc;
(psc->count)++;}
//----------
~String() //деструктор
{if(psc->count==1)
delete psc;
else
(psc->count)--;
}
//----------
void display()
{cout<<psc->str;
cout<<” (addr=”<<psc<<”)”; //виведення адреси
}
//-----------
String& operator=(String& S)
{cout<<”\nПрисвоювання”;
if(psc->count==1) //if last
delete psc;
else
(psc->count)--;
psc=S.psc;
(psc->count)++;
return *this;
}
};
//////////////
