#include <iostream>
using namespace std;
#include <string>
class T {
char* t;
int n;
void myo(char* s) {
t = new char[strlen(s) + 1];
strcpy(t, s);
}
public:
T(char* s) {myo(s); n = 0;}
T(const T& t) {myo(t.t); n = t.n; cout << "...\n";}
~T() {delete[]t; cout << "^^^\n";}
void operator=(const T& s) {
delete[]t;
n = s.n;
myo(s.t);
cout << "***\n";
}
void boo() {n = 0;}
bool end() {return n == strlen(t);}
int see(int m) {
int j;
for (j = 0; j < m && t[n]; j++)
cout << t[n++];
return (t[n]) ? j : 0;
}
};
class P : public T {
char* moo;
int g;
int w;
int n;
void myo(char* s) {
n = strlen(s);
moo = new char[n + 1];
strcpy(moo,s);
}
void lin() {
for(int i = 0; i < w; i++)
cout << '-';
cout << '\n';
}
public:
P(int nl, int up, char* s, char* t) : T(s) {
myo(t);
g = nl;
w = up;
}
void dow(int u) {w = u;}
void acr(int p) {g = p;}
P(const P& p) : T(p) {
myo(p.moo);
g = p.g;
w = p.w;
}
~P() {delete[]moo; lin();}
void operator=(const P& p) {
T::operator=(p);
delete[]moo;
g = p.g;
w = p.w;
myo(p.moo);
cout << "===\n";
}
void see(int e) {
bool ok = false;
int k, p = 0;
if (!end()) {
do {
k = 0;
for (int i = 0; i < (n-1)/w + 1; i++) {
for (int j = 0; j < w && moo[k]; j++)
cout << moo[k++];
cout << '\n';
}
lin();
for (int i = 0; i < g && !ok; i++) {
ok = (T::see(w) == 0);
cout << '\n';
}
cout << '\n';
p++;
} while(p < e && !ok);
}
}
};
int main() {
P a(2, 6, "Encapsulation, Inheritance and Polymorphism","BTP200");
a.see(1);
P b = a;
b.see(1);
a = b;
a.see(2);
a.dow(8);
a.acr(2);
a.boo();
a.see(1);
a.dow(3);
a.see(1);
return 0;
}
|