1#
Code
Ne kete teme do të keni mundesi qe të krijoni një program tuajin për c++ por vetem duke shkruajtur kode të cilat mund të kompilohen ne c++....
Se pari do të filloj me disa ushtrime të thjeshta për të pare se sa ne gjendje jane antaret e forumit..
1. një program i cili shfaq ne ekran kete:
::::::une jam agent0016:::::
//është programi me i thjeshte për c++
#include <iostream>
using namespace std;
int main(){
cout<<"une jam agent0016"<<endl;
return 0;
}
---------------------------------------------------------------------------------
// 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 për 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 */
----------------------------------------------------------------------------------
//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 është ne Fahrenheit, shtypni F; nese është 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 është " << res <<" grade celsius"<<endl;
if (letter == 'C' || letter == 'c')
{res=value*1.8+32;
cout <<"Temperatura ne Fahrenheit është " <<res<<"grade fahrenheit"<<endl;
}
else cout<<"Ju lutem jepni një shkronje të vlefshme."<<endl;
return 0;
}
#2
Code
// Llogaritja e numrit më të madh(MAX)
Kodi:
#include <iostream>
#include <conio.h>
void main()
{
float x, y;
cout << "Jepi dy numra të ndryshem: \n";
if( !(cin >> x && cin >> y))
{
cout << "Gabim!" << endl;
}
else
{
cout << "\n Numri me i madh është: "
<< (x > y ? x : y) << endl;
}
getch();
}
----------------------------------
#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
#3
Code
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);
}
}
#4
Code
#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 të besh greve urie kshu...?"<<endl;
if (time>1800 || time<=2200)
cout<<"Mos shih shumë 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 të kam thene mos rri zgjuar duke pare porno..."<<endl;
return 0;
}