Archive for Oktober 2013
Praktikum Struktur Data (Array)
#include <cstdlib>
#include <iostream>
#define maks 5
using namespace std;
class Array1D{
public:
Array1D();
void input();
void geser_kiri();
void geser_kanan();
void cetak();
private:
char A[maks];
};
Array1D::Array1D(){
cout<<"Belajar array 1D"<<endl<<endl;
}
void Array1D::input(){
for(int i=0;i<maks; i++)
{
cout<<"masukan indeks ke-"<<i<<" = "<<endl;
cin>>A[i];
}
}
void Array1D::cetak(){
for(int i=0; i<maks; i++){
cout<<A[i]<<" ";
}
cout<<endl;
}
void Array1D::geser_kanan(){
int n= maks;
char temp = A[n-1];
for(int i=n-2; i>=0; i--)
A[i+1]=A[i];
A[0] = temp;
}
int main(int argc, char *argv[]){
Array1D x;
x.input();
x.cetak();
x.geser_kanan();
x.cetak();
system("PAUSE");
return EXIT_SUCCESS;
}
Tag :
Struktur Data