Rabu, 18 Februari 2015

Library Function pada pemrograman C



Escape Character
\a :untukbunyi bell (alert)
\b :mundursatuspasi (backspace)
\f :gantihalaman (form feed)
\n :gantibarisbaru (new line)
\r :kekolompertama, baris yang sama (carriage return)
\v :tabulasi vertical
\0 :nilaikosong (null)
\’ :karakterpetiktunggal
\” :karakterpetikganda
\\ :karaktergaris miring

Library Function


Salah satufungsi library yang telahdiperkenalkanyaitu cout yaituuntukmencetakkelayar monitor. Fungsidikelompokkanmenurutjenisdansifatnyadandisimpandidalamsebuah file yang berekstensi .h. Sebagaicontohfungsi yang digunakanuntukmencetakkelayar monitor (cout) disimpanpada file iostream.h.
Library iostream.h

Standard Input / Output Streams Library.
Elemeniostream library (char instantion) :

Classes :

| ios_base Base | ios | istream | ostream | iostream | ifstream | ofstream | fstream | istringstream | ostringstream | stringtream | streambuf | filebuf | stringbuf |
Objects :

| cin | cout | cerr | clog |

Types :

| fpos : | streamoff | streampos | streamsize |

Manipulators :

| boolalpha | dec | endl | ends | fixed | flush | hex | internal | left | noboolalpha | noshowbase | noshowpoint | noshowpos | noskipws | nounitbuf | nouppercase | oct | resetiosflags | right | scientific | setbase | setfill | setiosflags | setprecision | setw | showbase | showpoint | showpos | skipws | unitbuf | uppercase | ws |

Objekiostreammewarisisemuaanggotayaituistreamdanostream, sehinggamampumelakukankeduaoperasi input dan output.
Library stdio.h

Library stdio.h adalah library padabahasa C yang digunakanuntukoperasi input output (stdio = Standard Input and Output). Tanpamenggunakan library inimakaperintah - perintah input/output tidakdapatdieksekusiataudijalankan.


Library Functions :

| clearr() | fclose() | fccloseall() | fdopen() | fflush() | fgetc() | fgetchar() | fgetpos() | fgets() | flushall() | fopen() | fprint() | fputc() | fputchar() | fputs() | fread() | free() | freopen() | fscan() | fseek() | fsetpos() | ftell() | fwrite() | gets() | getw() | perror() | printf() | puts() | putw() | rename() | rewind() | scanf() | unlink() |

Library Macroes :

| feof(f) | ferror(f) | fileno(f) | getch(f) | getchar(f) | putchar(f) | remove(path) |

Contohpenggunaan library stdio.h dengan library functions printf() dalam program :

#include <stdio.h>
intmain(){
printf("Hello World!\n");
printf("SelamatBelajarPemrogramanC/C++.");
return 0;
}




Contohpenggunaan library stdio.h dengan library functions puts() dalam program :

#include <stdio.h>
#include <conio.h>
using namespace std;
int main(){
char x[20]="Bandung";
puts("ITBHanya di ");
puts(x);
return 0;
}

Library math.h

Library math.h merupakansebuah library yang disediakanuntukmelakukanperhitungansecaramatematika.

Library Functions :

| abs() | acosh() | asin() | atan() | atan2() | atof() | ceil() | cos() | cosh() | exp() | fabs() | floor() | fmod() | labs() | ldexp() | log() | log10() | pow() | sin() | sinh() | sqrt() | tan() | tanh() |

Contohpenggunaan library math.h dengan library functions cos() dan sin() dalam program :

//Penggunaan library math.h
#include <iostream.h>
#include <math.h>
using namespace std;
int main(){
    double kecepatan, jarak, sudut;
    kecepatan=20;
    sudut=25;
jarak = 2*kecepatan*kecepatan*sin(sudut*3.14/180)*cos(sudut*3.14/180)/9.8;
cout<<"Jarak = "<<jarak;
    cout<<"\n";
    system("Pause");
    return 0;
}

Library stdlib.h

Library stdlib.h merupakan library yang hampirsamadengan library math.h, namunisidari library stdlib.h berbedadengan library math.h yaitu :

Library Functions :

| abs() | atof() | atoi() | atol() | div() | exit() | free() | ldiv() | malloc() | rand() | srand() | system() |

Library Macroes :

| abs(x) | atoi(s) | random(num) | randomize() |

Contohpenggunaan library stdlib.h dengan library functions atoi() dalam program :

//Penggunaan library stdlib.h
#include <iostream.h>
#include <stdlib.h>
using namespace std;
int main(){
    char karakter[8]="12.3AB";
    intnilai;
    nilai=atoi(karakter);
    cout<<nilai<<endl;
    system("Pause");
    return 0;
}

Library string.h

Suatu library padabahasa C yang digunakanuntukmemberikannilaisuatukarakter string.

LibrariFunctions :

| strcpy() | strcat() | strchr() | strcmp() | strlen() |

Contohpenggunaan library string.h dengan library functions strcpy() dalam program :

//Penggunaan library string.h
#include <iostream.h>
#include <string.h>
using namespace std;
int main(){
    char info[30];
strcpy(info, "info: D4 TKJMD");
cout<<info;
cout<<"\n";
system("Pause");
return 0;
}

Library conio.h

Library Functions :

| clrscr() | getch() | getche() | gotoxy() | khbit() | putch() |

Contohpenggunaan library conio.h dengan library funtions getche() atau getch() dalam program :

//Penggunaan library conio.h
#include <iostream.h>
#include <conio.h>
using namespace std;
int main(){
cout<<"Hai, SelamatdatangmahasiswabaruITB \n";
getche();
}

Library io.h

Library Functions :

| access() | _close() | close() | _creat() | eof() | filelenght() | _open() | open() | _read() | read() | _write() | write() |


Library ctype.h

Library Functions :

| stlower() | toupper() |

Library Macroes :


| isalnum( c) | isalpha( c) | isascii( c) | iscntrl( c) | isdigit( c) | isgraph( c) | islower( c) | isprint( c) | ispunct( c) | isspace( c) | isupper( c) | isxdigit( c) | toascii( c) | _tolower( c) | _toupper( c) |

0 komentar:

Posting Komentar