Portali
Posto temė tė re Pėrgjigju temės Faqja 1 e 2
Shko tek faqja 1, 2  Tjetėr
Ushtrime ne C++ 
Autori Mesazh

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh Ushtrime ne C++ 
 
Ne kete teme do te keni mundesi qe te krijoni nje program tuajin per c++ por vetem duke shkruajtur kode te cilat mund te kompilohen ne c++....
Se pari do te filloj me disa ushtrime te thjeshta per te pare se sa ne gjendje jane antaret e forumit..

1. nje program i cili shfaq ne ekran kete:
::::::une jam agent0016:::::
//eshte programi me i thjeshte per c++
#include <iostream>
using namespace std;
int main(){
cout<<"une jam agent0016"<<endl;
return 0;
}
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh re: Ushtrime ne C++ 
 
// Llogaritja e Sipėrfaqes dhe Perimetrit tė Rrethit

#include <iostream>
            #include <conio.h>


                    const double Pi = 3.141593;

                    void main(){
                    double siperfaqja, perimetri, r = 2.5;

                        siperfaqja = Pi * r * r;
                        perimetri = 2 * Pi * r;

                        cout << "\n LLOGARITJET per Rrethin\n" << endl;

                        cout << "Rrezja: " << r << endl
                        << "Siperfaqja: " << siperfaqja << endl
                        << "Perimetri: " << perimetri << endl;


                        getch();
                }/* <conio.h> dhe getch(); janė pėrdor pasi qė ėshtė pėrdorur Compiler-i i Borlandit pėr C  */
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh re: Ushtrime ne C++ 
 
//program qe kthen temperaturen nga celcius ne farenhiet

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
   float  value, res;
   char letter;
   cout<< "Nese temperatura e dhene eshte ne Fahrenheit, shtypni F; nese eshte ne Celsius, shtypni C."<<endl;
   cin>> letter;
   cout<< "Jepni vleren e temperatures."<<endl;
   cin>> value;
   cout<<fixed<<setprecision(2);
   if (letter == 'F' || letter == 'f')
  
      res=(value -32)/1.8;
   cout << "Temperatura ne Celsius eshte " << res <<" grade celsius"<<endl;
   if (letter == 'C' || letter == 'c')
      {res=value*1.8+32;
   cout <<"Temperatura ne Fahrenheit eshte " <<res<<"grade fahrenheit"<<endl;
}
else cout<<"Ju lutem jepni nje shkronje te vlefshme."<<endl;
   return 0;
}
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh re: Ushtrime ne C++ 
 
Nje Pyetje kisha une
Cili eshte qellimi i kesaj teme?
Eshte nje kurs per c++ apo nje prove per te pare se sa dime  ne?
 



Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit MSN Messenger

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh re: Ushtrime ne C++ 
 
thjesht nje teme qe ka ushtrime ne c++, mund te mesojne anetaret po te duan dhe te japin edhe ushtrime per tu zgjidhur ose te zgjidhura.... Laughing
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh re: Ushtrime ne C++ 
 
// Llogaritja e numrit mė tė madh(MAX)
Kodi:
#include <iostream>
                    #include <conio.h>
                    void main()
                    {
                        float x, y;
                        cout << "Jepi dy numra te ndryshem: \n";
                        if( !(cin >> x && cin >> y))
                        {
                            cout << "Gabim!" << endl;
                        }
                        else
                        {
                            cout << "\n Numri me i madh eshte: "
                                    << (x > y ? x : y) << endl;
                        }

                        getch();
                    }
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh re: Ushtrime ne C++ 
 
#include <iostream>
using namespace std;

main(){
char A[6]={'A','B','C','D','E','F'};
for(int j=5;j>=0;j--){
for(int i=0;i<=j;i++){
cout<<A[i];
}
cout<<endl;
}

}

shfaq ne ekran kete

ABCDEF
ABCDE
ABCD
ABC
AB
A
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh re: Ushtrime ne C++ 
 
Hanoi towers

#include <iostream.h>
void hanoi(int numDisks, int startPost, int endPost, int freePost);

