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

Membuat website dengan CodeIgniter Part1

Langsung aja saya jabarkan kebutuhan yg akan di pakai nanti untuk membuat sebuah website d ari framework codeigniter... pertama.. ya tentu saja source dari codeigniter-nya... bisa pake yg terbaru atau 2.0 ++ disini kedua.. database -nya bisa menggunakan MySql yg udah di bundle ke dalam Xampp disini ketiga (optional) Editor teks.... pake notepad oke... pake netbeans oke juga... Langkah selanjutnya adalah install terlebih dahulu xampp-nya jika sudah ada xamppnya, lanjut ke langkah selanjutnya, lalu kemudian extract source Codeigniter di htdocs xampp. berikut susunan direktori Codeigniter root dir....         .../application                   .../cache                   .../config                   .../controllers      ...

Mengurutkan string di C++

//*****************************************************************// // Mengurutkan data array string menggunakan bubble sort // // http://wirautama.net // //*****************************************************************// #include #include #include void main() { clrscr(); //declare the variable and array int n, test; char data[10][100]; char tmp[100]; n = 10; //input data for(int i=0; i { cout cin>>data[i]; } //sort data using bubble sort for(int i=0; i { for(int j=i+1; j { test = strcmp(data[i], data[j]); if(test > 0) { strcpy(tmp, data[i]); strcpy(data[i], data[j]); strcpy(data[j], tmp); } } } cout for(int i=0; i { cout } getch(); }

A history of Einstein

Around 1886 Albert Einstein began his school career in Munich. As well as his violin lessons, which he had from age six to age thirteen, he also had religious education at home where he was taught Judaism. Two years later he entered the Luitpold Gymnasium and after this his religious education was given at school. He studied mathematics, in particular the calculus, beginning around 1891.  In 1894 Einstein's family moved to Milan but Einstein remained in Munich. In 1895 Einstein failed an examination that would have allowed him to study for a diploma as an electrical engineer at the Eidgenössische Technische Hochschule in Zurich. Einstein renounced German citizenship in 1896 and was to be stateless for a number of years. He did not even apply for Swiss citizenship until 1899, citizenship being granted in 1901.  Following the failing of the entrance exam to the ETH, Einstein attended secondary school at Aarau planning to use this route to enter the ETH in Zurich. While at Aarau he wr...