summary of c
TRANSCRIPT
Inisialisasi variable
Tipe Data
How to use typedef?
When does wrapping happen?
IF
STRUCTURE
POINTER
TIP
===============================================================Always think that the warning messages as error messages
===============================================================
A Class has following features:- The capability to control access- Constructor- Destructor- Data members (usually called as properties)- Member functions (usually called as method)- A Hidden, special pointer called this
18 April 2014
A Class has three levels of access, there are: public, private, protected
A structure doesn’t have three levels of access, only public access
Public access means can be accessed by outside
Private access means only can be accessed internal implementation of the class (inner workings)
Protected access means can’t be accessed from public view, means user of the class doesn’t need to know
Data abstraction is the hiding of internal implementations within the class from outside view
Protected level is a little harder to be explained
Object is an instance of a class
Constructor doesn’t have return value
A class can have more than one constructor, but only one destructorCODING EXERCISE:
class mobil{public:int warna;mobil();mobil(int warna);void showColor();void releaseShow();
private:void showNomorMesin();};
void mobil::mobil(){ warna=0;}
void mobil::mobil(int warna){ mobil::warna=warna;}
void mobil::showColor(){ printf("WARNA:"); if(warna==0) printf("hitam"); else printf("putih"); printf("\n");}
void mobil::showNomorMesin(){ printf("TESTS");}
void mobil::releaseShow(){ showNomorMesin();}
void main(){clrscr();printf("A CAR\n");
mobil mobil1;mobil1.showColor();
mobil mobil2(1);mobil2.showColor();mobil2.releaseShow();
getch();}
Constructor dijalankan sebelum objek dihancurkan, di dalam constructor bias diletakkan baris program yang menghapus memori yang digunakan ( variable – variable yang tidak dipakai)
Data member is variables which are used in a class. They have access levels like the class access levels.
Tidak semua C language menyediakan tipe data Bool, tergantung versinya juga
1 May 2014
Multiple Inheritance -> dapat melakukan semua method public yang dimiliki induknya
Membaca File menggunakan library fstream.h
#include <fstream.h> // include library ifstream in; //in sebagai input file stream in.open(“TEST.CPP”); //membuka file target if(!in)… //jika file tidak ditemukan
while(!in.eof()) {…} //lakukan instruksi jika bukan akhir dari file in.getline(buff,sizeof(buff)); // baca per line dan ditampung di dalam buff in.close() // menutup file