Close
Faqja 0 prej 3 FillimFillim 12 FunditFundit
Duke shfaqur rezultatin -9 deri 0 prej 25
  1. #1
    i/e regjistruar
    Anėtarėsuar
    28-04-2002
    Vendndodhja
    USA
    Postime
    230

    C++ - Ushtrime

    1.
    Gjeneroni te gjitha perkembimet e mundshme te numrave 1, 2, 3,..., n. Per shembull, nese n eshte 3, programi juaj duhet te printoje (1, 2, 3) (1, 3, 2) (2, 1, 3) (2, 3, 1) (3, 1, 2) (3, 2, 1).

    Provojeni ta zgjidhni ushtrimin e mesiperm ne dy menyre: rekursive dhe jorekursive.

    2.
    Gjeni vleren e percaktuesit (determinant) te nje matrice me permasa m x n.

    3.
    Katrori magjik i permases n eshte nje matrice me permasa n x n e cila ploteson keto kushte:
    a- Ne kete matrice gjenden numrat nga 1 deri ne n^2, dhe cdo numer perdoret vetem njehere.
    b- Shuma e numrave per cdo rresht, kolone, apo diagonale eshte e njejte.



    Shkruani nje program qe gjeneron katror magjike per cdo numer te plote pozitiv tek. Pra, per n = 3, 5, 7, 9, 11,...

  2. #2
    i/e regjistruar Maska e Ujku_I_Vjeter
    Anėtarėsuar
    30-04-2002
    Vendndodhja
    Ne internet.
    Postime
    25
    Gje nje liber algoritmike se keto jane ushtrime klasike dhe cdo liber i ka ose bej nje search me google dhe ke per ti gjet edhe kode po deshe.

  3. #3
    i/e regjistruar
    Anėtarėsuar
    21-06-2002
    Postime
    12
    @Ujku_i_vjeter
    pershendetje! kampershtypjen se ideja e berat96 eshte goxha e mire dhe kam pershtypjen se nuk eshte qellimi aitj te hapi ndonje liber algoritmike apo te kerkoj me google.....mendoj se ai do qe kushdo qe ehste i interesuar per programim te merret me ushtrimet me klasike te programimit. dhe kjo ehste shume krize sepse po te lexoh te gjithe postimet neper forumet shqiptar do te lexosh vetem gjera te ketilla si : " ku ta gjej kete program, ku te gjej kete script..." etj etj. dhe shume shume rralle lexohen probleme te cilat normalisht jane per programuesit. vertt ato problenme jane hsume klasike dhe gjenden neper cdo liber algoritmike dhe ppothuajse ne cdo teze provimesh neper universitete te ndryshme ku studjohet Informatike, por ehste nje gje shume e miremendoj une dhe do i kerkoja te gjithe atyre qe jane teinteresuar per programim te postojne gjithnje ushtrime te tilla. kam pershtyphjen se ka shume studenta te cilet studiojne informatike ketu ne forum dhe do ishte mire qe si per ata te cilet duan te studiojne dicka te tille ose kane interes si dhe per vete studentat do ishte emire te postohen ushtrime te cilat jepen gjate studimit. dhe mos harro @Ujku_i_vjeter se baza e programimit nuke hste nje SCP ( Search+Copy+Paste ) por jane keto ushtrime te cilat jane kaq klassik.
    kalofshi mire dhe befshi qef me ato ushtrime qe berat96 ju ka ofruar.

  4. #4
    * mbrojtesi me i mire * Maska e Static - Y
    Anėtarėsuar
    04-07-2002
    Vendndodhja
    Itali
    Postime
    15

    Ushtrime ne C++

    I dashur popull...

    Ne te vertete kjo mu duk si nje ide e lezecme per te perfituar pak nga sejcili.Do te kisha deshiren qe ne kete teme te jepeshin ushtrime ne C++, keshtu qe mund te kemi mundesine te mesojme nga njeri tjetri.Ketu shumica nga ne jane jashte shtetit...duke mesuar dhe duke punuar.Shpresoj qe neser pasneser, cdonjeri nga ne te kthehet ne token memč dhe te gjithe dijen qe ka ta shfrytezoje per veten e tij, famijen e tij, fene e tij, vendin e tij...sepse vetem ne kete menyre mund te ecim perpara...Nejse...se e zgjata shume dhe besoj se e keni kuptu se cfare doja me ju thene....
    Po e nis une i pari me nje ushtrim shume banal...dhe keshtu INSHALLAH te arrijme te ecim perpara pak e nga pak...

    Edhe dicka...zgjidhja e nje problemi ka menyra te ndryshme...mjafton qe problemi te jete efektiv dhe te nxjerri te njejtin rezultat ne fund...


    Ushtrim : Konverto nje numer te plote pozitiv, treshifror, jo te plotpjestueshem me dhjete...psh 234 -> 432.

    #include

    main () {

    int numer;
    int njesi , tedhjetat , teqintat , rezultati;

    printf("Fut numrin treshifror -> ");
    scanf("%d",&numer);

    njesia=(numer)%10;
    tedhjetat=(numer/10)%10;
    teqintat=(numer/100)%10;

    rezultati=njesi*100 + tedhjetat*10 + teqintat;
    printf("Numri %d , i konvertuar = %d ",numer,rezultati);
    }


    Paqe
    All Rights Reserved © SkYLIGht 2002

  5. #5
    i/e regjistruar Maska e Olti
    Anėtarėsuar
    23-04-2002
    Vendndodhja
    Itali
    Postime
    8

    Loje ...

    Ky program qe shifni me poshte eshte nje loje e programuar ne C++.Eshte ne gjuhe Italisht, po i interesoji njeriut te me thoje te ia kthej ne Shqip


    #include
    #include
    #include

    char matrix[3][3];//={0};
    void cou(void);
    int main()
    {

    int m,n;
    char ch='y';
    while(ch=='Y'||ch=='y'){
    for (m=0;m<3;m++)for (n=0;n<3;n++)matrix[m][n]= '\0';
    int i,j,sum=0;
    while ( sum < 10){
    if (sum == 0) cou();
    cout<<"Il primo giocatore Š Olti il numero e la and colonna"< cout<<"Num : ";
    cin>>i;
    cout<<"Colonna : ";
    cin>>j;
    for (;i>3 || i<1 || j>3 || j<1 ||('X'==matrix[i-1][j-1]||'O'==matrix[i-1][j-1]) {cout<<"Mi dispiace ma devi trovare un altro posto.\n";cout<<"row : ";cin>>i;cout<<"column : ";cin>>j;}
    matrix[i-1][j-1]='X';
    sum++;
    cou();

    //check if wins
    if (matrix[0][0]=='X' && matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2]) {cout<<"Giocatore 1 vince"< if (matrix[2][0]=='X' && matrix[2][0]==matrix[1][1] && matrix[1][1]==matrix[0][2]) {cout<<"Giocatore 1 vince"< if (matrix[0][0]=='X' && matrix[0][0]==matrix[1][0] && matrix[1][0]==matrix[2][0]) {cout<<"Giocatore 1 vince"< if (matrix[0][1]=='X' && matrix[0][1]==matrix[1][1] && matrix[1][1]==matrix[2][1]) {cout<<"Giocatore 1 vince"< if (matrix[0][2]=='X' && matrix[0][2]==matrix[1][2] && matrix[1][2]==matrix[2][2]) {cout<<"Giocatore 1 vince"< if (matrix[0][0]=='X' && matrix[0][0]==matrix[0][1] && matrix[0][1]==matrix[0][2]) {cout<<"Giocatore 1 vince"< if (matrix[1][0]=='X' && matrix[1][0]==matrix[1][1] && matrix[1][1]==matrix[1][2]) {cout<<"Giocatore 1 vince"< if (matrix[2][0]=='X' && matrix[2][0]==matrix[2][1] && matrix[2][1]==matrix[2][2]) {cout<<"Giocatore 1 vince"<
    if (sum == 9){cout<<"IL, gioco e finito e nessuno ha vinto hahaha, fatte schifo tutti a due!!!"< //player 2's turn

    cout<<"Il giocatore due Š 'O': scegli il numero Š la colonna"< cout<<"Num : ";
    cin>>i;
    cout<<"Colonna : ";
    cin>>j;
    for (;i>3 || i<1 || j>3 || j<1 ||('X'==matrix[i-1][j-1]||'O'==matrix[i-1][j-1]) {cout<<"Mi dispiace ragazzo, ma devi scegliere un altro posto0'.\n";cout<<"Num : ";cin>>i;cout<<"Colonna : ";cin>>j;}
    matrix[i-1][j-1]='O';
    sum++;
    //the play box
    cou();
    //check if wins
    if (matrix[0][0]=='O' && matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2]) {cout<<"Giocatore 2 vince"< if (matrix[2][0]=='O' && matrix[2][0]==matrix[1][1] && matrix[1][1]==matrix[0][2]) {cout<<"Giocatore 2 vince"< if (matrix[0][0]=='O' && matrix[0][0]==matrix[1][0] && matrix[1][0]==matrix[2][0]) {cout<<"Giocatore 2 vince"< if (matrix[0][1]=='O' && matrix[0][1]==matrix[1][1] && matrix[1][1]==matrix[2][1]) {cout<<"Giocatore 2 vince"< if (matrix[0][2]=='O' && matrix[0][2]==matrix[1][2] && matrix[1][2]==matrix[2][2]) {cout<<"Giocatore 2 vince"< if (matrix[0][0]=='O' && matrix[0][0]==matrix[0][1] && matrix[0][1]==matrix[0][2]) {cout<<"Giocatore 2 vince"< if (matrix[1][0]=='O' && matrix[1][0]==matrix[1][1] && matrix[1][1]==matrix[1][2]) {cout<<"Giocatore 2 vince"< if (matrix[2][0]=='O' && matrix[2][0]==matrix[2][1] && matrix[2][1]==matrix[2][2]) {cout<<"Giocatore 2 vince"<
    }
    cout<<"\nVuoi giocare ancora??? (S - N)\n";
    cin>>ch;
    }
    system("PAUSE");
    return 0;
    }




    void cou(void)
    {
    //the play box
    cout<<"\n\t\t 1 2 3\n"< cout<<"\t\t 1 "< cout<<"\t\t ---|---|---\n";
    cout<<"\t\t 2 "< cout<<"\t\t ---|---|---\n";
    cout<<"\t\t 3 "< }
    :-3

  6. #6
    i/e regjistruar Maska e Olti
    Anėtarėsuar
    23-04-2002
    Vendndodhja
    Itali
    Postime
    8

    Ky program eshte me i thjesht.Te jep mundesin te gjesh vleren minimale te nje array..

    #include
    #include
    #include
    #define max 20

    unsigned int nMAX;
    unsigned int i;
    float a;
    float min;
    unsigned int v[max];

    void caricamento();
    void calcolo();
    void valore_minimo();

    void main()
    {clrscr();
    caricamento();
    calcolo();
    valore_minimo();
    getch();}

    void caricamento()
    {cout<<"inserisci valore nMAX: ";
    cin>>nMAX;
    while(nMAX<=0 || nMAX>20){
    cout<<"ERRORE! inserisci un nuovo valore: ";
    cin>>nMAX;}
    i=0;
    do{
    cout<<"inserisci valore di a: ";
    cin>>a;
    while(a<=0){
    cout<<"ERRORE! inserisci un valore positivo: ";
    cin>>a;}
    v[i]=a;
    i=i+1;}
    while(!(i>=nMAX));}

    void calcolo()
    {i=0;
    min=v[i];
    i=i+1;
    while(i if(v[i] min=v[i];
    i=i+1;}
    }

    void valore_minimo()
    {cout<<"Il valore minimo del vettore Š: "<
    :-3

  7. #7
    i/e regjistruar
    Anėtarėsuar
    28-04-2002
    Vendndodhja
    USA
    Postime
    230
    Ja nje ushtrim i thjeshte. Implementoni klasen abstrakte IVector:

    #ifndef _IVector_h_
    #define _IVector_h_

    #include

    const int
    VECTOR_DEFAULT_SIZE = 3;

    template
    class IVector
    {

    public:

    ////////////////////////////////////////////////////////////////////
    // Basic functions
    //
    //
    ////////////////////////////////////////////////////////////////
    // Basic access functions
    //
    //
    virtual Object getUndefined() const= 0;
    virtual IVector* getCopy() const= 0;

    ////////////////////////////////////////////////////////////////
    // Basic disposing functions
    //
    //
    virtual void empty()= 0;
    virtual void dispose()= 0;


    ////////////////////////////////////////////////////////////////
    // Basic assignment functions
    //
    //
    virtual void setUndefined(const Object)= 0;
    virtual void copyInfo(const IVector *)= 0;
    virtual void copy(const IVector *)= 0;
    virtual const IVector* operator= (const IVector*)= 0;

    ////////////////////////////////////////////////////////////////
    // Basic comparison functions
    //
    //
    virtual void setComparisonFunction(int (*) (const IVector*,
    const IVector*))= 0;
    virtual int compareTo(const IVector *) const= 0;

    virtual bool operator==(const IVector *) const= 0;
    virtual bool operator>=(const IVector *) const= 0;
    virtual bool operator<=(const IVector *) const= 0;
    virtual bool operator>(const IVector *) const= 0;
    virtual bool operator<(const IVector *) const= 0;
    virtual bool operator!=(const IVector *) const= 0;

    ////////////////////////////////////////////////////////////////
    // Basic input/output functions
    //
    //
    virtual void print() const= 0;
    virtual void read()= 0;

    friend ostream& operator<< (ostream &out, const IVector *);
    friend istream& operator>> (istream &in, IVector *);


    ////////////////////////////////////////////////////////////////////
    // Access functions
    //
    //

    virtual bool isEmpty() const= 0;
    virtual bool isFull() const= 0;

    virtual int getSize() const= 0;

    virtual Object getFirstObject() const= 0;
    virtual Object getLastObject() const= 0;
    virtual Object getObjectAtPos(const int) const= 0;

    virtual bool contains(const Object) const= 0;
    virtual int find(const Object) const= 0;

    ////////////////////////////////////////////////////////////////////
    // Standard Processing functions
    //
    //
    virtual void setSize(const int)= 0;

    virtual void setFirstObject(const Object)= 0;
    virtual void setLastObject(const Object)= 0;
    virtual void setObjectAtPos(const int, const Object)= 0;
    virtual void setAllObjects(const Object)= 0;

    virtual void insert(const Object)= 0;
    virtual void insertAtFront(const Object)= 0;
    virtual void insertAtEnd(const Object)= 0;
    virtual void insertAtPos(const int, const Object)= 0;

    virtual Object remove(const Object value)= 0;
    virtual Object removeFromFront()= 0;
    virtual Object removeFromEnd()= 0;
    virtual Object removeFromPos(const int)= 0;

    virtual void copy(const Object*, const int)= 0;


    ////////////////////////////////////////////////////////////////////
    // Non-Standard Processing functions
    //
    //
    virtual Object* toArray() const= 0;

    virtual void reverse()= 0;
    virtual void sort(const int)= 0;
    virtual void filter(bool (*) (const Object))= 0;
    virtual void map(Object (*) (const Object))= 0;
    virtual void append(const IVector*)= 0;

    ////////////////////////////////////////////////////////////////////
    // Overloaded Operators
    //
    //
    virtual Object operator[] (const int) const= 0;


    ////////////////////////////////////////////////////////////////////
    // Input/Output Functions
    //
    //


    };

    #endif

  8. #8
    i/e regjistruar
    Anėtarėsuar
    28-04-2002
    Vendndodhja
    USA
    Postime
    230
    /*Header file for Vector - An implementation of IVector Class
    * using arrays
    */

    #ifndef _Vector_h_
    #define _Vector_h_

    #include "myIVector.h"

    template
    class Vector : public IVector
    {

    public:

    ////////////////////////////////////////////////////////////////////
    // Constructors & Desctructors
    //
    //
    Vector(const Object, const int = VECTOR_DEFAULT_SIZE);
    Vector(const int, const Object, const Object);
    Vector(const IVector*);
    Vector(const Vector&);
    ~Vector();

    ////////////////////////////////////////////////////////////////////
    // Basic functions
    //
    //
    ////////////////////////////////////////////////////////////////
    // Basic access functions
    //
    //
    virtual Object getUndefined() const;
    virtual IVector* getCopy() const;

    ////////////////////////////////////////////////////////////////
    // Basic disposing functions
    //
    //
    virtual void empty();
    virtual void dispose();


    ////////////////////////////////////////////////////////////////
    // Basic assignment functions
    //
    //
    virtual void setUndefined(const Object);
    virtual void copyInfo(const IVector *);
    virtual void copy(const IVector *);
    virtual const IVector* operator= (const IVector*);

    ////////////////////////////////////////////////////////////////
    // Basic comparison functions
    //
    //
    virtual void setComparisonFunction(int (*) (const IVector*,
    const IVector*));
    virtual int compareTo(const IVector *) const;

    virtual bool operator==(const IVector *) const;
    virtual bool operator>=(const IVector *) const;
    virtual bool operator<=(const IVector *) const;
    virtual bool operator>(const IVector *) const;
    virtual bool operator<(const IVector *) const;
    virtual bool operator!=(const IVector *) const;

    ////////////////////////////////////////////////////////////////
    // Basic input/output functions
    //
    //
    virtual void print() const;
    virtual void read();

    ////////////////////////////////////////////////////////////////////
    // Access functions
    //
    //

    virtual bool isEmpty() const;
    virtual bool isFull() const;

    virtual int getSize() const;

    virtual Object getFirstObject() const;
    virtual Object getLastObject() const;
    virtual Object getObjectAtPos(const int) const;

    virtual bool contains(const Object) const;
    virtual int find(const Object) const;

    ////////////////////////////////////////////////////////////////////
    // Standard Processing functions
    //
    //
    virtual void setSize(const int);

    virtual void setFirstObject(const Object);
    virtual void setLastObject(const Object);
    virtual void setObjectAtPos(const int, const Object);
    virtual void setAllObjects(const Object);

    virtual void insert(const Object);
    virtual void insertAtFront(const Object);
    virtual void insertAtEnd(const Object);
    virtual void insertAtPos(const int, const Object);

    virtual Object remove(const Object value);
    virtual Object removeFromFront();
    virtual Object removeFromEnd();
    virtual Object removeFromPos(const int);

    virtual void copy(const Object*, const int);


    ////////////////////////////////////////////////////////////////////
    // Non-Standard Processing functions
    //
    //
    virtual Object* toArray() const;

    virtual void reverse();
    virtual void sort(const int);
    virtual void filter(bool (*) (const Object));
    virtual void map(Object (*) (const Object));
    virtual void append(const IVector*);

    ////////////////////////////////////////////////////////////////////
    // Overloaded Operators
    //
    //
    virtual Object operator[] (const int) const;


    ////////////////////////////////////////////////////////////////////
    // Input/Output Functions
    //
    //

    protected:

    ////////////////////////////////////////////////////////////////////
    // Helper Functions
    //
    //
    virtual void defaultValues();
    virtual void ensureMemory(const int);

    ////////////////////////////////////////////////////////////////////
    // Data Members
    //
    //
    int m_nrElem, // number of vector elements
    m_nrCells; // size of vector

    Object undefined; // reference to an undefined object

    Object *m_pVect;

    int (*compare)(const IVector*, //pointer to a function
    const IVector*); //that compares two vectors
    };


    #endif

  9. #9
    i/e regjistruar
    Anėtarėsuar
    28-04-2002
    Vendndodhja
    USA
    Postime
    230
    /* Implementation for Vector
    */

    #ifndef _Vector_cpp_
    #define _Vector_cpp_

    #include
    #include "myVector.h"

    ////////////////////////////////////////////////////////////////////
    // Constructors & Desctructors
    //
    //
    template
    Vector::Vector(const Object undef, const int cells):
    undefined(undef), compare(NULL)
    {
    defaultValues();
    Vector(cells, undefined, undefined);
    }
    template
    Vector::Vector(const int cells, const Object val, const Object undef):
    undefined(undef), compare(NULL)
    {
    defaultValues();
    if(cells > 0)
    {
    m_nrCells = cells;
    m_pVect = new Object[m_nrCells];
    assert(m_pVect != NULL);
    for(int i = 0; i < m_nrCells; i++)
    m_pVect[i] = val;
    }
    }
    template
    Vector::Vector(const IVector* pIVector):compare(NULL)
    {
    defaultValues();
    copy(pIVector);
    }
    template
    Vector::Vector(const Vector& vect):compare(NULL)
    {
    defaultValues();
    copy(&vect);
    }
    template
    Vector::~Vector()
    {
    dispose();
    }

    ////////////////////////////////////////////////////////////////////
    // Basic functions
    //
    //
    ////////////////////////////////////////////////////////////////
    // Basic access functions
    //
    //
    template
    Object Vector::getUndefined() const
    {
    return undefined;
    }
    template
    IVector* Vector::getCopy() const
    {
    IVector *temp = new Vector(undefined);
    assert(temp != NULL);

    temp->copy(this);
    return temp;
    }


    ////////////////////////////////////////////////////////////////
    // Basic disposing functions
    //
    //
    template
    void Vector::empty()
    {
    m_nrElem = 0;
    }
    template
    void Vector::dispose()
    {
    if(m_pVect != NULL)
    delete m_pVect;

    defaultValues();
    }

    ////////////////////////////////////////////////////////////////
    // Basic assignment functions
    //
    //
    template
    void Vector::setUndefined(const Object undef)
    {
    undefined = undef;
    }
    template
    void Vector::copyInfo(const IVector *pV)
    {
    if(this == pV || pV == NULL) return;

    setUndefined(pV->getUndefined());
    }
    template
    void Vector::copy(const IVector* pIVector)
    {
    if(this == pIVector || pIVector == NULL) return;

    copyInfo(pIVector);
    ensureMemory(pIVector->getSize());

    m_nrElem = pIVector->getSize();
    for(int i = 0; i < getSize(); i++)
    m_pVect[i] = pIVector->getObjectAtPos(i);

    }
    template
    const IVector* Vector::operator= (const IVector *pV)
    {
    copy(pV);
    return this;
    }

    ////////////////////////////////////////////////////////////////
    // Basic comparison functions
    //
    //
    template
    void Vector::setComparisonFunction(int (*cmp) (const IVector*,
    const IVector*))
    {
    compare = cmp;
    }
    template
    int Vector::compareTo(const IVector *pVector) const
    {
    if(compare == NULL)
    {
    if(pVector == NULL) return COMPARE_GREATER;

    //default comparison: compares the getSizes
    if(getSize() > pVector->getSize()) return COMPARE_GREATER;
    if(getSize() < pVector->getSize()) return COMPARE_LESS;
    return COMPARE_EQUAL;
    }
    return compare(this, pVector);
    }
    template
    bool Vector::operator==(const IVector *pV) const
    {
    return compareTo(pV) == COMPARE_EQUAL;
    }
    template
    bool Vector::operator>=(const IVector *pV) const
    {
    return compareTo(pV) >= COMPARE_EQUAL;
    }
    template
    bool Vector::operator<=(const IVector *pV) const
    {
    return compareTo(pV) <= COMPARE_EQUAL;
    }
    template
    bool Vector::operator>(const IVector *pV) const
    {
    return compareTo(pV) > COMPARE_EQUAL;
    }
    template
    bool Vector::operator<(const IVector *pV) const
    {
    return compareTo(pV) < COMPARE_EQUAL;
    }
    template
    bool Vector::operator!=(const IVector *pV) const
    {
    return compareTo(pV) != COMPARE_EQUAL;
    }

    ////////////////////////////////////////////////////////////////
    // Basic input/output functions
    //
    //
    template
    void Vector::print() const
    {
    cout << "(";
    for(int i = 0; i < getSize() - 1; i++)
    cout << m_pVect[i] << " ";

    if(getSize() >= 1)
    cout << m_pVect[getSize()-1];
    cout << ")";
    }
    template
    void Vector::read()
    {
    int nrElem = 0, i = 0;
    Object elem = undefined;

    cout << "Enter number of elements > ";
    cin >> nrElem;

    if(nrElem <= 0) return;

    ensureMemory(getSize() + nrElem);
    while(i < nrElem)
    {
    cout << "Enter element at position " << (i+getSize()) << " > ";
    cin >> elem;
    m_pVect[i + getSize()] = elem;
    i++;
    }
    m_nrElem += nrElem;
    }
    template
    ostream& operator<< (ostream &out, const IVector *pIVector)
    {
    if(pIVector == NULL) cout << "NULL";
    else pIVector->print();
    return out;
    }

    template
    istream& operator>> (istream &in, IVector *pIVector)
    {
    if(pIVector != NULL) pIVector->read();
    return in;
    }
    ////////////////////////////////////////////////////////////////////
    // Access functions
    //
    //
    template
    bool Vector::isEmpty() const
    {
    return getSize() == 0;
    }
    template
    bool Vector::isFull() const
    {
    return false;
    }
    template
    int Vector::getSize() const
    {
    return m_nrElem;
    }
    template
    Object Vector::getFirstObject() const
    {
    return getObjectAtPos(0);
    }
    template
    Object Vector::getLastObject() const
    {
    return getObjectAtPos(getSize() - 1);
    }
    template
    Object Vector::getObjectAtPos(const int i) const
    {
    if(i < 0 || i >= getSize()) return undefined;

    return m_pVect[i];
    }
    template
    bool Vector::contains(const Object value) const
    {
    return find(value) >= 0;
    }
    template
    int Vector::find(const Object value) const
    {
    for(int i = 0; i < getSize(); i++)
    if(value == m_pVect[i])
    return i;
    return -1;
    }

    ////////////////////////////////////////////////////////////////////
    // Standard Processing functions
    //
    //
    template
    void Vector::setSize(const int nrElem)
    {

    if(nrElem < 0) return;
    ensureMemory(nrElem);
    m_nrElem = nrElem;
    }

    template
    void Vector::setFirstObject(const Object value)
    {
    setObjectAtPos(0, value);
    }
    template
    void Vector::setLastObject(const Object value)
    {
    setObjectAtPos(getSize() - 1, value);
    }
    template
    void Vector::setObjectAtPos(const int i, const Object value)
    {
    if(i < 0 || i >= getSize()) return;

    m_pVect[i] = value;
    }
    template
    void Vector::setAllObjects(const Object value)
    {
    for(int i = 0; i < getSize(); i++)
    m_pVect[i] = value;
    }


    template
    void Vector::insert(const Object value)
    {
    insertAtFront(value);
    }
    template
    void Vector::insertAtFront(const Object value)
    {
    insertAtPos(0, value);
    }
    template
    void Vector::insertAtEnd(const Object value)
    {
    insertAtPos(getSize(), value);

    }
    template
    void Vector::insertAtPos(const int pos, const Object value)
    {
    int insert_at = pos;

    if(insert_at < 0 ) insert_at = 0;
    else if(insert_at > getSize()) insert_at = getSize();

    ensureMemory(1 + getSize());
    for(int i = getSize(); i > insert_at; i--)
    m_pVect[i] = m_pVect[i-1];
    m_pVect[insert_at] = value;

    m_nrElem++;
    }
    template
    Object Vector::remove(const Object value)
    {
    return removeFromPos(find(value));
    }
    template
    Object Vector::removeFromFront()
    {
    return removeFromPos(0);
    }
    template
    Object Vector::removeFromEnd()
    {
    return removeFromPos(getSize() - 1);
    }
    template
    Object Vector::removeFromPos(const int pos)
    {

    if(pos < 0 || pos >= getSize()) return undefined;

    Object value = m_pVect[pos];

    for(int i = pos; i < getSize(); i++)
    m_pVect[i] = m_pVect[i+1];

    m_nrElem--;

    return value;
    }

    template
    void Vector::copy(const Object *pObjects, const int size)
    {
    if(pObjects == NULL || size < 0)
    return;

    ensureMemory(size);
    m_nrElem = size;
    for(int i = 0; i < getSize(); i++)
    m_pVect[i] = pObjects[i];

    }

    ////////////////////////////////////////////////////////////////////
    // Non-Standard Processing functions
    //
    //
    template
    Object* Vector::toArray() const
    {
    if(getSize() <= 0) return NULL;

    Object *temp = new Object[getSize()];

    for(int i = 0; i < getSize(); i++)
    temp[i] = getObjectAtPos(i);
    return temp;
    }
    /************************************************** **************
    * reverse *
    ************************************************** **************/
    template
    void Vector::reverse()
    {
    int i = 0, j = getSize() - 1;

    Object temp;

    while(i <= j)
    {
    temp = m_pVect[i];
    m_pVect[i] = m_pVect[j];
    m_pVect[j] = temp;

    i++; j--;
    }
    }
    template
    void Vector::sort(const int order)
    {
    if(isEmpty()) return;

    for(int i = 0; i < getSize(); i++)
    {
    int index = i;
    for(int j = i + 1; j < getSize(); j++)
    switch(order)
    {
    case LIST_INCREASING_ORDER:
    if(getObjectAtPos(index) > getObjectAtPos(j))
    index = j;
    break;
    case LIST_DECREASING_ORDER:
    default:
    if(getObjectAtPos(index) < getObjectAtPos(j))
    index = j;
    break;
    }
    if(index != i)
    {
    Object temp = getObjectAtPos(i);
    setObjectAtPos(i, getObjectAtPos(index));
    setObjectAtPos(index, temp);
    }
    }
    }
    template
    void Vector::filter(bool (*f) (const Object))
    {
    int i = 0;
    while(i < getSize())
    {
    if(f(getObjectAtPos(i)) == true)
    removeFromPos(i);
    else i++;
    }
    }
    template
    void Vector::map(Object (*f) (const Object))
    {
    for(int i = 0; i < getSize(); i++)
    setObjectAtPos(i, f(getObjectAtPos(i)));
    }
    template
    void Vector::append(const IVector* pIVector)
    {
    if(pIVector == NULL || pIVector->getSize() == 0)
    return;

    ensureMemory(getSize() + pIVector->getSize());
    for(int i = 0; i < pIVector->getSize(); i++)
    m_pVect[i + getSize()] = pIVector->getObjectAtPos(i);

    m_nrElem += pIVector->getSize();
    }

    ////////////////////////////////////////////////////////////////////
    // Overloaded Operators
    //
    //
    /************************************************** *********
    * operator[] -- Access Function *
    * PRE : @this is properly initialized *
    * POST: None *
    ************************************************** *********/
    template
    Object Vector::operator[] (const int i) const
    {
    return getObjectAtPos(i);
    }

    ////////////////////////////////////////////////////////////////////
    // Input/Output Functions
    //
    //

    ////////////////////////////////////////////////////////////////////
    // Helper Functions
    //
    //
    template
    void Vector::defaultValues()
    {
    m_nrCells = 0;
    m_nrElem = 0;
    m_pVect = NULL;
    }

    template
    void Vector::ensureMemory(const int cells)
    {
    if(cells <0 || cells <= m_nrCells) return;

    m_nrCells = 2*cells + 1;


    Object *temp = new Object[m_nrCells];

    for(int i = 0; i < getSize(); i++)
    temp[i] = m_pVect[i];

    if(m_pVect != NULL)
    delete [] m_pVect;

    m_pVect = temp;
    }

    #endif

  10. #10
    * mbrojtesi me i mire * Maska e Static - Y
    Anėtarėsuar
    04-07-2002
    Vendndodhja
    Itali
    Postime
    15

    123456

    Cuna me bohet qefi qe po interesoheni...por vetem nje sugjerim kisha.Kete teme e hapa per arsye qe cdonjeri nga ne te perfitoje dicka.Nuk mjafton nje copy - paste se eshte shume e kollajshme... por per mendimin tim cdonjeri duhet te shkruaje nje program te tijin...nje pune te thjeshte dhe nqs eshte e mundur ne shqip se keshtu te pakten e morim vesh...
    Nejse..ju uroj nje pune te mbare dhe INSHALLAH me postime te tjera...

    Paqe
    All Rights Reserved © SkYLIGht 2002

  11. Faqja 0 prej 3 FillimFillim 12 FunditFundit

    Tema tė Ngjashme

    1. Adem Jashari - Hero i Kosovės
      Nga JONI 1 nė forumin Elita kombėtare
      Pėrgjigje: 296
      Postimi i Fundit: 05-03-2023, 21:58
    2. Ushtrime per muskulaturen e fytyres dhe te qafes dhe te gjoksit.
      Nga Mina nė forumin Bukuri dhe estetikė
      Pėrgjigje: 2
      Postimi i Fundit: 11-04-2011, 07:30
    3. Ushtrime pėr PHP & MySQL?
      Nga lars_peter nė forumin Arti i programimit
      Pėrgjigje: 1
      Postimi i Fundit: 07-11-2008, 09:57
    4. Si te jeni sa me te shendetshem.
      Nga Estella nė forumin Bukuri dhe estetikė
      Pėrgjigje: 16
      Postimi i Fundit: 07-09-2003, 02:37

    Regullat e Postimit

    • Ju nuk mund tė hapni tema tė reja.
    • Ju nuk mund tė postoni nė tema.
    • Ju nuk mund tė bashkėngjitni skedarė.
    • Ju nuk mund tė ndryshoni postimet tuaja.
    •