Wednesday, March 6, 2013
Fungsi STRING
Posted by
Unknown
at
10:50 PM
Macam-macam fungsi STRING
1.
#include <iostream>
#include <string.h>
main () {
using namespace std;
char kata1[15],kata2[15];
cout<<"Masukan Kata 1= ";cin>>kata1;
cout<<"Masukan Kata 2= ";cin>>kata2;
cout<<"hasilstrcat= "<<strcat(kata1,kata2)<<endl;
cout<<"hasilstrupr= "<<strupr(kata1)<<endl;
cout<<"hasilstrlwr= "<<strlwr(kata1)<<endl;
cout<<"hasilstrrev= "<<strrev(kata1)<<endl;
cout<<"hasilstrlen= "<<strlen(kata1)<<endl;
return 0;}
---------------------------------------------------------------------------------------------------------------------
2.
#include <iostream>
#include<stdio.h>
#include<string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(intargc, char *argv[]) {
using namespace std;
char kata[50];
cout<<"Masukkansembarang kata =";
gets(kata);
strrev(kata);
cout<<"Hasilperubahan="<<kata;
return 0; }
---------------------------------------------------------------------------------------------------------------------
3.
#include <iostream>
#include<stdio.h>
#include<conio.h>
#include<string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(intargc, char *argv[]) {
using namespace std;
charhuruf[50];
cout<<"Masukkan kata sembarang =";
gets(huruf);
cout<<"Panjang kata yang diinputkan=";
cout<<strlen(huruf);
cout<<"karakter";
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------------------
4.
#include <iostream>
#include<stdio.h>
#include<conio.h>
#include<string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(intargc, char *argv[]) {
using namespace std;
charhuruf[50];
cout<<"Masukkan kata sembarangdenganhurufbesar =";
gets(huruf);
cout<<"Hasilperubahan=";
cout<<strlwr(huruf);
return 0;
}
---------------------------------------------------------------------------------------------------------------------
5.
#include <iostream>
#include<stdio.h>
#include<conio.h>
#include<string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(intargc, char *argv[]) {
using namespace std;
charhuruf[50];
cout<<"Masukkan kata sembarangdenganhurufkecil =";
gets(huruf);
cout<<"Hasilperubahan=";
cout<<strupr(huruf);
return 0;
}
---------------------------------------------------------------------------------------------------------------------
6.
#include <iostream>
#include<stdio.h>
#include<conio.h>
#include<string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(intargc, char *argv[]) {
using namespace std;
charhuruf[100];
cout<<"Masukkannamaanda ?";
gets(huruf);
cout<<"Hello "<<huruf<<".\n";
cout<<"Film Favoritanda?";
gets(huruf);
cout<<"I Like "<<huruf<<" too.\n";;
return 0;
}
---------------------------------------------------------------------------------------------------------------------
7.
#include <iostream>
#include <conio.h>
#include <string.h>
int main(intargc, char *argv[]) {
using namespace std;
char nama_1[50];
char nama_2[50];
cout<<"---------------------------------------------"<<endl;
cout<<"Siti Sariyanti (12018183)"<<endl;
cout<<"---------------------------------------------"<<endl;
//input string
cout<<"MasukanNamaPertama : ";
cin.getline(nama_1,sizeof(nama_1));
cout<<"MasukanNamaKedua : ";
cin.getline(nama_2,sizeof(nama_2));
cout<<"NamaPertama : "<<nama_1<<endl;
cout<<"NamaKedua : "<<nama_2<<endl<<endl;
//menentukanpanjang string
cout<<"Panjang string untuknamapertama ("<<nama_1<<") adalah : "<<strlen(nama_1)<<endl;
cout<<"Panjang string untuknamakedua ("<<nama_2<<") adalah : "<<strlen(nama_2)<<endl<<endl;
//mengubahhurufkecil di string kehurufkapital
cout<<"Menjadihurufkapital"<<endl;
cout<<"Namapertama : "<<strupr(nama_1)<<endl;
cout<<"Namakedua : "<<strupr(nama_2)<<endl<<endl;
//mengubahhurufkapital di string kehurufkecil
cout<<"Menjadihurufkecil"<<endl;
cout<<"Namapertama : "<<strlwr(strupr(nama_1))<<endl;
cout<<"Namapertama : "<<strlwr(strupr(nama_2))<<endl<<endl;
//membalikanhuruf di string
cout<<"String namapertama ("<<nama_1<<") dibalikadalah : "<<strrev(nama_1)<<endl;
cout<<"String namakedua ("<<nama_2<<") dibalikadalah : "<<strrev(nama_2)<<endl<<endl;
//menggabungkan string namapertamadannamakedua
cout<<"Menggabungkandua string"<<endl<<"string namapertamadannamakedua"<<endl;
cout<<strcat(nama_1,nama_2)<<endl<<endl;
cout<<"-------------"<<endl;
cout<<"Terimakasih"<<endl;
cout<<"-------------"<<endl;
getch ();
}
Subscribe to:
Post Comments (Atom)
Nozh_Statistik
About Me
Translate
Facebook Nozhbitha
Twitter-nozhbitha
Followers
copyright by Nozhbitha. Powered by Blogger.
Labels
- ALPRO (9)
- Buah tangan (5)
- ISENG_ISENG (1)
- Latihan alpro (30)
- Linux (1)
- Nozh Gallery (2)
- Nozhbitha (29)
- Pemrograman C++ (7)
- tentang alpro (12)
0 comments:
Post a Comment