You are on page 1of 32

# #include <iostream> using namespace std; inline int vleraENdermjetme(int a,int b,int c) { int rez; if((a>c&&a<b)||(a<c&&a>b)) rez=a; else

## if((b>a&&b<c)||(b<a&&b>c)) rez=b; else rez=c; return rez;

} inline int mbetjaEPjestimit(int x,int y) { return x%y; } int main12() { int a,b,c,x,y; cout<<"Te caktohen tri vlera per krahasim:"; cin>>a>>b>>c; cout<<"Vlera e ndermjetme prej vlerave " <<a<<", "<<b<<" dhe "<<c<<" eshte " <<vleraENdermjetme(a,b,c)<<".\n"; cout<<"Te caktohen numrat e plote per pjestim:"; cin>>x>>y; cout<<"Mbetja e pjestimit te numrave te plote " <<x<<" dhe "<<y <<" eshte :" <<mbetjaEPjestimit(x,y)<<".\n"; } return 0;

#include <iostream> using namespace std; #define funksioni(x) (x<0)?(3):(2*x+1) int main() { float f,x; cout<<"Te caktohet vlera per x:"; cin>>x; f=funksioni(x); cout<<"f="<<f<<endl; } return 0;

#include <iostream> using namespace std; #define pi 3.14 #define perimetri(rrezja) 2*pi*rrezja #define siperfaqeja(rrezja) pi*rrezja*rrezja int main11() { float r; cout<<"Te caktohet rrezja e rrethit:"; cin>>r; cout<<"Perimetri i rrethit me rreze " <<r<< " eshte "<<perimetri(r) <<", ndersa siperfaqeja e rrethit eshte " <<siperfaqeja(r)<<".\n"; } return 0;

#include <iostream> #include <math.h> using namespace std; #define pi 3.14 double vellimi(float l,float w,float h); double vellimi(float l,float r); double vellimi(float r); int mainMbi1() { float l,w,h,r; cout<<"Te caktohet gjatesia, gjeresia dhe" <<" lartesia e paralelopipedit :"; cin>>l>>w>>h; cout<<"Vellimi i paralelopipedit eshte :" <<vellimi(l,w,h)<<endl; cout<<"Te caktohet gjatesia dhe rrezja e " <<"cilindrit:"; cin>>l>>r; cout<<"Vellimi i cilindrit eshte :" <<vellimi(l,r)<<endl; cout<<"Te caktohet rrezja e " <<"sferes:"; cin>>r; cout<<"Vellimi i sferes eshte :" <<vellimi(r)<<endl; return 0; } double vellimi(float l,float w,float h) { return l*w*h; } double vellimi(float l,float r) { return pow(r,2)*pi*l; } double vellimi(float r) { return (4.0/3)*pi*pow(r,3); }

#include <iostream.h> #include <math.h> double shuma_prodhimi(int x,int n); double shuma_prodhimi(float x,int n); double fakt(int m); int mainMbi2() { int x,n; double f,z; cout<<"Te caktohen vlerat per x dhe n:"; cin>>x>>n; f=shuma_prodhimi(x,n); z=shuma_prodhimi((float)x,n); cout<<"f="<<f<<endl<<"z="<<z<<endl; return 0;

} double fakt(int m) { double f; int i; f=1; for(i=1;i<=m;i++) f=f*i; return f; } double shuma_prodhimi(int x,int n) { double f,s; int i; s=0; i=2; while(i<=n+1) { if(i!=3) { s=s+(1+fakt(2*i)); } i++; } f=sqrt(x+s); return f; } double shuma_prodhimi(float x,int n) { double z,p; int i; p=1; i=2; do { p=p*(3+fakt(i+2)); i++; } while (i<=n+1); z=x+p; return z; }

#include <iostream> using namespace std; enum stina { pranvera, vera, vjeshta, dimri }; int mainEnum1() { stina s; s=dimri; if(s==pranvera) cout<<"Moti eshte else if(s==vera) cout<<"Moti eshte else if(s==vjeshta) cout<<"Moti eshte else cout<<"Moti eshte return 0; }

