# Shkenca > Informatikë dhe Internet > Arti i programimit >  C++ - Ushtrime

## berat96

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,...

----------


## Ujku_I_Vjeter

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.

----------


## McKINLEY

@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.

----------


## Static - Y

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 <stdio.h>

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    :Paqe:

----------


## Olti

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 <iostream.h>
#include <stdlib.h>
#include <conio.h>

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"<<endl;
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]) :shkelje syri:  {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"<<endl;break;}
if (matrix[2][0]=='X' && matrix[2][0]==matrix[1][1] && matrix[1][1]==matrix[0][2]) {cout<<"Giocatore 1 vince"<<endl;break;}
if (matrix[0][0]=='X' && matrix[0][0]==matrix[1][0] && matrix[1][0]==matrix[2][0]) {cout<<"Giocatore 1 vince"<<endl;break;}
if (matrix[0][1]=='X' && matrix[0][1]==matrix[1][1] && matrix[1][1]==matrix[2][1]) {cout<<"Giocatore 1 vince"<<endl;break;}
if (matrix[0][2]=='X' && matrix[0][2]==matrix[1][2] && matrix[1][2]==matrix[2][2]) {cout<<"Giocatore 1 vince"<<endl;break;}
if (matrix[0][0]=='X' && matrix[0][0]==matrix[0][1] && matrix[0][1]==matrix[0][2]) {cout<<"Giocatore 1 vince"<<endl;break;}
if (matrix[1][0]=='X' && matrix[1][0]==matrix[1][1] && matrix[1][1]==matrix[1][2]) {cout<<"Giocatore 1 vince"<<endl;break;}
if (matrix[2][0]=='X' && matrix[2][0]==matrix[2][1] && matrix[2][1]==matrix[2][2]) {cout<<"Giocatore 1 vince"<<endl;break;}

if (sum == 9){cout<<"IL, gioco e finito e nessuno ha vinto hahaha, fatte schifo tutti a due!!!"<<endl; break;} //sum=9 because there are only 9 boxes in the game
//player 2's turn

cout<<"Il giocatore due   'O': scegli il numero  la colonna"<<endl;
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]) :shkelje syri:  {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"<<endl;break;}
if (matrix[2][0]=='O' && matrix[2][0]==matrix[1][1] && matrix[1][1]==matrix[0][2]) {cout<<"Giocatore 2 vince"<<endl;break;}
if (matrix[0][0]=='O' && matrix[0][0]==matrix[1][0] && matrix[1][0]==matrix[2][0]) {cout<<"Giocatore 2 vince"<<endl;break;}
if (matrix[0][1]=='O' && matrix[0][1]==matrix[1][1] && matrix[1][1]==matrix[2][1]) {cout<<"Giocatore 2 vince"<<endl;break;}
if (matrix[0][2]=='O' && matrix[0][2]==matrix[1][2] && matrix[1][2]==matrix[2][2]) {cout<<"Giocatore 2 vince"<<endl;break;}
if (matrix[0][0]=='O' && matrix[0][0]==matrix[0][1] && matrix[0][1]==matrix[0][2]) {cout<<"Giocatore 2 vince"<<endl;break;}
if (matrix[1][0]=='O' && matrix[1][0]==matrix[1][1] && matrix[1][1]==matrix[1][2]) {cout<<"Giocatore 2 vince"<<endl;break;}
if (matrix[2][0]=='O' && matrix[2][0]==matrix[2][1] && matrix[2][1]==matrix[2][2]) {cout<<"Giocatore 2 vince"<<endl;break;}

}
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"<<endl;
cout<<"\t\t             1  "<<matrix[0][0]<<" | "<<matrix[0][1]<<" | "<<matrix[0][2]<<endl;
cout<<"\t\t               ---|---|---\n";
cout<<"\t\t             2  "<<matrix[1][0]<<" | "<<matrix[1][1]<<" | "<<matrix[1][2]<<endl;
cout<<"\t\t               ---|---|---\n";
cout<<"\t\t             3  "<<matrix[2][0]<<" | "<<matrix[2][1]<<" | "<<matrix[2][2]<<"\n\n\n";
}

----------


## Olti

#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#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<nMAX){
 if(v[i]<min)
   min=v[i];
 i=i+1;}
 }

