Footer 1

2012/05/05

LP Manipulasi String C++

1. Berikan contoh program manipulasi string!!

a. #include <iostream>
#include <conio>
#include <string.h>
main () {
char kata1[15],kata2[15];
cout<<"Masukan Kata 1= ";cin>>kata1;
cout<<"Masukan Kata 2= ";cin>>kata2;
cout<<"hasil strcmp= "<<strcmp(kata1,kata2)<<endl;
cout<<"hasil strcat= "<<strcat(kata1,kata2)<<endl;
cout<<"hasil strlwr= "<<strlwr(kata1)<<endl;
cout<<"hasil strupr= "<<strupr(kata1)<<endl;
cout<<"hasil strrev= "<<strrev(kata1)<<endl;
cout<<"hasil strlen= "<<strlen(kata1)<<endl;
getch();}

b. #include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <string.h>
main () {
char depan[25],belakang[25];
clrscr();
cout<<"Input nama depan = ";gets(depan);
cout<<"Input Nama belakang =";gets(belakang);
cout<<"---------------------------------------"<<endl;
cout<<"Nama lengkap = "<<strcat(depan,belakang)<<endl;
cout<<"Panjang Nama = "<<strlen(depan)<<endl;
cout<<"Nama dibalik = "<<strrev(depan)<<endl;
cout<<"Huruf kecil = "<<strlwr(depan)<<endl;
cout<<"Huruf Kapital = "<<strupr(depan)<<endl;
getch();}

c. #include <conio.h>
#include <iostream.h>#include <stdio.h>
#include <string.h>
main() {
char a1[5]="BSI",a2[5]="WRJ";
strcpy(a1,a2);
cout<<"Hasilnya Adalah = "<<a1;
getch();}
Rating: 5

0 comments: