Kuis minggu ini dikerjakan secara
berkelompok. Masing-masing kelompok harus membuat algoritma, cpp dan raptor.
Saya mendapat bagian mengerjakan cpp nya. Teman saya nisa nur istiqomah
mengerjakan raptor dan vita silvia mengerjakan algoritmanya.
Soalnya seperti ini.
Input : 123
Output : seratus dua puluh tiga.
Program cpp nya seperti ini.
#include <iostream>
using namespace std;
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
{
cout<<"error";
}
}
int main()
{
unsigned long nilai;
printf(" \t\t\t Konversi Angka ke Dalam Kata \n");
cout << "\n MASUKKAN BILANGAN : ";
cin >>nilai;
terbilang(nilai);
}
using namespace std;
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
{
cout<<"error";
}
}
int main()
{
unsigned long nilai;
printf(" \t\t\t Konversi Angka ke Dalam Kata \n");
cout << "\n MASUKKAN BILANGAN : ";
cin >>nilai;
terbilang(nilai);
}
Program ini menggunakan function.
Ada 2 function yaitu untuk satuan dan terbilang. Function satuan untuk
mendiskripsikan pengkondisian angka 1-11 agar bisa teroutput kata satu –
sebelas. Lalu pada function terbilang
untuk mendiskripsikan agar outputnya belas, ratus, puluh, seratus. Penginputan nilai dan outputnya
dipanggil di dalam int main.
outputnya seperti dibawah ini
untuk raptornya dapat dilihat di http://nisanurist.blogspot.co.id/2016/04/minggu-kelima-alpro-kuis-kelompok.html
untuk algoritma dapat dilihat di http://vitawijaya.blogspot.co.id/2016/04/kuis-alpro-minggu-ke-5kelompok.html

Tidak ada komentar:
Posting Komentar