#include <iostream>
#include <conio.h>
#include <iomanip>
#include <math.h>
using namespace std;
class bubblesort{
private:
float A[5];
public:
void isi_array(float B[]);
void urutkan(float B[]);
void tampilkan(float B[]);
};
void bubblesort::isi_array(float B[]){
for(int i=0;i<5;i++){
cout<<"Masukkan data ke-"<<i+1<<":";
cin>>B[i];
}
}
void bubblesort::urutkan(float B[]){
float temp;
for(int i=1;i<5;i++){
for (int j=0;j<4;j++){
if(B[j]>B[j+1]){
temp=B[j];
B[j]=B[j+1];
B[j+1]=temp;
}
}
}
}
void bubblesort::tampilkan(float B[]){
for(int i=0;i<5;i++){
cout<<B[i]<<" ";
}
cout<<endl;
}
int main(int argc, char *argv[])
{
bubblesort bs;
float A[5];
int key;
bs.isi_array(A);
bs.urutkan(A);
bs.tampilkan(A);
cout<<"Tekan Esc untuk mengakhiri...\n";
while(1)
{
if(kbhit())
{
key = getch();
if(key == 27)
break;
}
}
return 0;
}
Tidak ada komentar:
Posting Komentar