Continua Re Sub Ex Ppoo

  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Continua Re Sub Ex Ppoo as PDF for free.

More details

  • Words: 758
  • Pages: 9
35.

36.

37.

38. Fie programul : // Constructor cu semantica prin referinta // Operatorul = cu semantica prin valoare si stergere destinatie #include class C{ public: C(int n=0, int v[]); C& C::operator=(C& x); 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; } C& C::operator=(C& x){ // stergerea valorior din vectorul destinatie, care ori cum vor fi modificate delete[] pi; // atribuire dim=x.dim; pi=new int[dim]; for(int j=0; j
39. Fie urmãtoarele clase Java: class CoadaCirculara{ public CoadaCirculara(int n, String s){maxDim=n; nume=s; v= new Object[m axDim];} public boolean esteGoala(){return numarElemente==0;} public boolean estePlina(){return numarElemente==maxDim;} public void adauga(Object ob){ numarElemente++; ultim= (ultim+1)%maxDim; v[ultim]=ob; }

public void elimina(){ numarElemente--; prim=(prim+1)%maxDim; } public Object element(){ return v[prim]; }

public String nume(){return nume;} private Object v[]; private int maxDim; // numarul maxim de elemente private int prim=0;//pozitia primului element din lista private int ultim=-1; //pozitia elementului adaugat ultima data //lista are elementele in vectorul v, de la prim la ultim, //in sensul acelor de ceasrnic private int numarElemente=0; // numarul de elemente din coada private String nume;// numele cozii } public class TestCoadaCirculara{ public static void main(String[] args){ CoadaCirculara x=new CoadaCirculara(3,"X"); x.adauga("a"); x.adauga("b"); x.adauga("c"); x.adauga("d"); x.adauga("e"); x.adauga("f"); System.out.println(x.element()); } } Care afirmaþie este adevãratã: a. Programul afiºeazã: c b. Programul afiºeazã: a c. Programul afiºeazã: b d. Programul afiºeazã: d 40. Se considera clasa: #include "iostream.h" template class C{ public:

C(int nrmax=0); void put(T); T get(); void remove();

private: int nrmax; int nrelem; int first; int free; T* support; }; template C::C(int nrmax):nrmax(nrmax){ first=free=nrelem=0; support = new T [nrmax -1]; } template void C::put(T e){ support[free]=e; free= ++free % nrmax; nrelem++; } template T C::get(){ return support[first]; } template void C::remove(){ first= ++first % nrmax; --nrelem; } a. Clasa C este o clasa generica b. Clasa C este o clasa abstracta c. Clasa C este derivata din clasa T d. Clasa T este derivata din clasa C

41. Fie programul : // destructor virtual, #include class B{ public: virtual ~B(){cout<<"~B()"<<end l;} }; class D: public B{ public: virtual ~D(){cout<<"~D()"<<endl;} }; void main(){ B *pb;

D *pd; pd= new D(); pb=new D(); delete pb; delete pd; } Programul afiseaza: a. ~ B()~D()~B() ~D() b. ~ B() ~B() ~D() c. ~ B() ~D() d. ~ D()~B()~D() ~B()

42. Fie programul: #include class Cerc{ public: Cerc(float r):raza(r){} float getRaza(){return raza;} Cerc& operator++(){raza++;return *this;}// return by reference Cerc operator--(){raza--;return *this;}// return by value private: float raza; }; void main(){ Cerc c(1.0); cout<<(++(++c)).getRaza()<<” ”; cout<
43. Fie urmatorul program: #include class A{ public: // supraincaracre void s() void s(){cout<<"void A::s()"<<endl;} void s(int i){i++;cout<<"void A::s(int)"<<endl; }

// supraincarcare void v() virtual void v(){cout<<"virtual void A::v()"<<endl;} virtual void v(int i){i++;cout<<"virtual void A::v(int)"<<endl;} }; class B:public A{ public: // 1. supraincarcare metoda statica int s(){cout<<"int B::s()"<<endl; return 1 ;} // 2. specializare metoda statica void s(int i){i++;cout<<"void B::s(int)"<<endl; } // 3. specializare metoda virtuala virtual void v(int i){i++;cout<<"virtual void B::v(int)"<<endl;} }; void main(){ A *pa; B b; pa=&b; pa->s(); pa->v(1); } Prin executarea sa, programul afiseaza: a. void B::v() void A::v(int) b. void A::v() void B::v(int) c. void A::s() void B::v(int) d. void A::v() void A::v(int)

44. Fie urmãtorul program Java: import java.awt.*; import java.awt.event.*; class Model{ private int x=0; public Model(){}; public void increment(){x++;} public int get_x(){return x;} } public class View extends Frame{ private Button b; protected Model m; private Controller c; protected TextField tf;

public static void main(String args[]){ Frame f= new View(); } public View(){ setTitle("Exemplu Model -View-Controller"); b= new Button("Actiune"); add("North",b); m=new Model(); c=new Controller(this); b.addActionListener(c); tf=new TextField(10); add("Center",tf); setSize(100,250); setVisible(true); } } class Controller implements ActionListener{ private View vw; public Controller(View v){ vw=v; } public void actionPerformed(ActionEvent e){ vw.m.increment(); vw.tf.setText(String.valueOf(vw.m.get_x())); } } Care afirmaþie este adevãratã, dacã se face de douã ori click pe butonul stang mouse asupra butonului Actiune: a. În câmpul de text f.tf este afiºatã valoarea 2 b. În câmpul de text f.tf este afiºatã valoarea 1 c. Programul nu afiºeazã nimic d. Valoarea atributului f.m.x rãmâne me reu la valoarea 0

Related Documents

Continua Re Sub Ex Ppoo
December 2019 7
Ex Ppoo Mai 09
May 2020 8
Sub Re Des 2
July 2020 4
Sub Re Des
November 2019 3
Ppoo Nou
December 2019 18