/* * paid_student.cpp * * Created on: 18.04.2013 * Author: trifon */ #include #include using namespace std; #include "paid_student.h" PaidStudent::PaidStudent() : fee(100) { cerr << "PaidStudent()\n"; sponsor = new char[strlen("Anonymous")+1]; strcpy(sponsor, "Anonymous"); } PaidStudent::PaidStudent(char const* _name, char const* _id, int _fn, double _grade, double _fee, char const* _sponsor) : Student(_name, _id, _fn, _grade), fee(_fee) { cerr << "PaidStudent(...)\n"; sponsor = new char[strlen(_sponsor)+1]; strcpy(sponsor, _sponsor); } void PaidStudent::setFee(double _fee) { fee = _fee; } double PaidStudent::getFee() const { return fee; } char const* PaidStudent::getSponsor() const { return sponsor; } ostream& operator<<(ostream& os, PaidStudent const& ps) { os << "Такса: " << ps.fee << endl; os << "Спонсор: " << ps.sponsor << endl; return os << (Student const&)ps; } istream& operator>>(istream& is, PaidStudent& ps) { is >> ps.fee; is.get(); char buf[100]; is.getline(buf, 99, ' '); delete[] ps.sponsor; ps.sponsor = new char[strlen(buf)+1]; strcpy(ps.sponsor, buf); return is >> (Student&)ps; } PaidStudent::~PaidStudent() { cerr << "~PaidStudent\n"; delPaidStudent(); } void PaidStudent::copyPaidStudent(PaidStudent const& p) { setFee(p.fee); sponsor = new char[strlen(p.sponsor) + 1]; strcpy(sponsor, p.sponsor); } void PaidStudent::delPaidStudent() { delete[] sponsor; } PaidStudent::PaidStudent(PaidStudent const& p) : Student(p) { cerr << "copy PaidStudent\n"; copyPaidStudent(p); } PaidStudent& PaidStudent::operator=(PaidStudent const& p) { if (this != &p) { // !!! *this Person::= p; // !!! *this = p; // !!! Person::operator=(p); Student::operator=(p); //*(Student*)this = p; //(Student&)*this = p; //!!!*this = (Student&)p; cerr << "PaidStudent=\n"; delPaidStudent(); copyPaidStudent(p); } return *this; }