Clase, Clase Derivate, Constructori, Destructori - Programe POO

Imagine preview
(7/10)

Aceasta fituica rezuma Clase, Clase Derivate, Constructori, Destructori - Programe POO.
Mai jos poate fi vizualizat un extras din document (aprox. 2 pagini).

Arhiva contine 1 fisier doc de 8 pagini .

Iti recomandam sa te uiti bine pe extras si pe imaginile oferite iar daca este ceea ce-ti trebuie pentru documentarea ta, o poti descarca. Ai nevoie de doar 4 puncte.

Domeniu: Calculatoare

Extras din document

Constructori si destructori

#include "conio.h"

#include "iostream"

using namespace std;

class complex

{private:

double re; double im;

public:

complex();

complex(double re);

complex(double re,double im);

~complex();

complex(complex &r);

void display(); };

complex::~complex(){ cout<<"distruge instanta"; }

complex::complex(complex &r)

{ complex::re=r.re;

complex::im=r.im;}

void complex::display(){ cout<<"partea reala: "<<re<<"tpartea imaginara: "<<im<<endl;}

complex::complex(){ complex::re=0; complex::im=0;}

complex::complex(double re){ complex::re=re; complex::im=0;}

complex::complex(double re,double im){complex::re=re; complex::im=im;}

int main(){ complex c1;

c1.display();

complex c2(5,1);

c2.display();

complex c3(1,2);

c3.display();

complex c4=c3;

complex c5(c2);

c4.display();

c5.display(); getch();}

Constructori de initializare,constructori de copiere si destructori cu alocare dinamica

#include "iostream"

#include"conio.h"

using namespace std;

class DStack{

int *pvect;

int size;

int tos;

public:

DStack(int s){

cout << "Constructor initializaren";

pvect = new int[s];

size = s;

tos = 0;}

DStack(DStack &r);

~DStack();

void push(int x);

int pop();};

DStack::DStack(DStack &r){

cout << "Constructor copieren";

size = r.size;

tos = r.tos;

pvect = new int[size];

for (int i=0; i< size; i++)

pvect[i] = r.pvect[i];}

DStack::~DStack(){cout << "Destructorn";

if (pvect){

delete pvect;

pvect = NULL;}}

DStack h(){

DStack stack(200);

return stack;}

int main(){h();

cout << "Revenire din h()n";

getch();}

Fisiere in arhiva (1):

  • Clase, Clase Derivate, Constructori, Destructori - Programe POO.doc

Alte informatii

Aceste fisiere contin programe de POO.UPB ETTI anul 2