Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string.h>
- #include<conio.h>
- using namespace std;
- class Telefon{
- protected:
- char* numar;
- char* marca;
- public:
- Telefon(char *numar, char *marca);
- Telefon(const Telefon &t);
- ~Telefon();
- void setNumar(char *numar);
- void apeleaza(char *numar);
- void raspunde();
- Telefon & operator=(Telefon &n);
- void afisare();
- };
- Telefon::Telefon(char *numar, char *marca){
- this->numar=new char[strlen(numar)+1];
- strcpy(this->numar, numar);
- this->marca=new char[strlen(marca)+1];
- strcpy(this->marca, marca);
- cout<<"Apel constructor cu param Telefon"<<endl;
- }
- Telefon::Telefon(const Telefon &t){
- numar=new char[strlen(t.numar)+1];
- strcpy(this->numar, t.numar);
- marca=new char[strlen(t.marca)+1];
- strcpy(marca, t.marca);
- cout<<"Apel constructor copiere Telefon"<<endl;
- }
- Telefon::~Telefon(){
- delete[]numar;
- delete[]marca;
- cout<<"Apel destructor Telefon"<<endl;
- }
- void Telefon::setNumar(char *numar){
- if(strlen(this->numar)<strlen(numar)) {
- delete this->numar;
- this->numar=new char[strlen(numar)+1];
- }
- strcpy(this->numar,numar);
- }
- void Telefon::apeleaza(char *numar){
- cout<<"suna "<<numar<<endl;
- }
- void Telefon::raspunde(){
- cout<<"te suna cineva";
- }
- Telefon& Telefon:: operator=(Telefon &n){
- if(this!=&n){
- delete[]numar;
- delete[]marca;
- numar=new char[strlen(n.numar)+1];
- strcpy(numar, n.numar);
- marca=new char[strlen(n.marca)+1];
- strcpy(marca, n.marca);
- }
- }
- void Telefon::afisare(){
- cout<<"numar "<<numar<<", marca "<<marca<< endl;
- }
- ///*******************
- class TelefonFix: public Telefon{
- protected:
- bool whireless;
- public:
- TelefonFix(char *n, char *m, bool whir);
- void afisare();
- };
- TelefonFix::TelefonFix(char *n, char *m, bool whir): Telefon(n,m){
- this->whireless=whir;
- }
- void TelefonFix::afisare(){
- Telefon::afisare();
- cout<<"whireless "<<whireless<<endl;
- }
- ///****************
- class TelefonMobil:public Telefon{
- protected:
- int autonomie;
- // char *Operator; redefinim supraincarcarea =
- public:
- TelefonMobil(char *n, char *m, int autonomie );
- void afisare();
- };
- TelefonMobil::TelefonMobil(char *n, char *m, int autonomie ):Telefon(n, m){
- this->autonomie=autonomie;
- }
- void TelefonMobil::afisare(){
- Telefon::afisare();
- cout<<"Autonomie "<<autonomie<<endl;
- }
- int main(){
- Telefon t("0744501110", "Motorola");
- t.afisare();
- cout<<endl;
- TelefonFix t1("0351411111", "rds", true);
- t1.afisare();
- cout<<endl;
- TelefonMobil t2("0721444444", "Vodafone", 24);
- t2.afisare();
- cout<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment