Fungsi Terbilang Di C++

Tugas akhir 12 RPL semester ganjil  : Membuat fungsi terbilang

Pada tugas ini saya selain membuat fungsi terbilang saya juga membuat fungsi pengolahan string seperti mid, left, right,  ucase, lcase dan fcase.

// fungsi.cpp : Defines the entry point for the console application.
//author : Rizki Dermawan
//

#include “stdafx.h”
#include <iostream>
#include <string>
using namespace std;
char* mid(char *V,int a, int b){
char *B = new char[b];
for(int i=a,j=0;i<=a+b;i++,j++){
if(i==(a+b)){
B[j] = ”;
}
else
B[j] = V[i];
}
return B;
}
char* left(char *V,int a){
char *B = new char[a];
for(int i=0,j=0;i<=a;i++,j++){
if(i==a){
B[j] = ”;
}
else
B[j] = V[i];
}
return B;
}
char* right(char *V,int a){
char *B = new char[a];
int x = strlen(V);
for(int i=x-a,j=0;i<=a;i++,j++){
if(i==a){
B[j] = ”;
}
else
B[j] = V[i];
}
return B;
}
char* ucase(char *V){
int x = strlen(V);
char *B = new char[x];
for(int i=0,j=0;i<=x;i++,j++){
if(i==x){
B[j] = ”;
}
else{
if(char(V[i])>=97 && char(V[i])<=122)
B[j] = char(V[i]-32);
else
B[j] = V[i];
}
}
return B;
}
char* lcase(char *V){
int x = strlen(V);
char *B = new char[x];
for(int i=0,j=0;i<=x;i++,j++){
if(i==x){
B[j] = ”;
}
else{
if(char(V[i])>=65 && char(V[i])<=90)
B[j] = char(V[i]+32);
else
B[j] = V[i];
}
}
return B;
}
char* fcase(char *V){
int x = strlen(V);
char *B = new char[x];
for(int i=0,j=0;i<=x;i++,j++){
if(i==x){
B[j] = ”;
}
else if(i==0){
if(char(V[i])>=97 && char(V[i])<=122)
B[j] = char(V[i]-32);
else
B[j] = V[i];
}
else
B[j] = V[i];
}
return B;
}
string terbilang(char *V){
int x = strlen(V);
char **B,**s;
char *sat;
string final=””;
B = new char*[x];
s = new char*[x];
char *kata[10]={“”,”satu “,”dua “, “tiga “, “empat “, “lima “, “enam “, “tujuh “, “delapan “, “sembilan “};
char *kat[6]={“rupiah “,”ribu “,”juta “,”milyar “,”triliun “,”niunniun “};
char *achi[3]={“”,”puluh “, “ratus “};
for(int i=x-1,j=0;i>=0;i–,j++){
int z = j%3;
int a = j/3;
z!=0?s[j]=achi[z]:s[j]=kat[a];
B[j]=kata[atoi(mid(V,j,1))];
}
for(int i=0,j=x-1;i<x;i++,j–){
int z = j%3;
int a = j/3;

if(char(V[i])==48 && z!=0){
s[j]=””;
}
if(x==4 && z==0  && char(V[i])==49 || z>0 && char(V[i])==49){
B[i]=”se”;
switch(z){
case 1: s[j]=”puluh “;break;
case 2: s[j]=”ratus “;break;
case 0: s[j]=”ribu “;break;
}
}
if(z==1){
if(a>0){
if(char(V[i])==48 && char(V[i+1])==48 && char(V[i-1])==48){
s[j-1]=””;
}
}
if(char(V[i])==49){
if(char(V[i+1])!=49){
if(char(V[i+1])==48){
B[i]=”se”;
}
else{
B[i]=B[i+1];
s[j]=”belas “;
B[i+1]=””;
}
}
else{
B[i]=”Se”;
s[j]=”belas “;
B[i+1]=””;
}
}
}
B[0]=fcase(B[0]);
final+=B[i];
final+=s[j];
}
return final;
}
int main()
{
char nama[100];
char anka[16];
cout<<“======================================”<<endl;
cout<<“Nama Pemberi             : “;cin.getline(nama,sizeof(nama));
anka:
cout<<“Jumlah Uang              : “;cin.getline(anka,sizeof(anka));
if(atoi(anka)==0){
cout<<“Jumlah yang dimasukan salah”<<endl;
goto anka;
}
cout<<“======================================”<<endl;
cout<<endl;
cout<<“Bukti Pembayaran”<<endl;
cout<<endl;
cout<<“======================================”<<endl;
cout<<“Nama         : “<<fcase(nama)<<endl;
cout<<“Banyak uang  : Rp.”<<anka<<endl;
cout<<“Terbilang    : “<<endl;
cout<<“————————————–“<<endl;
cout<<”    “<<terbilang(anka)<<endl<<endl;
cout<<“======================================”<<endl;
}

One thought on “Fungsi Terbilang Di C++

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s