summary of c

16
Inisialisasi variable Tipe Data How to use typedef?

Upload: guitararchieves

Post on 02-May-2017

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Summary of C

Inisialisasi variable

Tipe Data

How to use typedef?

Page 2: Summary of C

When does wrapping happen?

Page 3: Summary of C
Page 4: Summary of C
Page 5: Summary of C
Page 6: Summary of C

IF

Page 7: Summary of C

STRUCTURE

Page 8: Summary of C
Page 9: Summary of C

POINTER

Page 10: Summary of C

TIP

===============================================================Always think that the warning messages as error messages

Page 11: Summary of C

===============================================================

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

Page 12: Summary of C

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();}

Page 13: Summary of C

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

Page 14: Summary of C

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

Page 15: Summary of C

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