## i fresket.\n"; i nxehte.\n"; me shi.\n"; i ftohete.\n";

#include <iostream.h> enum dita { E_hene, E_Marte, E_Merkure, E_Enjete, E_Premte, E_Shtune, E_Diele }; enum ngjyra { e_bardhe, e_verdhe, e_gjelberte, e_kuqe, e_kalter, e_kafte, e_zeze }; int mainEnum2() { dita d; d=E_Premte; if(d==E_Shtune||d==E_Diele) cout<<"Dite pushuese.\n"; else cout<<"Dite punuese.\n"; return 0; }

#include <iostream.h> enum lenda { Matematika_2=6, Fizika_2, BET, Materialet, Algoritmet }; int mainEnum3() { lenda l; for(l=Matematika_2;l<=Algoritmet; l=static_cast<lenda>(l+1)) cout<<"Numri perkates i lendes eshte :" <<l<<endl; } return 0;

#include <iostream.h> enum muaji { janar, shkurt, mars, prill, maj, qershor, korrik, gusht, shtator, tetor, nentor, dhjetor }; int main() { const int n=12,NDM[n]={31,28,31,30,31, 30,31,31,30,31,30,31}; float Q[n],qv,qm,qbd; muaji m; cout<<"Te caktohet qiraja baze ditore:"; cin>>qbd; qv=0; for(m=janar;m<=dhjetor; m=static_cast<muaji>(m+1)) { if(m==qershor||m==korrik ||m==gusht) { Q[m]=qbd*NDM[m]*1.2; } else if(m==dhjetor||m==janar ||m==shkurt) { Q[m]=qbd*NDM[m]*0.9; } else Q[m]=qbd*NDM[m]; qv=qv+Q[m]; } qm=qv/n; for(m=janar;m<=dhjetor; m=static_cast<muaji>(m+1)) { cout<<"Qeraja per mujin " <<m+1<<" eshte " <<Q[m]<<" euro.\n"; } cout<<"Qeraja per tere vitin eshte " <<qv<<" euro.\n"; cout<<"Qeraja mesatare per nje muaj " <<"eshte "<<qm<<" euro.\n"; return 0; }

#include <iostream> using namespace std; enum opcioni { shume=1, prodhim, mesatare }; double funksioni(int vektori[],int n, opcioni o); int mainEnum5() { const int n=5; int A[n]={3,4,2,1,6}; opcioni o; int z; char p; B: cout<<"Caktoni llojin e operacionit.\n" <<"Shtypni 1, per shume.\n" <<"Shtypni 2, per prodhim.\n" <<"Shtypni 3, per mesatare.\n"; cin>>z; o=static_cast<opcioni>(z); cout<<"Rezultati eshte :" <<funksioni(A,n,o) <<endl; cout<<"A te perseritet programi(p/j)?"; cin>>p; if(p=='p'||p=='P') goto B; else cout<<"Perfundoj ekzekutimi" <<" i programit.\n"; return 0; } double funksioni(int vektori[],int n, opcioni o) { double rez; int i; if(o==shume||o==mesatare) { rez=0; for(i=0;i<n;i++) rez=rez+vektori[i]; if(o==mesatare) rez=rez/n; } else { rez=1; i=0; do { rez=rez*vektori[i]; i++;} while(i<n); } return rez;}

#include <iostream.h> enum opcioni { barabart=1, identik, perbashkte }; bool rezultati(int A[],int B[],int n, int m,opcioni o); int main() { const int n=5,m=6; int A[n], B[m]; opcioni o; int z,i; char p; B: cout<<"Caktoni llojin e operacionit.\n" <<"Shtypni 1, per barabart.\n" <<"Shtypni 2, per identik.\n" <<"Shtypni 3, per perbashket.\n"; cin>>z; o=static_cast<opcioni>(z); cout<<"Te caktohen anetaret e vektorit A:\n"; for(i=0;i<n;i++) { cout<<"A["<<i+1<<"] :"; cin>>A[i]; } cout<<"Te caktohen anetaret e vektorit B:\n"; for(i=0;i<m;i++) { cout<<"B["<<i+1<<"] :"; cin>>B[i]; } cout<<"Rezultati eshte :" <<rezultati(A,B,n,m,o) <<endl; cout<<"A te perseritet programi(p/j)?"; cin>>p; if(p=='p'||p=='P') goto B; else cout<<"Perfundoj ekzekutimi" <<" i programit.\n"; return 0; } bool rezultati(int A[],int B[],int n, int m,opcioni o) { bool rez; int i,j; if(o==barabart||o==identik) { if(n==m) {

} else } else {

} return rez;

