Skip to main content

Dasar - dasar C++

<::> Setiap program C++ mempunyai bentuk umum seperti di bawah, yaitu:
# prepocessor directive
void main()
{
// Batang Tubuh Program Utama
}


1. Include
Adalah salah satu pengarah prepocessor directive yang tersedia pada C++. Preprocessor selalu dijalankan terlebih dahulu pada saat proses kompilasi terjadi. Bentuk umumnya :
# include

tidak diakhiri dengan tanda semicolon, karena bentuk tersebut bukanlah suatu bentuk pernyataan, tetapi merupakan prepocessor directive. Baris tersebut menginstrusikan kepada kompiler yang menyisipkan file lain dalam hal ini file yang berakhiran .h (file header) yaitu file yang berisi sebagai deklarasi contohnya:

alloc.h Declares memory-management functions (allocation, deallocation, and so on).
assert.h ANSI C Defines the assert debugging macro.
bcd.h C++ Declares the C++ class bcd and the overloaded operators for bcd and bcd math functions.
bios.h Declares various functions used in calling IBM-PC ROM BIOS routines.
bwcc.h Defines the Borland Windows Custom Control interface.
checks.h C++ Defines the class diagnostic macros.
complex.h C++ Declares the C++ complex math functions.

conio.h Declares various functions used in calling the operating system console I/O routines.
constrea.h C++ Defines the conbuf and constream classes.
cstring.h C++ Defines the string classes.
ctype.h ANSI C Contains information used by the character classification and character conversion macros (such as isalpha and toascii).
date.h C++ Defines the date class.
_defs.h Defines the calling conventions for different application types and memory models.
dir.h Contains structures, macros, and functions for working with directories and path names.

direct.h Defines structures, macros, and functions for dealing with directories and path names.
dirent.h Declares functions and structures for POSIX directory operations.
dos.h Defines various constants and gives declarations needed for DOS and 8086-specific
calls.
errno.h ANSI C Defines constant mnemonics for the error codes.
except.h C++ Declares the exception-handling classes and functions.
excpt.h Declares C structured exception support.
fcntl.h Defines symbolic constants used in connection with the library routine open.
file.h C++ Defines the file class.
float.h ANSI C Contains parameters for floating-point routines.

fstream.h C++ Declares the C++ stream classes that support file input and output.
generic.h C++ Contains macros for generic class declarations.
io.h Contains structures and declarations for low-level input/output routines.
iomanip.h C++ Declares the C++ streams I/O manipulators and contains templates for creating parameterized manipulators.
iostream.h C++ Declares the basic C++ streams (I/O) routines.
limits.h ANSI C Contains environmental parameters, information about compile-time limitations, and ranges of integral quantities.
locale.h ANSI C Declares functions that provide country- and language-specific information.

malloc.h Declares memory-management functions and variables.
math.h ANSI C Declares prototypes for the math functions and math error handlers.
mem.h Declares the memory-manipulation functions. (Many of these are also defined in string.h.)
memory.h Contains memory-manipulation functions.
new.h C++ Access to _new_handler, and set_new_handler.
_nfile.h Defines the maximum number of open files.
_null.h Defines the value of NULL.
process.h Contains structures and declarations for the spawn... and exec... functions.
search.h Declares functions for searching and sorting.

setjmp.h ANSI C Declares the functions longjmp and setjmp and defines a type jmp_buf that these functions use.
share.h Defines parameters used in functions that make use of file-sharing.
signal.h ANSI C Defines constants and declarations for use by the signal and raise functions.
stdarg.h ANSI C Defines macros used for reading the argument list in functions declared to accept a variable number of arguments (such as vprintf, vscanf, and so on).
stddef.h ANSI C Defines several common data types and macros.
stdio.h ANSI C Defines types and macros needed for the standard I/O package defined in Kernighan and Ritchie and extended under UNIX System V. Defines the standard I/O predefined streams stdin, stdout, stdprn, and stderr and declares stream-level I/O routines.
stdiostr.h C++ Declares the C++ (version 2.0) stream classes for use with stdio FILE structures. You should use iostream.h for new code.

stdlib.h ANSI C Declares several commonly used routines such as conversion routines and search/sort
routines.
string.h ANSI C Declares several string-manipulation and memory-manipulation routines.
strstrea.h C++ Declares the C++ stream classes for use with byte arrays in memory.
sys\locking.h Contains definitions for mode parameter of locking function.
sys\stat.h Defines symbolic constants used for opening and creating files.
sys\timeb.h Declares the function ftime and the structure timeb that ftime returns.
sys\types.h Declares the type time_t used with time functions.
thread.h C++ Defines the thread classes.

time.h ANSI C Defines a structure filled in by the time-conversion routines asctime, localtime, and gmtime, and a type used by the routines ctime, difftime, gmtime, localtime, and stime. It also provides prototypes for these routines.
typeinfo.h C++ Declares the run-time type information classes.
utime.h Declares the utime function and the utimbuf struct that it returns.
values.h Defines important constants, including machine dependencies; provided for UNIX System V compatibility.
varargs.h Definitions for accessing parameters in functions that accept a variable number of
arguments. Provided for UNIX compatibility; you should use stdarg.h for new code.


