CONTOH CODING MENGGUNAKAN
BORLAND C++
CONTOH APLIKASI BANK
MENGURUT KAN SALDO TERBESAR KE TERKECIL DAN SEBALIKNYA
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
#include<stdlib.h>
struct nasabah
{
char norek[10];
char nama[25];
int saldo;
};
nasabah nsb[100];
main()
{
char ada,pilihan;
int a,tsaldo,tukar,pil;
char tnorek[11],tnama[26];
int jml=0;
ada='Y';a=0;
while(ada=='Y')
{
cout<<"\nData
Nasabah -"<<(a+1)<<endl;
cout<<"No
Rekening : ";gets(nsb[a].norek);
cout<<"Nama
Nasabah : ";gets(nsb[a].nama);
cout<<"Saldo
Tabungan : ";cin>>nsb[a].saldo;
cout<<"Ada Data
Nasabah Lannya [Y/T] : ";cin>>ada;
a++;
jml++;
}
pilihan='Y';
while(pilihan=='Y'){
cout<<"\n\nPilihan Output\n";
cout<<"1.Tertinggi ke
rendah\n";
cout<<"2.Rendah
ke tertinggi\n";
cout<<"3.Exit\n";
cout<<"Plihan :
";cin>>pil;
if(pil==1)
{
//proses sortig
tukar=1;
while(tukar==1)
{
tukar=0;
for(a=0;a<jml-1;a++)
{
if(nsb[a].saldo<nsb[a+1].saldo)
{
strcpy(tnorek,nsb[a].norek);
strcpy(nsb[a].norek,nsb[a+1].norek);
strcpy(nsb[a+1].norek,tnorek);
strcpy(tnama,nsb[a].nama);
strcpy(nsb[a].nama,nsb[a+1].nama);
strcpy(nsb[a+1].nama,tnama);
tsaldo=nsb[a].saldo;
nsb[a].saldo=nsb[a+1].saldo;
nsb[a+1].saldo=tsaldo;
tukar=1;
}
}
}
cout<<"\n\nDAta
Nasabah\n";
cout<<"------------------------------------------\n";
cout<<"No. No Rekening
Nama Nasabah Saldo \n";
cout<<"------------------------------------------\n";
a=0;
while(a<jml)
{
cout<<setw(3)<<(a+1)
<<setw(11)<<nsb[a].norek
<<setw(11)<<nsb[a].nama
<<setw(11)<<nsb[a].saldo<<endl;
a++;
}
cout<<"------------------------------------------\n";
}
else if (pil==2)
{
//proses sortig
tukar=1;
while(tukar==1)
{
tukar=0;
for(a=0;a<jml-1;a++)
{
if(nsb[a].saldo>nsb[a+1].saldo)
{
strcpy(tnorek,nsb[a].norek);
strcpy(nsb[a].norek,nsb[a+1].norek);
strcpy(nsb[a+1].norek,tnorek);
strcpy(tnama,nsb[a].nama);
strcpy(nsb[a].nama,nsb[a+1].nama);
strcpy(nsb[a+1].nama,tnama);
tsaldo=nsb[a].saldo;
nsb[a].saldo=nsb[a+1].saldo;
nsb[a+1].saldo=tsaldo;
tukar=1;
}
}
}
cout<<"\n\nDAta
Nasabah\n";
cout<<"------------------------------------------\n";
cout<<"No. No Rekening
Nama Nasabah Saldo \n";
cout<<"------------------------------------------\n";
a=0;
while(a<jml)
{
cout<<setw(3)<<(a+1)
<<setw(11)<<nsb[a].norek
<<setw(11)<<nsb[a].nama
<<setw(11)<<nsb[a].saldo<<endl;
a++;
}
cout<<"------------------------------------------\n";
}
else if(pil==3)
{
exit(1);
}
cout<<"Ada
Pilihan Lainnya[Y/T] : ";cin>>pilihan;
}
getch();
}
No comments:
Post a Comment