## rez=false; for(i=0;i<n;i++) { for(j=0;j<m;j++) { if(A[i]==B[j]) { rez=true; break; } } if(rez==true) break; }

#include <iostream> #include <string> using namespace std; struct punetori {A int n; string e,m; char a[30]; }; int mainSt1() { punetori p; cout<<"Te caktohen te dhenat" <<" e punetorit\n"; cout<<"Numri:"; cin>>p.n; cout<<"Emri:"; cin>>p.e; cout<<"Mbiemri:"; cin>>p.m; cin.ignore(); cout<<"Adresa:"; cin.getline(p.a,30); cout<<"Te dhenat e punetorit jane\n"; cout<<"Numri:"<<p.n<<endl <<"Emri:"<<p.e<<endl <<"Mbiemri:"<<p.m<<endl <<"Adresa:"<<p.a<<endl; return 0;

#include <iostream> using namespace std; struct funksioni { int a,b; double f; }; int mainSt2() { funksioni fu; cout<<"Te caktohen vlerat per a dhe b:"; cin>>fu.a>>fu.b; int i; fu.f=1; for(i=1;i<=2*fu.a+2*fu.b+4;i++) fu.f=fu.f*i; cout<<"F=" <<fu.f <<endl; return 0; }

#include <iostream> using namespace std; struct llogaritja { float x; int n; double fakt(int m); double shuma(int a,int b,bool c); double y() { return 2*shuma(n,2,false); } double z() { return 2*x-3*shuma(n+1,1,true); } }; int mainSt3() { llogaritja ll; cout<<"Te caktohen vlerat per x dhe n:"; cin>>ll.x>>ll.n; cout<<"y="<<ll.y()<<endl <<"z="<<ll.z()<<endl; return 0; } double llogaritja::fakt(int m) { double f; int i; f=1; for(i=1;i<=m;i++) f=f*i; return f; } double llogaritja::shuma(int a,int b,bool c) { double s=0; int i; for(i=1;i<=a;i++) { if(c) { if(i!=3) s=s+(b*x+2*i-1); } else { s=s+(b*x+fakt(i+1)); } } return s; }

#include <iostream> using namespace std; struct punetor { int ID; char e[50]; float no; float pj; float pagaJavore(int pagaPerOre) { return no*pagaPerOre; } }; int mainSt4() { const int m=5; punetor p[m]={{1,"Fitim Aliu",45}, {2,"Rifat Blaku",35}, {3,"Ylfete Jashari",38}, {4,"Njomza Vokshi",60}, {5,"Brahim Istogu",28}}; int i; for(i=0;i<m;i++) { p[i].pj=p[i].pagaJavore(7); } int Pmax,Imax; Pmax=p[0].pj; Imax=0; for(i=1;i<m;i++) { if(p[i].pj>Pmax) { Pmax=p[i].pj; Imax=i; } } cout<<"Punetori qe ka" <<" pagen maksimale " <<"eshte "<<p[Imax].e <<" me vlere prej " <<p[Imax].pj<<" euro.\n"<<endl; return 0; }