int main()
{
   cout << "Kullat e Hanoit" << endl;
   int numDisks;
   do
   {
       cout << "Sa disqe?  n <= 12" << endl;
       cin >> numDisks;
   }while (numDisks > 12 || numDisks < 1);

   hanoi(numDisks, 1, 3, 2);
   cout << "Problemi u zgjidh!" << endl;

   return 1;
}

void hanoi(int numDisks, int startPost, int endPost, int freePost)
{
   if (numDisks == 1)
       cout << "Leviz nga " << startPost << "
tek " << endPost << endl;
   else
   {
       hanoi(numDisks-1, startPost, freePost, endPost);
       hanoi(1, startPost, endPost, freePost);
       hanoi(numDisks-1, freePost, endPost, startPost);
   }
}
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh re: Ushtrime ne C++ 
 
//This program will read in a five digit integer and then will print each number forming this integer.
//To do this will be used the division and modulus operators.
#include <iostream>//access of stream
using namespace std;
int main()//the main function is in every program
{
   int num, n1, n2, n3 ,n4, n5;//declaring the integer that will be entered and 5 integers in which will be stored the 5 digits
   cout<<"Please enter a five digit integer.\n";//Prompting the user for the integer
   cin>>num;//storing the five digit integer into num
   n1=num/10000;//Using the division with 10000 i will get stored in n1 the first digit of the integer
   num=num%10000;//The remander which will be the result of this operation(modulus operation) will give me the 4 last digits of the integer entered and will store it in num giving it a new value
   n2=num/1000;//in this way i will get the second digit
   num=num%1000;//using the modulus operator to get the 3 last digits of the number
   n3=num/100;//third digit is stored in n3
   num=num%100;//last 2 digits
   n4=num/10;//fourth digit is stored in n4
   n5=num%10;//this way i have the last digit which is the remainder of the 2 digit number stored in num divided by 10
   cout<<"The number you entered is:     \n"<<n1<<"      "<<n2<<"      "<<n3<<"      "<<n4<<"      "<<n5<<endl;
   return 0;
}
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh re: Ushtrime ne C++ 
 
#include <iostream>
using namespace std;
int main()
{
int time;
cout<<"Please enter the time in the format HHMM in a 24 hour format.\n";
cin>>time;
if (time>=5000 || time<=9000)
cout<<"Miremengjes, si u gdhite sot?"<<endl;
if (time>9000 || time <=1200)
cout<<"Me ne fund u zgjove ti gjumashi..."<<endl;
if (time>1200 || time<=1400)
cout<<"He more ke ngrene dreke akoma apo si e ke hallin??"<<endl;
if (time>1400 || time<=1800)
cout<<"Uaaa do te besh greve urie kshu...?"<<endl;
if (time>1800 || time<=2200)
cout<<"Mos shih shume TV ama..."<<endl;
if (time>2200 || time<=2400)
cout<<"Hajt kris tani.. vrap ne shtrat."<<endl;
if (time>2400 || time<5000)
cout<<"Puuu sa here te kam thene mos rri zgjuar duke pare porno..."<<endl;
return 0;
}
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh re: Ushtrime ne C++ 
 
class cl {
  // ...
public:
  friend void frnd(cl ob);
 // ...
 };

listing 2
#include <iostream>
using namespace std;

class myclass {
  int a, b;
public:
  myclass(int i, int j) { a=i; b=j; }
  friend int sum(myclass x);
};

// Note: sum() is not a member function of any class.
int sum(myclass x)
{
  /* Because sum() is a friend of myclass, it can
     directly access a and b. */

  return x.a + x.b;
}

int main()
{
  myclass n(3, 4);

  cout << sum(n);

  return 0;
}
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh re: Ushtrime ne C++ 
 
/******************************* PLOOP.CPP ************************************
* Example showing the use of pointers and arrays in a loop         1998-09-02 *
*                                                                   Agner Fog *
*                                                                             *
* The same loop is made in three different ways.                              *
******************************************************************************/
#include <iostream.h>
#include <conio.h>

const int ARRAYSIZE = 10;

void main ()
{
   int i;  float f[ARRAYSIZE];  float * p;

   // method 1: index through array
   for (i=0; i<ARRAYSIZE; i++)  cout << f[i] << "\n";


   // method 2: use pointer to go through array
   p = f;
   for (i=0; i<ARRAYSIZE; i++)
   {
      cout << *p << "\n";
      p++;
   }


   // method 3: use pointer also as loop counter
   for (p=f; p<f+ARRAYSIZE; p++)  cout << *p << "\n";

   getch();
}
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh Re: Ushtrime Ne C++ 
 
