Periksa
buku tabungan salah satu anggota kelompok. Lakukan detail transaksi pengambilan
uang tabungan termasuk detail isian dalam formulir transaksi. Pisahkan
algoritma penulisan angka menjadi ejaan :
Misal anda mengambil uang sebesar 300.000 akan
tertulis sebagai ‘Tiga ratus ribu rupiah”
Menggunakaan c++ :
#include<stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;
class pembilang{
public :
void satuan(int x){
if (x==1) {
cout<<" Satu ";
}
else if (x==2){
cout<<" Dua ";
}
else if (x==3){
cout<<" Tiga ";
}
else if (x==4){
cout<<" Empat ";
}
else if (x==5){
cout<<" Lima ";
}
else if (x==6){
cout<<" Enam ";
}
else if (x==7){
cout<<" Tujuh ";
}
else if (x==8){
cout<<" Delapan ";
}
else if (x==9){
cout<<" Sembilan ";
}
else if (x==10){
cout<<" Sepuluh ";
}
else if (x==11){
cout<<" Sebelas ";
}
}
void terbilang(long y){
if (y<=11) satuan(y);
else if ((y>11) && (y<=19)){
terbilang(y%10);
cout<<" Belas";
}
else if ((y>=20)&&(y<=99)){
terbilang(y/10);
cout<<" Puluh";
terbilang(y%10);
}
else if ((y>=100)&&(y<=199)){
cout<<" Seratus";
terbilang(y%100);
}
else if ((y>=200)&&(y<=999)){
terbilang(y/100);
cout<<" Ratus";
terbilang(y%100);
}
else if ((y>=1000)&&(y<=1999)){
cout<<" Seribu";
terbilang(y%1000);
}
else if ((y>=2000)&&(y<=9999)){
terbilang(y/1000);
cout<<" Ribu";
terbilang(y%1000);
}
else if ((y>=10000)&&(y<=99999)){
terbilang(y/1000);
cout<<" Ribu";
terbilang(y%1000);
}
else if ((y>=100000)&&(y<=999999)){
terbilang(y/1000);
cout<<" Ribu";
terbilang(y%1000);
}
else if ((y==1000000)){
terbilang(y/1000000);
cout<<" Juta";
terbilang(y%1000000);
}
else if ((y>1000000) && (y < 10000000)){
terbilang(y/1000000);
cout<<" juta";
terbilang(y%1000000);
} else {
cout<<"error";
}
}
};
int main(){
pembilang a;
unsigned long uang;
cout << " masukkan bilangan uang anda = Rp."; cin >>uang;
a.terbilang(uang); cout<<" Rupiah";
}
#include <conio.h>
#include <iostream>
using namespace std;
class pembilang{
public :
void satuan(int x){
if (x==1) {
cout<<" Satu ";
}
else if (x==2){
cout<<" Dua ";
}
else if (x==3){
cout<<" Tiga ";
}
else if (x==4){
cout<<" Empat ";
}
else if (x==5){
cout<<" Lima ";
}
else if (x==6){
cout<<" Enam ";
}
else if (x==7){
cout<<" Tujuh ";
}
else if (x==8){
cout<<" Delapan ";
}
else if (x==9){
cout<<" Sembilan ";
}
else if (x==10){
cout<<" Sepuluh ";
}
else if (x==11){
cout<<" Sebelas ";
}
}
void terbilang(long y){
if (y<=11) satuan(y);
else if ((y>11) && (y<=19)){
terbilang(y%10);
cout<<" Belas";
}
else if ((y>=20)&&(y<=99)){
terbilang(y/10);
cout<<" Puluh";
terbilang(y%10);
}
else if ((y>=100)&&(y<=199)){
cout<<" Seratus";
terbilang(y%100);
}
else if ((y>=200)&&(y<=999)){
terbilang(y/100);
cout<<" Ratus";
terbilang(y%100);
}
else if ((y>=1000)&&(y<=1999)){
cout<<" Seribu";
terbilang(y%1000);
}
else if ((y>=2000)&&(y<=9999)){
terbilang(y/1000);
cout<<" Ribu";
terbilang(y%1000);
}
else if ((y>=10000)&&(y<=99999)){
terbilang(y/1000);
cout<<" Ribu";
terbilang(y%1000);
}
else if ((y>=100000)&&(y<=999999)){
terbilang(y/1000);
cout<<" Ribu";
terbilang(y%1000);
}
else if ((y==1000000)){
terbilang(y/1000000);
cout<<" Juta";
terbilang(y%1000000);
}
else if ((y>1000000) && (y < 10000000)){
terbilang(y/1000000);
cout<<" juta";
terbilang(y%1000000);
} else {
cout<<"error";
}
}
};
int main(){
pembilang a;
unsigned long uang;
cout << " masukkan bilangan uang anda = Rp."; cin >>uang;
a.terbilang(uang); cout<<" Rupiah";
}
Output :

Tidak ada komentar:
Posting Komentar