#include <iostream> using namespace std; struct malli { char emertimi[30]; double cmimi; char njesia[6]; float sasia; }; struct fatura { int numri; char valuta; double vlera_totale; malli mallrat[5]; }; int mainSt5() { fatura f={100,'e'}; malli m[5]={{"Qumeshte i lehte",0.7,"liter",3}, {"Veze",0.1,"cope",30}, {"Lenge portokalli",1,"liter",5}, {"Banane",1,"kg",2}, {"Smoka",0.15,"cope",4}}; int i; for(i=0;i<5;i++) f.mallrat[i]=m[i]; f.vlera_totale=0; for(i=0;i<5;i++) { f.vlera_totale=f.vlera_totale+ f.mallrat[i].cmimi* f.mallrat[i].sasia; } cout<<"Vlera totale e fatures eshte:" <<f.vlera_totale<<endl; return 0; }

#include <iostream> using namespace std; enum rangu { i_dalluar=1, mesatar=2, i_dobet=3 }; struct studenti { char e[51]; float nm; int np; int nv; rangu r; }; int main() { studenti s[5]= {{"Njomza Hadri",8.23,24,2}, {"Fitim Guri",7.35,29,3}, {"Teuta Kodra",9.47,20,3}, {"Ymer Hoxha", 9.10, 32,3}, {"Yllka Gashi",9.5,30,4}}; int i; for(i=0;i<5;i++) { if(s[i].nm>9&& s[i].np>=30&& s[i].nv<=3) s[i].r=i_dalluar; else if(s[i].nm<7&& s[i].nv>5) s[i].r=i_dobet; else s[i].r=mesatar; } for(i=0;i<5;i++) cout<<"Studenti/ja e quajtur " <<s[i].e <<" ka rangun "<<s[i].r <<".\n"; return 0;

#include <iostream> #include <string> using namespace std; class njeriu { private: int mosha; public: int nr_pers; string emri; string adresa; }; int mainK1() { njeriu n; n.nr_pers=100; n.emri="Njomza Halili"; n.adresa="Rr. Skenderbeu, p.n., Prishtine"; cout<<"Numri personal:"<<n.nr_pers<<endl <<"Emri:"<<n.emri<<endl <<"Adresa:"<<n.adresa<<endl; return 0;

#include <iostream> using namespace std; class fatura { private: int numri; double vlera; public: void vendosNumri(int nr) { numri=nr; } int merrNumri() { return numri; } void vendosVlera(double v) { vlera=v; } double merrVlera() { return vlera; } }; int mainK2() { fatura f; f.vendosNumri(1000); f.vendosVlera(234.56); cout<<"Numri eshte:" <<f.merrNumri()<<endl <<"Vlera eshte:" <<f.merrVlera()<<endl; return 0;

#include <iostream> using namespace std; class malli { private: double cmimi; int sasia; public: char emertimi[31]; malli() { cout<<"Te caktohet emertimi i mallit:"; cin.getline(emertimi,30); cout<<"Caktoje edhe cmimin dhe sasine:"; cin>>cmimi>>sasia; } double merrCmimi() { return cmimi; } int merrSasia() { return sasia; } }; int mainK3() { malli m; cout<<"Emertim i mallit:" <<m.emertimi<<endl <<"Cmimi i mllit:" <<m.merrCmimi()<<endl <<"Sasia e mallit" <<m.merrSasia()<<endl; } return 0;

#include <iostream> using namespace std; class prodhimi { private: int n; double x; double pr(int a, int b) { double p=1; int i; for(i=a;i<=b;i++) p=p*(x*(i+1)); return p; } double p1(); double p2(); public: prodhimi() { cout<<"Cakto vlerat per x dhe n:"; cin>>x>>n; } void shtypVlerat() { cout<<"p1="<<p1()<<endl <<"p2="<<p2()<<endl; } }; int main() { prodhimi p; p.shtypVlerat(); return 0; } double prodhimi::p1() { return pr(1,n); } double prodhimi::p2() { return pr(2,n-1); }

