#include
#include
#include "xcept.h"
class Array1D{
friend istream& operator<<(ostream&,const Array1D&); public: Array1D(int size=0); Array1D(const Array1D& v); ~Array1D(){delete [] element;} int& operator[](int i)const; int Size(){return size;} Array1D& operator=(const Array1D& v); Array1D operator+()const; Array1D operator+(const Array1D& v)const; Array1D operator-()const; Array1D operator-(const Array1D& v)const; Array1D operator*(const Array1D& v)const; Array1D& operator+=(const int& x); Array1D& Resize(int sz); private: int size; int* element; }; Array1D::Array1D(int sz){ if(sz<0)throw size="sz;" element="new" size="v.size;" element="new" i="0;" int="" i=""><0||i>=size)throw OutOfBounds();
return element[i];
}
Array1D& Array1D::operator=(const Array1D& v){
if(this !=&v){
size=v.size;
delete[]element;
element=new int[size];
for(int i=0;i
element[i]=element[i];
}
return* this;
}
Array1D Array1D::operator+(const Array1D& v)const{
if (size != v.size) throw SizeMismatch();
Array1D w(size);
for(int i=0; i
w.element[i]=element[i]+v.element[i];
return w;
}
Array1D Array1D::operator-(const Array1D& v)const{
if(size != v.size) throw SizeMismatch();
Array1D w(size);
for(int i=0; i
w.element[i]=element[i]-v.element[i];
return w;
}
Array1D Array1D::operator-()const{
Array1D w(size);
for(int i=0; i
w.element[i]=-element[i];
return w;
}
Hasil Output :
About Me
Statistik
Live Traffic Feed
Daftar Blog Teman
Link
Blogroll
Didukung
Followers
- Anak Indonesia Harapan Masa Depan (1)
- APBO (1)
- Basis Data (2)
- ERD (1)
- MySQL (1)
- Pendidikan (3)
- Peran Perbankan dan Koperasi dalam mendorong peningkatan kewirausahaan di Indonesia (1)
- PHP (2)
- Programing C++ (8)
- Sewa Ruang Kantor Jakarta Murah (1)
- Sistem Operasi (6)
- Struktur Data (1)
- Web Desain (4)
- Web Dinamis (2)
#include
#include
#define maks 5
using namespace std;
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];
};
Array1D::Array1D()
{
for(int i=0;i
{
int posisi;
cout<<"Mengisi pada posisi ke : "; in>>posisi;
if(posisi>0 &&posisi<=maks){ cout<<"masukkan elemen array-nya :"; in>>x.A[posisi-1];
}
else
cout<<"anda memasukan posisi diluar range ..."; return in; } void Array1D::geser_kanan() { int n = maks; int temp = A[n-1]; for(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
cout<<"isi array saat ini:"<
x.geser_kiri();
cout<<"isi array setelah digeser ke kiri :"<
x.geser_kanan();
cout<<"isi array setelah digeser ke kanan :"<
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil output :