Me sa kam pare une, shumica e ketyre ushtrimeve qe ke vene ti Agent , ndodhet ne librat  e C++.... KOMPLIMENTE  per zgjidhjen e tyre !!!
 



Offline Shiko profilin e anėtarit Dėrgo mesazh privat

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh Re: Ushtrime Ne C++ 
 
sqarohu icik me mire se nuk po te kuptoj!!!!

gjeni gabimet ne kete ushtrim Smile

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

class Book{

public:

    //Book(int sz = 50);
    //~Book();

    void setDay(ifstream fn);
    void setMonth(ifstream fn);
    void setYear(ifstream fn);
    void setNpg(ifstream fn);
    void setIsbn(ifstream fn);
    void setCateg(ifstream fn);
    void setAid(ifstream fn);
    void setTitle(ifstream fn);

    int getDay() const;
    int getMonth() const;
    int getYear() const;
    int getNpg() const;
    int getIsbn() const;
    string getCateg() const;
    int getAid() const;
    string getTitle() const;
    
private:

    int d; //day

    int m; //month

    int y; //year

    int npg; //number of pages

    int isbn; //ISBN 13 digits number

    string categ; //category of the title

    int aid; //author ID

    string title; //title of the book

    int sz;

    //Book *data;
};

class Author{

public:

    //Author(int sz = 50);
    //~Author();


    void setFname(ifstream fn2);
    void setLname(ifstream fn2);
    void setAid(ifstream fn2);

    string getFname() const;
    string getLname() const;
    int getAid() const;
    
private:

    string fname; //the first name of the author

    string lname; //the last name of the author

    int aid; //author id

    int sz;

    //Author *data;
};




int main(){

    char choice;
    
    do{
        ifstream fn1;

        ifstream fn2;
        
        string ch;        

        string filename1 = "book.txt";

        string filename2 = "author.dat";

        cout<<"Welcome!!!"<<endl;

        cout<<"Please enter a filename: ";

        cin>>ch;

        if(ch == filename1){

            fn1.open(filename1.c_str());

            cout<<"File "<<filename1<<" succesfully opened!!!"<<endl;


            Book::setNpg(fn1);
            Book::setIsbn(fn1);
            Book::setCateg(fn1);
            Book::setDay(fn1);
            Book::setMonth(fn1);
            Book::setYear(fn1);
            Book::setAid(fn1);
            Book::setTitle(fn1);

            cout<<"The file: "<<endl;
            cout<<endl;

            cout<< Book::getAid();

            fn1.close();

        }

        else if(ch == filename2){

            fn2.open(filename2.c_str());

            cout<<"File "<<filename2<<" succesfully opened!!!"<<endl;

            Author::setFname(fn2);
            Author::setLname(fn2);
            Author::setAid(fn2);

        }
        else
            cout<<"Please enter the exact filename if you know it!!!"<<endl;

        cout<<"Enter [Y/y] to enter the filename again or [N/n] to exit the program now: ";
        cin>>choice;

    }while(choice == 'Y' || choice == 'y');
    
    
    return 0;
}//end of main


/*
Book::Book(int sz){

    if(sz == 0)
        data = NULL;
    
    else
        data = new Book[sz];
}//end of constructor

Book::~Book(){

    if(sz == 1)
        delete data;

    else if(sz > 1)

        delete [] data;
}//end of destructor
*/

void Book::setNpg(ifstream fn){


    while(!'\0'){

    int npg[50];

    for(int i = 0; i < sz; i++)

        fn>>npg[i];
    }

}//end of setNpg;

void Book::setIsbn(ifstream fn){

    
    while(!'\0'){

        int isbn[50];

    for(int i = 0; i < sz; i++)

        fn>>isbn[i];
    }
}

void Book::setCateg(ifstream fn){


    while(!'\0'){

    for(int i = 0; i < sz; i++)

        fn>>categ[i];
    }
}

void Book::setDay(ifstream fn){
    
    while(!'\0'){

        int d[50];

    for(int i = 0; i < sz; i++)

        fn>>d[i];
    }
}