2. Fungsi main ()
Fungsi ini menjadi awal dan akhir eksekusi program C++. main adalah nama
judul fungsi. Melihat bentuk seperti itu dapat kita ambil kesimpulan bahwa batang tubuh
program utama berada didalam fungsi main( ). Berarti dalam setiap pembuatan program
utama, maka dapat dipastikan seorang pemrogram menggunakan minimal sebuah fungsi.
Pembahasan lebih lanjut mengenai fungsi akan diterangkan kemudian. Yang sekarang
coba ditekankan adalah kita menuliskan program utama kita didalam sebuah fungsi
main().

3. Komentar
Komentar tidak pernah dicompile oleh compiler. Dalam C++ terdapat 2 jenis
komentar, yaitu:
Jenis 1 : /* Komentar anda diletakkan di dalam ini
Bisa mengapit lebih dari satu baris */
Jenis 2 : // Komentar anda diletakkan disini ( hanya bisa perbaris )

4.Tanda Semicolon
Tanda semicolon “ ; ” digunakan untuk mengakhiri sebuah pernyataan. Setiap
pernyataan harus diakhiri dengan sebuah tanda semicolon.

5. Mengenal cout(dibaca : C out)
Pernyataan cout merupakan sebuah objek di dalam C++, yang digunakan untuk
mengarahkan data ke dalam standar output (cetak pada layar)

#include
void main()
{
cout<<"hello world"; //kalimat ini akan tercetak di layar
}

Tanda “ << “ merupakan sebuah operator yang disebut operator “penyisipan/peletakan”

Comments

Popular posts from this blog

A history of Ir. Soekarno

Sukarno This is an Indonesian name; it does not have a family name  Ir. Sukarno 1st President of Indonesia In office 18 August 1945 – 12 March 1967 Prime Minister Sutan Sjahrir Amir Sjarifuddin Muhammad Hatta Abdul Halim Muhammad Natsir Soekiman Wirjosandjojo Wilopo Ali Sastroamidjojo Burhanuddin Harahap Djuanda Kartawidjaja Vice President Mohammad Hatta Succeeded by Suharto Born 6 June 1901 Blitar, Dutch East Indies Died 21 June 1970 (aged 69) Jakarta, Indonesia Political party None Spouse Oetari Inggit Garnasih Fatmawati Hartini Kartini Manoppo Ratna Sari Dewi Soekarno Haryati Yurike Sanger Heldy Djafar Religion Islam Signature  Sukarno, born Kusno Sosrodihardjo (6 June 1901 - 21 June 1970) was the first President of Indonesia. He helped the country win its independence from the Netherlands and was President from 1945 to 1967, presiding with mixed success over the country's turbulent transition to independence. Sukarno was forced out of power by one of his generals, Suharto, who

pemrograman C++

okelah.. sekarang ane iseng mw biki tutor sederhana.. soalnya ini ditanyain pas ane sidang kompre..wkwkwk asik juga sih..dah lama di lupain C++nya.. untung masih rada inget ama perintah perintahnya...so jangan loading terlalu lama.langsung aja ane kasih script sederhana C++ cuman buat nampilin file txt #include <iostream.h>   #include <fstream.h>   #include <conio.h> void main()   {   ofstream textbaru;   textbaru.open("D:/example.txt");   textbaru<<"Ini adalah contoh program menuliskan teks ke dalam file"<<endl;   textbaru.close();   getch();   } nah kan sederhana... ga ribet..bisa di baca dan di jelaskan oleh dirimu sendiri? klo masih ga ngerti sih gampang penjelesannya. script include klo kate dosen ane adalah kunci untuk menyalakan beberapa perintah script yang di gunakan... klo contoh paling gampang ya itu iostream (input output stream) fungsinya buat ngejalanin script cin or cout ofstream di bawah header berfungsi buat man

Instal linux di usb

HAi linux-er mania.... okay langsung ajah tips dari saya tentang membuat live Usb dengan mudah dan cepat, yaitu : 1. Download UNetBootin (pilih sesuai Sistem operasi yang anda gunakan, windows ato linux) disini 2. Siapkan Distro linux yang anda ingin gunakan.... bisa dari cd/dvd, file iso-nya, ato anda punya koneksi internet? bisa otomatis di download sama UNetBootin. 3. Berikut ini daftar Distro Linux yang ringan, yang dapat anda pertimbangkan untuk di instal ke flash disk anda... - DSL (Damn Small Linux - ARCH Linux - xpud-0.9 - clonezilla-live-1.2.2-14 - austrumi-1.7.2 - slax-6.0.7 - Dream Linux - FreeBSD - Elive - System rescue dan lain - lain sebagainya..... 4. Setelah memilih Distro yang cocok, kemudian Pilih flashdisk yang ingin digunakan, minimal kapasitas yang dapat saya anjurkan adalah flashdisk dengan kapasitas minimal 1 GB..... Lalu masukkan FlashDisk ke komputer anda. 5. Jika sistem operasi yang anda gunakan adalah windows, maka tinggal anda klik