0% found this document useful (0 votes)
16 views4 pages

Subiecte Carte Poo

subiecte poo

Uploaded by

Apostol Florin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Subiecte Carte Poo

subiecte poo

Uploaded by

Apostol Florin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Ex 1.

#include <iostream>
template <unsigned N>
class A {
public:
int m_n;
A(int n) : m_n(n) { if ( 0 ==n) { throw " Examen "; }}
~ A() { std :: cout << m_n; }
};

int main() {
try { A a(1) ; A b(3); A c(2);} catch ( . . . ) { std :: cout << 3; }
return 0;
}
Rezultatul afișat pe ecran în urma executării programului va fi "231".
Ex. 2
#include <iostream>
template <unsigned N>
class A{
public: A(){std::cout << N;}
private: A<N-1> m_a;
};
template<> class A<0>{
public: A() {std::cout << 'A'; }
};
int main() {A<4>(); return 0;}
Rezultatul afișat pe ecran în urma executării programului va fi: A1234
Ex. 3
#include <iostream>

class A {
public:
A(int n = 2) : m_i(n) {}
~A() { std::cout << m_i; }

protected: int m_i;


};

class B : public A {
public: B(int n) : A(n), m_x(m_i + 1), m_a(n) {}

public : ~B() { std::cout << m_i; --m_i; }

private: A m_x; A m_a;


};

int main() { B b(5); return 0; } * SE AFISEAZA 5564


4.
#include <iostream>
class A {
public:
A(int n = 0) : m_i(n) { std::cout << m_i; }
protected:
int m_i;
};
class B : public A {
public:
B(int n) : m_j(n), m_a(--m_j), m_b() { std::cout << m_j; }
private:
int m_j;
A m_a;
A m_b;

static A m_c;
};

A B::m_c(3);
int main() {
B b(2);
return 0;
}

Se afiseaza : 30101
5.
#include <iostream>

class A {
public: A(int n = 0) : m_i(n) { std::cout << m_i; ++m_i; }
protected:
int m_i;
};

class B : public A {
public:
B(int n) : m_a(new A[2]), m_x(++m_i) { std::cout << m_i; }
~B() { delete[] m_a; }
private:
A m_x;
A* m_a;
};

int main() {
B b;
return 0;
} SE AFISEAZA 0112
6.

#include <iostream>

class A {
public:
A(int n) : m_n(n) { std::cout << m_n; }
~A() { std::cout << m_n; }

private:
int m_n;
};

int f(int n) {
if (1==n) {
throw 0;
}
A 1(n) ;
return f n * (n - 1)/(n-1);
}

int main() {
try {
int r = f(3);
A a(r);
} catch (int e) {
std::cout << e << std::endl;
}
return 0;
}

* se afișează "32230"

7.

#include <iostream>
class A {
public:
virtual ~A() {f () ; }
public:
virtual void f() const { std::cout << "1"; }
};

class B : public A {
public:
~ B () { f() ; }
private:
virtual void f () const { std::cout << 2; }
};

int main() {
A* a = new B;
delete a;
std::cout << std::endl;

return 0; } * SE AFISEAZA 21
8.
#include <iostream>

class A {
public:
A(int n) {
if (n == 0) {
throw "Examen";
}
}
};

int main() {
A *p0 = 0, *p1 = 0, *p2 = 0;

try {
p1 = new A(1);
p0 = new A(0);
p2 = new A(2);
} catch (...) {std::cout << 3;}
std::cout << ((0 != p1) ? 1:0);
std::cout << ((0 != p0) ? 1:0);
std::cout << ((0 != p2) ? 1:0) << std::endl;

delete p1;
delete p0;
delete p2;

return 0;
} SE AFISEAZA 3100

9.

You might also like