void Book::setMonth(ifstream fn){

    while(!'\0'){

        int m[50];

    for(int i = 0; i < sz; i++)

        fn>>m[i];
    }
}

void Book::setYear(ifstream fn){

    while(!'\0'){

        int y[50];

    for(int i = 0; i < sz; i++)

        fn>>y[i];
    }
}

void Book::setAid(ifstream fn){

    
    while(!'\0'){

        int aid[50];

    for(int i = 0; i < sz; i++)

        fn>>aid[i];
    }
}

void Book::setTitle(ifstream fn){


    while(!'\0'){

    for(int i = 0; i < sz; i++)

        fn>>title[i];
    }
    
};

int Book::getAid() const{return aid;}
string Book::getCateg() const{return categ;}
int Book::getDay() const{return d;}
int Book::getMonth() const{return m;}
int Book::getYear() const{return y;}
string Book::getTitle() const{return title;}
int Book::getIsbn()const{return isbn;}
int Book::getNpg()const{return npg;}

/*
Author::Author(int sz){

    if(sz == 0)
        data = NULL;
    
    else
        data = new Author[sz];
}//author class constructor

Author::~Author(){

    if(sz == 1)
        delete data;

    else if(sz > 1)

        delete [] data;
}//author class destructor
*/

void Author::setAid(ifstream fn2){

    while(!'\0'){

        int aid[50];

        for(int i = 0; i < sz; i++)

            fn2>>aid[i];
    }
}

void Author::setFname(ifstream fn2){


    while(!'\0'){

        for (int i = 0; i< sz; i++)

            fn2>>fname[i];
    }
}

void Author::setLname(ifstream fn2){

    
        while(!'\0'){

        for (int i = 0; i< sz; i++)

            fn2>>lname[i];
    }
}

int Author::getAid() const{return aid;}
string Author::getFname() const{return fname;}
string Author::getLname() const{return lname;}
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ

Pėrgjigju me kuotė Shkarko Mesazhin
Mesazh Re: Ushtrime Ne C++ 
 
#include <iostream>    // cin, cout, cerr, endl
#include <fstream>    // ifstream
#include <string>    // string

using namespace std;

// main always has an int return type.
int main() {

    ifstream nameStream;
    cout << "What is the name of the file? ";
    string fileName;
    cin >> fileName;
    // We can not pass a string object to the
    // method "open".
    // We have to pass a "C string".  
    // (C strings are just arrays of characters
    // with a NULL character at the end.)
    // The method "c_str()" returns a C string
    // version of a string object.
    nameStream.open(fileName.c_str());

    // We do not have to explicitly invoke the
    // "fail" method here, though we could if we
    // want.  When we test the stream object nameStream,
    // it returns false if the stream is broken and true otherwise.
    // Note that it is perfectly ok to write "nameStream.fail()" instead
    // of "!nameStream".
    if (!nameStream) {
        // Using the stream object cerr since this is an error message.
        cerr << "Couldn't open the names file.\n";
        return 1;
    }

    string name;

    // if nameStream is already broken before the read or breaks
    // during the read then the test for the while will fail.
    // What does "broken" mean?  That we failed to do something that
    // we tried to do with the stream.
    while ( nameStream >> name ) {
        cout << name << endl;
    }

    nameStream.close();

    // Note that the following line, "return 0;" is optional.
    // VC++6 used to give a warning
    // but .Net does a better job of conforming to the standard.
    return 0;
}
 




____________
Image
Image
Image
Offline Shiko profilin e anėtarit Dėrgo mesazh privat Vizito websitin e shkruesit Adresa e AIM Yahoo Messenger MSN Messenger Nr. i ICQ
Shfaq mesazhet nga:
Shuma e Votimeve:
Vlerėsim Mesatar Vlerėsim Minimal Vlerėsim Maksimal Numri Vlerėsimeve
0.00 0 0 0
Shiko info tė Detajuar
Zgjidh Vlerėsimin: 
Posto temė tė re Pėrgjigju temės  Faqja 1 e 2
Shko tek faqja 1, 2  Tjetėr

Pėrdorues duke shfletuar temėn: 0 anėtarė 0 tė fshehur 0 vizitorė
Anėtarėt e regjistruar Asnjė