Friday, 23 October 2015
Bahasa Pemrograman : Struktur Data 05
TDA(Tipe Data Abstrak).
Tipe Data Abstrak 1D Statis
# include <iostream.h>
# define maks 5
class Array1D {
friend ostream& operator<<(ostream&, const Array1D&);
friend istream& operator>>(istream&, Array1D&);
public :
Array1D();
void cetak();
void geser_kiri();
void geser_kanan();
private :
char A[maks];
};
void Array1D::cetak(){
for (int i=0; i<maks; i++)
cout << A[i] << " ";
}
ostream& operator<<(ostream& out, const Array1D& x){
for (int i=0; i<maks; i++){
cout << x.A[i] << " ";
cout << endl;
return out;
}
istream& operator>>(istream& in, Array1D& x){
int posisi;
cout << "Mengisi array pada posisi ke : ";
in >> posisi;
if (posisi > 0 && posisi <= maks) {
cout << "Masukkan elemen array-nya : ";
in >> x.A[posisi-1];
}
else
cout << "Anda memasukkan posisi di luar range ... ";
return in;
}
voi d Array1D::geser_kanan(){
int n = maks;
int temp = A[n-1];
f or (int i=n-1; i >= 0; i--)
A[i+1] = A[i];
A [0] = temp;
}
void Array1D::geser_kiri(){
int n = maks;
int temp = A[0];
for (int i=0; i < n; i++)
A[i] = A[i+1];
A[n-1] = temp;
}
Main
main() {
Array1D x;
cout << "Array masih kosong : " << x;
cin >> x;
cout << "Isi Array saat ini : " << x;
x.geser_kiri();
cout << "Isi Array setelah digeser ke kiri : " << x;
x.geser_kanan();
cout << "Isi Array setelah digeser ke kanan : " << x;
return 0;
}
Subscribe to:
Post Comments (Atom)
R-chord 謝和弦 - I'm Not Your Prince Charming 我不是白馬王子 Lyrics 歌詞 with Pinyin
R-chord 謝和弦 x 高爾宣 & 李傑明 - I'm Not Your Prince Charming 我不是白馬王子 (Wo Bu Shi Bai Ma Wang Zi) Lyrics 歌詞 with Pinyin | 謝和弦 我不是白馬王子 歌詞 ...
-
He Yi Hang 賀一航 - Please Say Hello First 請先說你好 (Qing Xian Shuo Ni Hao) Lyrics 歌詞 with Pinyin | 賀一航 請先說你好 歌詞 Singer: He Yi Hang 賀一航 Album: Ple...
-
Wang Yi Tai 王以太 - Mu Bu Zhuan Jing 目不轉睛 Lyrics 歌詞 with Pinyin | 王以太 目不轉睛 歌詞 Singer: Wang Yi Tai 王以太 Album: Mu Bu Zhuan Jing 目不轉睛 Title: Mu B...
-
Ann 白安 - After You Left 離開後 (Li Kai Hou) Lyrics 歌詞 with Pinyin | 白安 離開後 歌詞 Singer: Ann 白安 Album: 1990s Title: 離開後 (Li Kai Hou) English Title...
No comments:
Post a Comment