void valore_minimo()
{cout<<"Il valore minimo del vettore : "<<min;}

----------


## berat96

Ja nje ushtrim i thjeshte.  Implementoni klasen abstrakte IVector:

#ifndef _IVector_h_
#define _IVector_h_

#include <fstream.h>

const int
  VECTOR_DEFAULT_SIZE = 3;

template <class Object>
class IVector
{

public:

////////////////////////////////////////////////////////////////////
// Basic functions
//
// 
    ////////////////////////////////////////////////////////////////
    // Basic access functions
    //
    //    
    virtual Object getUndefined() const= 0;
    virtual IVector<Object>* 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<Object> *)= 0; 
    virtual void copy(const IVector<Object> *)= 0; 
    virtual const IVector<Object>* operator= (const IVector<Object>*)= 0;

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

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

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

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


////////////////////////////////////////////////////////////////////
// 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<Object>*)= 0;  

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


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


};

#endif

----------


## berat96

/*Header file for Vector - An implementation of IVector Class  
 * using arrays
 */

#ifndef _Vector_h_
#define _Vector_h_

#include "myIVector.h"

template <class Object>
class Vector : public IVector<Object>
{

public:

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

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

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


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

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

    virtual bool operator==(const IVector<Object> *) const;
    virtual bool operator>=(const IVector<Object> *) const;
    virtual bool operator<=(const IVector<Object> *) const;
    virtual bool operator>(const IVector<Object> *) const;
    virtual bool operator<(const IVector<Object> *) const;
    virtual bool operator!=(const IVector<Object> *) 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<Object>*);  

////////////////////////////////////////////////////////////////////
// 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<Object>*,  //pointer to a function
                   const IVector<Object>*); //that compares two vectors
};


#endif

----------


## berat96

/* Implementation for Vector
 */

#ifndef _Vector_cpp_
#define _Vector_cpp_

#include <assert.h>
#include "myVector.h"