#include <iostream> using namespace std; class funksioni { private: int x,n; public: double shuma(int a, int b, int c, int d); int merrX(); int merrN(); funksioni(); double y,z; }; int mainK5() { const int g=2,h=3; funksioni f; f.y=f.merrX()+3*f.shuma(1,f.merrN()+2,2,-5); f.z=f.merrX()/3.0+2*f.shuma(1,f.merrN(),1,g)3*f.shuma(2,f.merrN()+1,4,-h); cout<<"y="<<f.y<<endl <<"z="<<f.z<<endl; return 0; } double funksioni::shuma(int a, int b, int c, int d) { double s=0; int i; for(i=a;i<=b;i++) s=s+(c*i+d); return s; } int funksioni::merrX() { return x; } int funksioni::merrN() { return n; } funksioni::funksioni() { cout<<"Vlera per x dhe n:"; cin>>x>>n; }

#include <iostream> using namespace std; class llogaritja { private: int n; double fakt(int m); double shuma(int a,int b, int c); double y(float x); public: llogaritja(); void shtypVlerat(float x); }; int mainK6() { const float x=3.14; llogaritja ll; ll.shtypVlerat(x); return 0; } double llogaritja::fakt(int m) { double f=1; int i; for(i=1;i<=m;i++) f=f*i; return f; } double llogaritja::shuma(int a,int b, int c) { double s=0; int i=1; do { s=s+(b*i+c); i++; }while (i<=a); return s; } llogaritja::llogaritja() { cout<<"Te caktohet vlera per n:"; cin>>n; } double llogaritja::y(float x) { double rez; rez=x+fakt(n)/2-3*shuma(n+1,4,0)+ fakt(n+2)+2*shuma(n-1,2,1); return rez; } void llogaritja::shtypVlerat(float x) { cout<<"y="<<y(x)<<endl; }

#include <iostream> using namespace std; class personi { public: char emri[31],adresa[51]; int mosha; }; class studenti:public personi { public: char indeksi [9]; char fakulteti[11]; }; int mainK7() { studenti s; cout<<"Te dhenat e studentit:\n"; cout<<"Emri:"; cin.getline(s.emri,30); cout<<"Adresa:"; cin.getline(s.adresa,50); cout<<"Mosha:"; cin>>s.mosha; cout<<"Indeksi:"; cin.ignore(); cin.getline(s.indeksi,9); cout<<"Fakulteti:"; cin.getline(s.fakulteti,10); return 0; }

#include <iostream> using namespace std; int mainP1() { int a,*pa=0; double b,*pb=NULL; bool c,*pc; cout<<"Te caktohen vlerat per a, b" <<" dhe c:"; cin>>a>>b>>c; pa=&a; pb=&b; pc=&c; cout<<"Te caktohen vlerat per a, b" <<" dhe c:"; cin>>*pa>>*pb>>*pc; cout<<"Vlera e variables a eshte:" <<a<<endl <<"Adresa e variables a eshte:" <<pa<<endl; cout<<"Vlera e variables b eshte:" <<b<<endl <<"Adresa e variables b eshte:" <<pb<<endl; cout<<"Vlera e variables c eshte:" <<c<<endl <<"Adresa e variables c eshte:" <<pc<<endl;

return 0;

#include <iostream> using namespace std; int mainP2() { double y,*py,s,*ps,f, *pf; int i,*pi,j,*pj,n,*pn,x,*px; py=&y;ps=&s;pf=&f;pi=&i;pj=&j; pn=&n;px=&x; *pn=1;*px=1; *ps=0; for(*pi=1;*pi<=*pn;(*pi)++) { *pf=1; for(*pj=1;*pj<=(*pi)+1;(*pj)++) *pf=(*pf)*(*pj); *ps=*ps+(*pf+2*(*px)); } *py=2*(*ps); cout<<"y="<<*py<<endl; return 0; }

#include <iostream> using namespace std; void llogaritja(int a, int b, int c, int *pmax,int *pmin, float *pmes); int main() { int x=3,y=2,z=6; int ma,*pma,mi,*pmi; float me,*pme; pma=&ma; pmi=&mi; pme=&me; llogaritja(x,y,z,pma,pmi,pme); cout<<"Vlera me e madhe eshte:" <<*pma<<endl <<"Vlera me e vogel eshte:" <<mi<<endl <<"Vlera mesatare eshte:" <<me<<endl; return 0; } void llogaritja(int a, int b, int c, int *pmax,int *pmin, float *pmes) { if(a>b&&a>c) *pmax=a; else if(b>a&&b>c) *pmax=b; else *pmax=c; if(a<b&&a<c) *pmin=a; else if(b<a&&b<c) *pmin=b; else *pmin=c; *pmes=(a+b+c)/3.0; }

