1 / 12

Referencat

Referencat. Deklarimi dhe inicializimi. a=100. //ref1… int main(){ int a=100; int &amp;r=a; cout&lt;&lt;“<br> a=&quot;&lt;&lt; a ; cout&lt;&lt;“<br> r=&quot;&lt;&lt; r ; cout&lt;&lt;“<br> &amp;a=&quot;&lt;&lt; &amp;a ; cout&lt;&lt;“<br> &amp;r=&quot;&lt;&lt; &amp;r ; return 0; }. int &amp;r=a. Dalje a=100 r=100 &amp;a=0x22FF24 &amp;r=0x22FF24. Referencat.

clarissa
Download Presentation

Referencat

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Referencat • Deklarimi dhe inicializimi a=100 //ref1… int main(){ int a=100; int &r=a; cout<<“\n a="<<a; cout<<“\n r="<<r; cout<<“\n &a="<<&a; cout<<“\n &r="<<&r; return 0; } int &r=a Dalje a=100 r=100 &a=0x22FF24 &r=0x22FF24

  2. Referencat • Ndryshimi i vlerave //ref2… int main(){ int a=100; int &r=a; cout<<"Vlera fillestare (a=100)"; cout<<"\n a="<<a; cout<<"\n r="<<r; a=200; cout<<"\nNdryshim 1 (a=200)"; cout<<"\n a="<<a; cout<<"\n r="<<r; r=300; cout<<"\nNdryshim 2 (r=300)"; cout<<"\n a="<<a; cout<<"\n r="<<r; return 0; } Dalje Vlera fillestare (a=100) a=100 r=100 Ndryshim 1 (a=200) a=200 r=200 Ndryshim 2 (r=300) a=300 r=300

  3. Referencat • Deklarimi i disa referencave të një variable //ref3... int main(){ int a=100; int &r1=a; int &r2=a; cout<<"Vlera fillestare (a=100)"; cout<<"\n a="<<a; cout<<"\n r1="<<r1; cout<<"\n r1="<<r2; r2=200; cout<<"\nNdryshimi (r2=200)"; cout<<"\n a="<<a; cout<<"\n r1="<<r1; cout<<"\n r2="<<r2; return 0; } Dalje Vlera fillestare (a=100) a=100 r1=100 r1=100 Ndryshim 1 (r2=200) a=200 r1=200 r2=200

  4. Referencat • Referencat në funksione Pa referenca //funkPa... double siperfaqe(double x,double y); int main(){ double a,b,S; cout<<"Brinja a:"; cin>>a; cout<<"Brinja b:"; cin>>b; S=siperfaqe(a,b); cout<<"Siperfaqja S="<<S<<endl; return 0; } double siperfaqe(double x,double y){ return x*y; } Dalje Brinja a:6 Brinja b:5 Siperfaqja S=30

  5. Referencat • Referencat në funksione Me referenca //funkPb… double siperfaqe(double &x,double &y); int main(){ double a,b,S; cout<<"Brinja a:"; cin>>a; cout<<"Brinja b:"; cin>>b; S=siperfaqe(a,b); cout<<"Siperfaqja S="<<S<<endl; return 0; } double siperfaqe(double&x,double &y){ return x*y; } Dalje Brinjet a:6 b:5 Siperfaqja S=30

  6. Referencat • Përdorimi i identifikatorëve të njëjtë Me referenca //funkPc… double siperfaqe(double &a,double &b); int main(){ double a,b,S; cout<<"Brinja a:"; cin>>a; cout<<"Brinja b:"; cin>>b; S=siperfaqe(a,b); cout<<"Siperfaqja S="<<S<<endl; return 0; } double siperfaqe(double &a,double &b){ return a*b; } Dalje Brinjet a:6 b:5 Siperfaqja S=30

  7. Referencat • Referencat për rezultatet //funkPd… void siperfaqe(double &x,double &y,double &z); int main(){ double a,b,S; cout<<"Brinja a:"; cin>>a; cout<<"Brinja b:"; cin>>b; siperfaqe(a,b,S); cout<<"Siperfaqja S="<<S<<endl; return 0; } void siperfaqe(double&x,double &y,double &z){ z=x*y; return; } Dalje Brinjet a:6 b:5 Siperfaqja S=30

  8. Referencat • Përcjellja e vlerave të variablave #include <iostream> using namespace std; void swap(int x,int y); int main(){ int a,b; a=3; b=6; cout<<“Para funksionit\n" <<"a="<<a<<" b="<<b<<endl; swap(a,b); cout<<“Pas funksionit\n" <<"a="<<a<<" b="<<b<<endl; return 0; } void swap(int x,int y){ int t; t=x; x=y; y=t; } Dalje Para funksionit a=3 b=6 Pas funksionit a=6 b=3

  9. Referencat • Referenca të vektorëve //refV… int main(){ const int n=5; int i; double a[n]={7,3,9,2,4}; double (&b)[n]=a; cout<<"Vektori a\n"; for(i=0; i<n; i++) cout<<setw(3)<<a[i]; cout<<"\nVektori b\n"; for(i=0; i<n; i++) cout<<setw(3)<<b[i]; return 0; } Dalje Vektori a 7 3 9 2 4 Vektori b 7 3 9 2 4

  10. Referencat • Referenca të matricave //refM… int main(){ const int m=4, n=5; int i,j; double A[m][n]={{-4,6,9,2,1}, {6,-3,8,5,9}, {-1,7,3,8,5}, {4,3,2,-7,2}}; double (&B)[m][n]=A; cout<<"Matrica A\n"; for(i=0; i<m; i++){ for(j=0; j<n; j++) cout<<setw(3)<<A[i][j]; cout<<endl; } cout<<"\nMatrica B\n"; for(i=0; i<m; i++){ for(j=0; j<n; j++) cout<<setw(3)<<B[i][j]; cout<<endl; } return 0; } Dalje Matrica A -4 6 9 2 1 6 -3 8 5 9 -1 7 3 8 5 4 3 2 -7 2 Matrica B -4 6 9 2 1 6 -3 8 5 9 -1 7 3 8 5 4 3 2 -7 2

  11. Referencat • Përdorimi i referencave brenda klasave void kater::lexo(){ cout<<"Vlerat e lexuara\n"; cout<<"Brinja a:"; cin>>a; cout<<"Brinja b:"; cin>>b; } void kater::llogarit(){ s=a*b; p=2*(a+b); } void kater::merri(double &x,double &y){ x=s; y=p; } //refC… class kater{ private: double a,b,s,p; public: void lexo(); void llogarit(); void merri(double &x,double &y); }; int main(){ kater alfa; double S,P; alfa.lexo(); alfa.llogarit(); alfa.merri(S,P); cout<<"Vlerat e llogaritura\n" <<"S="<<S<<endl<<"P="<<P<<endl; return 0; } Dalje Vlerat e lexuara Brinja a:5 Brinja b:4 Vlerat e llogaritura S=20 P=18

  12. Referencat • Referenca të objekteve //refO class Klasa1{ public: int a; float b; void shtypja(); }; int main(){ Klasa1 k1; Klasa1 &k2=k1; cout<<"Leximi i vlerave\n"; cout<<"a:"; cin>>k1.a; cout<<"b:"; cin>>k1.b; cout<<"\nObjekti k1\n"; k1.shtypja(); cout<<"\nObjekti k2\n"; k2.shtypja(); return 0; } void Klasa1::shtypja(){ cout<<"a="<<a<<endl <<"b="<<b<<endl; } Dalje Leximi i vlerave a:9 b:5 Objekti k1 a=9 b=5 Objekti k2 a=9 b=5

More Related