#include <iostream.h>
#include <conio.h>
//header
class array{
friend istream& operator >> (istream&, array&);
friend ostream& operator << (ostream&, array&);
//overloading input output
public:
int proses();
private:
int n, baris, kolom;
int array1[50];
int array2[50][50];
//class
};
istream& operator >> (istream& in, array& masuk){
cout<<"==ARRAY 2 DIMENSI=="<<endl;
cout<<"banyaknya kolom : ";
in>>masuk.kolom;
cout<<"banyaknya baris : ";
in>>masuk.baris;
//input bilangan
for (int k=0;k<masuk.baris;k++)
{
for (int l=0;l<masuk.kolom;l++)
{
cout<<"Masukkan data ke ["<<k+1<<"] ["<<l+1<<"] : ";
in>>masuk.array2[k][l];
//cout<<masuk.array2[k][l]<<" ";
for (int k=0;k<masuk.baris;k++)
{
for (int l=0;l<masuk.kolom;l++)
{
cout<<masuk.array2[k][l];
}
cout<<endl;
}
}
}}
ostream& operator <<(ostream& out, array& keluar){
out<<endl<<"Thank you.."<<endl;
}
int array::proses()
{
cout<<"==ARRAY 1 DIMENSI=="<<endl;
int d=0;
cout<<endl<<"setelah diubah menjadi satu dimensi: "<<endl;
for (int k=0;k<baris;k++)
{
for (int l=0;l<kolom;l++)
{
array1[d]=array2[k][l];//konversi array 2 dimensi ke 1 dimensi
cout<<array1[d];//cetak array 1 dimensi
}
}
}
int main(){
array a;
cin >> a;
a.proses();
cout << a;
getch ();
return 0;
//main function
}
0 komentar:
Posting Komentar