#include <iostream> using namespace std; const int n=4; void shumezimi(int A[],int B[],int m, int Y[]); float VM(int C[][n],int m); int mainP4() { const int m=3; int A[m]={2,4,6},B[m]={3,5,7}, Y[m],C[m][n]={{1,1,1,1}, {2,2,2,2}, {3,3,3,3}},i; shumezimi(A,B,m,Y); cout<<"Vektori Y eshte:"; for(i=0;i<m;i++) cout<<Y[i]<<" "; cout<<endl; cout<<"Mesatarja e anetareve te" <<" matrices eshte :" <<VM(C,m)<<endl; return 0; } void shumezimi(int A[],int B[],int m, int Y[]) { int *pa,*pb,i; pa=&A[0]; pb=B;//ose &B[0] for(i=0;i<m;i++) Y[i]=(*(pa+i))*(*(pb+i)); } float VM(int C[][n],int m) { double s,*ps; int i,j; ps=&s; *ps=0; for(i=0;i<m;i++) for(j=0;j<n;j++) *ps=*ps+C[i][j]; return *ps/(m*n); }

#include <iostream> using namespace std; int mainR1() { int x; double y; bool z; cout<<"Te cakohen x, y dhe z:"; cin>>x>>y>>z; int &rx=x; double &ry=y; bool &rz=z; cout<<"Te cakohen x, y dhe z:"; cin>>rx>>ry>>rz; cout<<"Vlera per x dhe rx:" <<x<<", "<<rx<<endl; cout<<"Vlera per y dhe ry:" <<y<<", "<<ry<<endl; cout<<"Vlera per z dhe rz:" <<z<<", "<<rz<<endl; return 0; }

#include <iostream> using namespace std; struct ekipi { char emri; short piket,kartonat; float posedimi; }; void llogaritja(ekipi Ekipet[], int m, char &kfp, char &kvp, char &kavpt, float &mes); int main() { const int m=5; ekipi E[m]={{'A',45,24,0.48}, {'B',49,22,0.51}, {'C',46,30,0.52}, {'D',40,25,0.43}, {'E',44,29,0.50}}; char kfp,kvp,kavpt; float mes; llogaritja(E,m,kfp,kvp,kavpt,mes); cout<<"Klubi me fair play :" <<kfp<<endl <<"Klubi ne vendin e pare:" <<kvp<<endl <<"Klubi me posedimi te vogel" <<" te topit:" <<kavpt<<endl <<"Mesatarja e kartonave te " <<" verdhe eshte:" <<mes<<endl; return 0; } void llogaritja(ekipi Ekipet[], int m, char &kfp, char &kvp, char &kavpt, float &mes) { int i,Imin,Kmin; Kmin=Ekipet[0].kartonat; Imin=0; for(i=1;i<m;i++) if(Ekipet[i].kartonat<Kmin) { Kmin=Ekipet[i].kartonat; Imin=i; } kfp=Ekipet[Imin].emri; int Imax,Pmax; Pmax=Ekipet[0].piket; Imax=0; for(i=1;i<m;i++) if(Ekipet[i].piket>Pmax)

} kvp=Ekipet[Imax].emri; float Pmin; Pmin=Ekipet[0].posedimi; Imin=0; for(i=0;i<m;i++) if(Ekipet[i].posedimi <Pmin) { Pmin=Ekipet[i].posedimi; Imin=i; } kavpt=Ekipet[Imin].emri; double s=0; for(i=0;i<m;i++) s=s+Ekipet[i].kartonat; mes=s/m;

Pmax=Ekipet[i].piket; Imax=i;