Tuesday, 15 May 2012

Examples of RAPTOR and C + + program to shift to the left of the array elements


on this occasion, return to admin flowchartnya array, the array itself is of the order, maybemy friends are more familiar, the array is shifted to the left, for example we have input 1:2: 3: 4: 5; it will be shifted left 2; 3, 4; 5; 0; or there is also a 2; 3, 4, 5, 1;, is the same just different assumptions here are peoggram RAPTOR to transform the image to the leftArray elements:







































for more details, please just try it on file. rapnya can be downloaded atRaptor-Array elements shifted to the left

Program Array elements shifted to the left

#include <cstdlib>
#include <iostream>
#define maks5


using namespace std;



class array{
friend ostream& operator<<(ostream&, const array&);
friend istream& operator>>(istream&, array&);
public:
array();
void cetak();
void geser_kiri();



private:
char a[5];
int posisi;
};

array::array(){
for(int i=0;i<5;i++)
a[i]='O';
}



void array::cetak(){
for(int i=0;i<5;i++)
cout<<a[i]<<" ";
}

ostream& operator<<(ostream& out, const array& keluar){
for(int i=0;i<5;i++)
out<<keluar.a[i]<<" ";
out<<endl;
return out;
}

istream& operator>>(istream& in, array& masuk){
int posisi;
for (int posisi=1; posisi<=5; posisi++){
cout<<"masukkan nilai array posisi ke-"<<posisi<<"= ";
//in>>masuk.posisi;
if(posisi >= 0 && posisi <= 5){
//cout<<"masukkan elemen arraynya :";
in>>masuk.a[posisi-1];
}
}
return in;
}

void array::geser_kiri(){
int n=5;
int temp=a[0];
for(int i=0;i<n;i++)
a[i]=a[i+1];
a[n-1]=temp;
}

int main(int argc, char *argv[])
{
array X;
cout<<"Array masih kosong : "<<X;
cin>>X;

cout<<"Isi Array saat ini : "<<X;
X.geser_kiri();
cout<<"Isi Array setelah di geser kiri : "<<X;

system("PAUSE");
return EXIT_SUCCESS;
}

0 comments:

Post a Comment

.

.

.

.
Design by BlogSpotDesign | Ngetik Dot Com