1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include <iostream>
#include <string>
using namespace std;
class Nev{
protected:
char *string;
int length;
public:
Nev() {
string = new char(1);
length=1;
string = "";
}
Nev(char n[], int l) {
string = new char(l+1);
length=l;
strcpy(string, n);
}
void getstring() {
cout << string;
}
void getLengthN() {
cout << length;
}
~Nev() {
delete string;
}
};
class Alkalmazott:public Nev{
char *beosztas;
int length2;
public:
Alkalmazott(char n[], char b[], int l, int l2) {
string = new char(l+1);
length=l;
strcpy(string, n);
beosztas = new char(l2+1);
length2=l2;
strcpy(beosztas, b);
}
~Alkalmazott(){
delete beosztas;
}
void getInfo() {
cout << beosztas;
};
Alkalmazott& operator=(const Alkalmazott& sec) {
if (this != &sec) {
delete string;
delete beosztas;
string = new char(sec.length+1);
strcpy(string, sec.string);
beosztas = new char(sec.length2+1);
strcpy(string, sec.beosztas);
length=sec.length;
length2=sec.length2;
}
return *this;
}
void setBeosztas(char *b, int l) {
if (beosztas != NULL) delete beosztas;
beosztas = new char(l+1);
strcpy(beosztas,b);
length2=l;
}
void getLength() {
cout << length2;
}
};
void main(){
Alkalmazott a("Kovacs", "Raktaros", 6, 8);
Alkalmazott b("Kiss", "Ugyved", 4, 6);
int stop;
a.getstring();
a.getInfo();
a.getLengthN();
a.getLength();
a.setBeosztas("Ugyved", 6);
cin >> stop;
}
| |