Jumat, 01 Januari 2016

Tugas DDP "CLASS"



                                                                                 #include <iostream>
                                                                                 #include <conio.h>
                                                                                 Using namespace std;
                                                                                 Class luas{
                                                                                 Public:
                                                                                 Int sisi;
                                                                                 Int kel ()
                                                                                 {return (12*sisi);}
                                                                                 ;}

                                                                                 int main(int argc, char** argv) {
                                                                                 luas kub;
                                                                                 cout<<”Sisi kubus  =  ”; cin>>kub.sisi;
                                                                                 cout<<”Keliling kubus =  ”<<kub.kel();
                                                                                 return 0;
                                                                                 }
                                                                                

PENJELASAN :
Class(nama_class);
Mendeklarasikan variable yang mau di input kan.
Penggantian variable tanpa int. contoh : luas kub;
Untuk men outputkan : contoh : int kel() – cout<<”text”<<kub.kel();
=========================================================== 


PENJELASAN :
Seperti penjelasan nomer 1, tetapi private ini tidak bisa compiling (seperti dikunci dan seperti ada kesalahan dalam ngodingnya)
=======================================================================
 

                                                                             #include <iostream>
                                                                             #include <conio.h>
                                                                             Using namespace std;
                                                                             Class panjang{
                                                                             Private:
                                                                             Int p,l;
                                                                             Public:
                                                                             Int luas()
                                                                             {return (p*l);}
                                                                             Void hokya (int p1, int l1)
                                                                             {p=p1;  l=l1;}
                                                                             ;}
                                                                             Int main (int argc, char** argv){
                                                                             Panjang coy, cuy;
                                                                             Int I,j;
                                                                             Cout<<”Panjang = ”; cin>>I;
                                                                             Cout<<”Luas = ”; cin>>j;
                                                                             Coy.hokya(I,j);
                                                                             Cuy.hokya(15,j);
                                                                             Cout<<”\n Luas i =  ”<<coy.luas();
                                                                             Cout<<”\n Luas j = ”<<cuy.luas();
                                                                             Return 0;
                                                                             }
PENJELASAN:
Private menjadi public : ada tambahan dari void, yang di private fungsi awal aja, lalu di publickan dengan “void ” contoh : void bisa (int a1, int b1)
Penjelasan lainnya sama seperti penjelasan nomer 1.


Tidak ada komentar:

Posting Komentar