////////////////////////////////////////////////////////////////////
// Constructors & Desctructors
//
//     
    template <class Object>
    Vector<Object>::Vector(const Object undef, const int cells): 
                                undefined(undef), compare(NULL)                       
    {
        defaultValues();
        Vector<Object>(cells, undefined, undefined);
    }
    template <class Object>
    Vector<Object>::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 <class Object>
    Vector<Object>::Vector(const IVector<Object>* pIVector):compare(NULL)
    {
        defaultValues();
        copy(pIVector);
    }
    template <class Object>
    Vector<Object>::Vector(const Vector<Object>& vect):compare(NULL)
    {
        defaultValues();
        copy(&vect);
    }
    template <class Object>
    Vector<Object>::~Vector()
    {       
        dispose();
    }

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

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


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

       defaultValues();
    }

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

        setUndefined(pV->getUndefined());
    }
    template <class Object>
    void Vector<Object>::copy(const IVector<Object>* 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 <class Object>
    const IVector<Object>* Vector<Object>::operator= (const IVector<Object> *pV)
    {
       copy(pV);
       return this;
    }

    ////////////////////////////////////////////////////////////////
    // Basic comparison functions
    //
    //                
    template <class Object>
    void Vector<Object>::setComparisonFunction(int (*cmp) (const IVector<Object>*, 
                                                           const IVector<Object>*))
    {
       compare = cmp;
    } 
    template <class Object>
    int Vector<Object>::compareTo(const IVector<Object> *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 <class Object> 
    bool Vector<Object>::operator==(const IVector<Object> *pV) const
    {
        return compareTo(pV) == COMPARE_EQUAL;
    }
    template <class Object> 
    bool Vector<Object>::operator>=(const IVector<Object> *pV) const
    {
        return compareTo(pV) >= COMPARE_EQUAL;
    }
    template <class Object> 
    bool Vector<Object>::operator<=(const IVector<Object> *pV) const
    {
        return compareTo(pV) <= COMPARE_EQUAL;
    }
    template <class Object> 
    bool Vector<Object>::operator>(const IVector<Object> *pV) const
    {
        return compareTo(pV) > COMPARE_EQUAL;
    }
    template <class Object> 
    bool Vector<Object>::operator<(const IVector<Object> *pV) const
    {
        return compareTo(pV) < COMPARE_EQUAL;
    }
    template <class Object> 
    bool Vector<Object>::operator!=(const IVector<Object> *pV) const
    {
        return compareTo(pV) != COMPARE_EQUAL;
    }

    ////////////////////////////////////////////////////////////////
    // Basic input/output functions
    //
    //                    
    template <class Object>
    void Vector<Object>::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 <class Object>
    void Vector<Object>::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 <class Object>
    ostream& operator<< (ostream &out, const IVector<Object> *pIVector)
    {
       if(pIVector == NULL) cout << "NULL";
       else                 pIVector->print();
       return out;
    }

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

	 return m_pVect[i];
   }
   template <class Object>
   bool Vector<Object>::contains(const Object value) const
   {
     return find(value) >= 0;
   }
   template <class Object>
   int Vector<Object>::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 <class Object>
   void Vector<Object>::setSize(const int nrElem)
   {

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

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

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


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

   }
   template <class Object>
   void Vector<Object>::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 <class Object>
   Object Vector<Object>::remove(const Object value)
   {
       return removeFromPos(find(value));       
   }
   template <class Object>
   Object Vector<Object>::removeFromFront()
   {      
       return removeFromPos(0);
   }
   template <class Object>
   Object Vector<Object>::removeFromEnd()
   {
      return removeFromPos(getSize() - 1);
   }
   template <class Object>
   Object Vector<Object>::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 <class Object>
    void Vector<Object>::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 <class Object>
   Object* Vector<Object>::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 <class Object>
   void Vector<Object>::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 <class Object>
   void Vector<Object>::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 <class Object>
   void Vector<Object>::filter(bool (*f) (const Object))
   {       
       int i = 0;
       while(i < getSize())
       {
         if(f(getObjectAtPos(i)) == true)
             removeFromPos(i);
         else i++;
       }
   } 
   template <class Object>
   void Vector<Object>::map(Object (*f) (const Object))
   {
       for(int i = 0; i < getSize(); i++)
           setObjectAtPos(i, f(getObjectAtPos(i)));
   }
   template <class Object>
   void Vector<Object>::append(const IVector<Object>* 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 <class Object>
    Object Vector<Object>::operator[] (const int i) const
    {        
        return getObjectAtPos(i);
    }   

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

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

    template <class Object>
    void Vector<Object>::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

----------


## Static - Y

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  :Paqe:

----------


## Static - Y

Ushtrim qe kerkon nje numer ne nje vektor numrash te plote...





*#include <stdio.h>
void main() {

     int VLERAT[100]; int VEKERKUAR,PERGJIGJA,I,N;
     typedef enum {falco , vertete} boolean;
     boolean EGJETA;

     printf("Sa vlera ne vektor ? ");
     scanf("%d",&N);

for (I=0;I<N;I++){
     printf("Fut vleren %d :   ", I+1);
     scanf("%d",&VLERAT[I]);}


for (I=0;I<N;I++){
     printf("%d",VLERAT[I]);}

do {
     printf("Fut vleren qe do te kerkosh  ");
     scanf("%d",&VEKERKUAR);

     I=0; EGJETA=falco;
     while((I<N) && !GJETA) {
if (VLERAT[I]==VEKERKUAR)
EGJETA=vertete; I=I+1;
if (EGJETA)
     printf("Vlera : %d",&VLERAT[I-1]);
else printf("Vlera e kerkuar nuk gjendet \n");
do { printf("Do te kerkosh perseri ?
                   (0/1: 0=jo, 1=po)");

     scanf("%d",&PERGJIGJA); }

while (!(PERGJIGJA==0||PERGJIGJA=1));}
while  (PERGJIGJA==1);
}*

----------


## berat96

Static-Y,

Kodi eshte i imi dhe jo cut-paste nga interneti. Programet i kam vetem ne anglisht dhe fatkeqsisht nuk kam kohe qe t'i kthej ne shqip.

Faqja eshte per ushtrime ne C++. Deri tani shembujt e dhene jane me shume nga C. Programi qe solla ilustron shume tipare te gjuhes C++ qe nuk gjenden ne C, per shembull:

1- Klasat
2-Klasat abstrakte dhe funksionet virtuale
3-Inheritance (trashgimnine) nga njera klase ne tjeter
4-Perdorimin e templates si per funksionet ashtu edhe per klasat.
5. Overloading of operators (mbingarkimin e operatoreve)

Me vone, ne varesi te kohes, mund te shpjegoje me ne detaje sesi duhen perdorur keto.

Per mendimin tim eshte mire qe ne cdo kod qe jepet te jete Object Oriented, pra sa me i paster C++ dhe jo nje perzierje e C me C++ (pavaresisht se C eshte nenbashkesi e C++).

----------


## Olti

Eshte e rendesishme qe te shkruajme disa fjale per evulimin e C++ , duke filluar nga origjina e tij per te kuptuar me mire strukturen, qellimet dhe motivimet qe kane sjelle ne standarizimin e ksaj gjuhe,kshtu siç eshte ne formen aktuale.
Antenati me i drejt i C++ eshte C, qe quhet CWC, dmth. C With Classes, zvilupuar nga Bearne Strustrup ne 1980.U bente fjale per nje ampliament te C te Kernighan e Ritchie, gati komplet i bazuar ne kostruktet e gjuhes Simula.
Idea e Stroustrup ishte ajo qe te perdorte C, gjuhe shume e fuqishme dhe fleksible, per te zhvilluar simulime te dimensioneve te medha qe nuk mund tu realizonin me Simula.Ky koncept ngeli shtylla ne te gjitha fazat e svilipimit te C++ si gjuhe e orientuar ne aplikacione me shume impenjative nga ana e dimensioneve , nga rreshtat e codit dhe fuqia elaboruse.
Zgjedhja e gjuhes C eshte shume e lidhur me piket me te forta te tij;
-Eficence ;
-Fleksibilitet ;
-Portabilitet ;
Portabiliteti i karakterizon programet ne C sepse jane te thjeshta per tu kompiluar ne piataforma te ndryshme.
C-ja eshte gjuha me fleksibile, mbas assembly puro, perderisa i adoptohet çdo stili dhe teknike dhe mbi te gjitha perdoret per te perballuar çdo lloj problemi ne lidhje me programimin.Edhe eficenza e C eshte shume e larte.(eficenza e C++ e perdorur ne maksimunim e mundesive te tij, dmth per qellimin qe eshte projektuar eshte me e keqe ne krahasim me ate te C standard,  dhe duke ngelur me e mire ne krahasim me shume gjuhe te tjera, duke filluar nga Visual Basic,Pascal,,Delphi e deri tek Java.

Dy fjale dhe per kompilatoret e C 
Ne fakt ne boten e personal  compiutrave (PC) gjerat filluan te levizin pak me vonese: ne 1988 doli me ne fund ne qarkullim  compilatori i C++ qe ishte me teper nje bug i madh i veshur si kompilator.
Me kalimin e kohes u permiresua shume pas blerjes nga ana  e Symantech te Peter Norton. Pas pak muajsh vijne ne shitje dhe kompilatore te tjere si Borland, Watcom dhe natyrisht Microsoft.

----------


## claude

Hey shoke,

basoj qe edhe ky programi im do t'ju perqeje. Eshte nje program qe perdoret per te vene ne komunikim 2 computera me ane portes seriale. Natyrisht personat qe nuk dine se ç'fare eshte porta seriale, ç'fare funksioni ka ajo, ç'fare eshte UART dhe si funksionon UART do te kuptojne pak.

Megjithate kush ka nevoje per sqarime te metejshme mund te kerkoje ato ne adresen time.

Ja programi:

#include<dos.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

int scelta=0;
unsigned int RBR,THR,IER,IIR,LCR,MCR,LSR,MSR,DLL,DLH;

void inizializzazione(void){
 unsigned int port;
 unsigned char car;

 RBR=port;
 THR=port;
 DLL=port;
 DLH=port+1;
 IER=port+1;
 IIR=port+2;
 LCR=port+3;
 MCR=port+4;
 LSR=port+5;
 MSR=port+6;

 outportb(LCR,0x80);
 outportb(DLL,0x60);
 outportb(DLH,0x00);
 outportb(LCR,0x0A);
 outportb(MCR,0x03);
 outportb(IER,0x00);
 car=inportb(RBR) & 0x7F;
 outportb(THR,0x00);
}

int controlli(unsigned char caratt){
 if(caratt==13){
	printf("\n");
	if(scelta==1) outportb(THR,13);
	if(scelta==2) outportb(THR,138);
	return(1);
 }
 if(caratt==138){
	outportb(THR,101);
	delay(10);
	outportb(THR,39);
	return(1);
 }
}

unsigned carattere_ricezione(unsigned char caratt){
 switch(caratt){
	case 28: return(156); break;
	case  2: return(130); break;
	case 23: return(151); break;
	case  5: return(133); break;
	case 21: return(149); break;
	default: return(caratt);
 }
}

unsigned char ricezione(void){
 unsigned char caratt;

 caratt=inportb(RBR);
 if(caratt==13) printf("\n");
 caratt=carattere_ricezione(caratt);
 textcolor(RED);
 putch(caratt);
 return(caratt);
}

unsigned char trasmissione(void){
 unsigned char caratt;

 caratt=getch();
 textcolor(GREEN);
 putch(caratt);
 while(!(inportb(LSR)&0x20));
 if(controlli(caratt)!=1) outportb(THR,caratt);
 return(caratt);
}

void main(void){
 unsigned char errore,flag=0;

 clrscr();

 inizializzazione();

 printf("Tipo di comunicazione:\n");
 printf("1) PC - PC\n");
 printf("2) PC - Terminale\n");

 do{
	scanf("%d",&scelta);
	clrscr();
 }while(!((scelta==1)||(scelta==2)));

 while(flag!=27){
	errore=inportb(LSR);
	if((errore & 0x1E)!=0) flag=1;
	else {
	 if((errore & 0x01)!=0) flag=ricezione();
	 else {
		if(kbhit())
		flag=trasmissione();
	 }
	}
 }
}

Pershendetje nga CLAUDE!

----------


## claude

Si mund te krijohet nje BOOT FDD?

Pershendetje!

----------


## Tech_Warrior

Claude

Programi yt per serial ports ka nje gabim. Aty nuk e ke bere inicializimin e variables port (po ma merr mendja se ne proceduren inicializuesi ishte dashte me qene port = adresen e portit te cilin e perdore). E dyta eshte se ky program punon vetem ne DOS.

Sa per BOOT FDD, a mendon ta besh me programim apo thjeshte ta perdoresh sistemin operativ ?

Te pershendes

----------


## claude

Faleminderit Tech Writer,

e kam harruar numrin e portes. Programi qe une kam bere punon dhe ne Windows, mjafton te trasportohet kodi ne VC++ dhe te ndrerrohen emrat e funksioneve te I/O rrespektivisht ne ato qe perdoren nga VC++. Natyrisht programi do te punoje vetem ne Windows 95/98. Per Windows2000/XP ka funksione te tjera.

Mendoj te bej:
programin qe shkruan ne BS(Boot Sector) dhe ate qe hapet per here te pare, pra kur behet BOOT i FDD.

Shendet!

----------


## Tech_Warrior

Sa per te shkruar ne Boot Sector, me duket se ne disketa boot sektori eshte sektori 0. Pra qkado qe te futesh ne sektorin 0, sistemi do te mundohet ta ekzekutoj.

Per ta programuar programin e pare startues, duhet qe krejt i/o (tastature dhe ekran) ta programosh vet pasiqe ke qasje vetem ne BIOS funksione.

Per ti'a lehtesuar punen vehtes une te kisha propozuar qe ta perdoresh DOS kernel (IO.SYS dhe MSDOS.SYS) sepse eshte mjafte i vogel ( < 64k) dhe ka mjafte funksione (varesishte se per qka e perdore), kurse komand editorin ta shkruash vet.

----------


## claude

Faleminderit!

Une e di shume mire se duhet te shkruaj ne BS (pra ai qe identifikohet me numrin 0), por nuk di cilin INT dhe ADRESEN E FUNKSIONIT qe duhet te therras nga BIOS-i per te shkruar ne kete sektor. 
Persa i perket KRNL jam duke krijuar nje vete. Ky qe po bej support-on pak gjera: tastiere, video card dhe I/O.

Shendet!

----------


## claude

Ah harrova! Kam perdorur ASM dhe C.

----------

