0% found this document useful (0 votes)
114 views5 pages

Examen PPOO

The document contains 10 questions about C++ programming concepts like classes, inheritance, constructors, destructors, pointers, and operator overloading. It asks the reader to determine things like the order of constructor/destructor calls for a given class hierarchy, what would be printed by a program, which function version would be called, etc. and provides multiple choice answers for each question.

Uploaded by

moloz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views5 pages

Examen PPOO

The document contains 10 questions about C++ programming concepts like classes, inheritance, constructors, destructors, pointers, and operator overloading. It asks the reader to determine things like the order of constructor/destructor calls for a given class hierarchy, what would be printed by a program, which function version would be called, etc. and provides multiple choice answers for each question.

Uploaded by

moloz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

O secventa de program si se cerea sa se aleaga expresia care completeaza programul facand


posibila extragerea …. (printre raspunsuri erau expresii cu template, ifriend etc) 20pct

2. Un program cu 2 vectori si se cerea sa se precizeze ce se va afisa la executarea


programului. (am raspuns ca se vor afisa cei doi vectori cu valori nule) 20pct

3. Sa se spuna ce se afiseaza si ordinea de apel a constructorilor: 10pct

class Clasa1
{
public:
Clasa1(){ cout<<"C1::C1()"<<endl;}

};
class Clasa2
{
public:
Clasa2() { cout<<"C2::C2()"<<endl;}
};
class System
{
Clasa1 ob1;
Clasa2 ob2;
public:
System() { cout<<"S::S()"<<endl;}
};
int main (int argc, char* argv[])
{
System a;
return 0;
}
#include <iostream>

using namespace std;


class Clasa1
{ public:
~Clasa1(){ cout <<"C1::~C1()" <<endl; }
};
class Clasa2
{
public:
~Clasa2(){ cout <<"C2::~C2()" <<endl; }
};
class System
{
Clasa1 ob1;
Clasa2 ob2;
public:
System():ob2(),ob1(){ }
virtual ~System() { cout << "S::~S()" <<endl;}
};
int main (int argc, char* argv[] )
{
System a;
return 0;
}

Raspuns:
C1::~C1()
C2::~C2()
S::~S()

4. Analizati cu atentie urmatorul fragment de cod sursa. Precizati care este efectul apelarii
metodei Create(), ce varianta a functiei se va apela si ce se afiseaza pe ecran? 10pct

class A
{
protected:
int dim;
public:
A(){ cout<<"A::A()"<<endl;}

virtual ~A(){ cout<<"A::~A()"<<endl;}


void Create(int d = 0x10)
{
dim = d;
cout<<"A::Create("<<dim<<")"<<endl;
}
};

class B: public A
{
public:
B(){ cout<<"B::B()"<<endl;}
virtual ~B(){ cout<<"B::~B()"<<endl;}

virtual void Create(int d = 0x100)


{
dim = d;
cout<<"B::Create("<<dim<<")"<<endl;
}
};

int main(int argc, char* argv[])


{

A* p = new B();
p->Create( );
delete p;
return 0;
}

Raspuns:
A::Create(16)

5. Fie urmatorul program: 5pct

class A{
public:
void m(){cout<<"A:m()"<<endl;};
virtual void v(){cout<<"A:v()"<<endl;};
};
class B: public A{
private:
void m(){cout<<"B:m()"<<endl;};
virtual void v(){cout<<"B:v()"<<endl;};
};

void main(){
A a,*p;
B b;
b.m();
b.v();

p=&b;
p->m();
p->v();

Care expresie este corecta:


a) b.m();
b) b.v();
c) p->f();
d) p->m();
Raspuns: d) p->m()

6.

7.
8. Fie urmatorul program: 5pct
#include <iostream.h>
class C{
public: C(int n=0, int v[]);
friend ostream& operator<<(ostream &o, const C&);
private: int dim; int *pi;
};
C::C(int n, int v[]) {
dim=n; pi= v;
}
ostream& operator<<(ostream &o, const C &m){
for(int j=0; j<m.dim; j++)o<< m.pi[j]<<" ";
return o;
}
void main(){
int a[]={1,2,3}, b[]={10,20};
C x(3,a),y(2, b);
a[0]=-100;
cout<<(x=y)<<endl;
}
Programul afiseaza:
10 20

9. 10pct

10. Ce reprezinta urmatoarea diagrama UML: 10pct

Raspuns : d)

You might also like