Array statis dan dinamis

#include <cstdlib>
#include <iostream>
#define maks 5

using namespace std;

class Array1D{
public:
Array1D();
void input();
void cetak();
void geser_kanan();
private:
char A[maks];
};

Array1D::Array1D(){
cout<<“Belajar Array 1D”<<endl<<endl;
}

void Array1D::input(){
for(int i=0; i<maks; i++){
cout<<“Masukan index ke-“<<i<<“=”;
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;
}

Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s