{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

solutii2 - Capitolul 2 Clase i obiecte E2.3 Pentru...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Capitolul 2 - Clase şi obiecte E2.3 Pentru reprezentarea unui aparat de înregistrare se poate defini clasa Contor astfel: #include <iostream.h> class Contor{ int sute, zeci, unitati; public: Contor(int s, int z, int u) // Constructor { sute = s; zeci = z; unitati = u;} void avans(); void display(){ cout << "Sute: "<< sute << " Zeci: " cout << zeci << " Unitati: " << unitati << endl; } }; void Contor::avans(){ unitati++; if (unităţi > 9){ zeci++; if (zeci > 9){ sute++; if (sute > 9){ sute=0; zeci = 0; unitati = 0; } } } } void main (){ Contor C1(9,7,2); C1.display(); for (int i=0;i<5;i++) C1.avans(); C1.display(); } Mesajul la consolă este: Sute: 9 Zeci: 7 Unitati: 7 Nu este necesară definirea unui destructor, deoarece este suficient destructorul implicit pentru eliberarea zonei de memorie, neexistând variabile alocate dinamic. E2.4 Mesajele sunt: Nr. obiecte 1 Nr. obiecte 2 Nr. obiecte 3 Nr. obiecte 4 Nr. obiecte 5 Nr. obiecte 4
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Nr. obiecte 3 Nr. obiecte 4 Nr. obiecte 5 Nr. obiecte 6 Nr. obiecte 5 Nr. obiecte 4 Nr. obiecte 3 Nr. obiecte 2 Nr. obiecte 1 Nr. obiecte 0 Primele trei obiecte ( ob1 , ob2 , ob3 ) sunt create la începutul funcţiei main() . La
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern