ARRAY (MATRIK)

ini adalah menu utamanya dalam program ini ,, terdiri dari beberapa program array ,,


jika kita memasukan angka satu maka akan menghasilkan program sebagai berikut..


 

dan jika memasukan angka 2 maka akan muncul. .


untuk output lainnya dapat di coba sendiri aja kali yah ...
berikut ini adalah codingnya :

#include<conio.h>
#include<iostream.h>
#include<iomanip.h>

void kertas1()
{
cout<<" =========================================\n";
cout<<"      Tugas Algoritma dan Pemrograman 2  \n";
cout<<" =========================================\n";
cout<<"       UNIVERITAS PAKUAN KOTA BOGOR \n";
cout<<" =========================================\n\n";
}

void kertas2()
{
cout<<" - - - - - - - - - - - - -\n";
cout<<" Program Membuat Matrik \n";
cout<<" - - - - - - - - - - - - -\n";
}

void kertas3()
{
cout<<" - - - - - - - - - - - - - - - -\n";
cout<<" Program Perkalian Matrik \n";
cout<<" - - - - - - - - - - - - - - - -\n";
}

void kertas4()
{
cout<<" - -  - - - - - - - - - - - - \n";
cout<<" Program Pengurangan Matrik \n";
cout<<" - - - -- - - - - - - - - - - \n";
}

void kertas5()
{
cout<<" - -  - - - - - - - - - -\n";
cout<<" Program Perkalian Matrik \n";
cout<<" - - - -- - - -- -  - - -\n";
}

void kertas6()
{
cout<<" - -  - - - - - - - - - - -\n";
cout<<" Program Matrik Transpose \n";
cout<<" - - - -- - - - - - - - - -\n";
}

void kertas7()
{
cout<<"- - - - - - - - - - - - -\n";
cout<<" Program Matrik Identitas\n";
cout<<"- - - - - - - - - - - - -\n";
}
void main()
{
int lu,sy, I;
float A[10][10], B[10][10], T[10][10], K[10][10], Kali[10][10];

char pil;
sang:
clrscr();
kertas1();
cout<<"Menu : \n";
cout<<"1. Membuat Matrik \n";
cout<<"2. Penjumlahan Matrik \n";
cout<<"3. Pengurangan Matrik \n";
cout<<"4. Perkalian Matrik \n";
cout<<"5. Matrik Transpose \n";
cout<<"6. Matrik Identitas \n";
cout<<"7. Selesai\n";
cout<<"\nPilih Program Nomor[1-6] dan keluar[7] : ";
cin>>pil;cout<<endl;
switch(pil)
{
  case '1' :

  {
clrscr();
kertas1();
getch();
  kertas2();
  cout<<" masukan ordo matrik : "; cin>>I;
  cout<<" ----------------------";
  cout<<"\n Elemen Matrik A ";
cout<<endl;

for (lu=0;lu<I;lu++)
{
for (sy=0;sy<I;sy++)
{
cout<<"indek["<<lu<<"]["<<sy<<"] : ";
cin>>A[lu][sy];
}
cout<<endl;
}

cout<<"  matrik A \n";
cout<<"--------------";
cout<<endl;
for (lu=0;lu<I;lu++)
{
cout<<setiosflags(ios::left)<<setw(2)<<" ";
for (sy=0;sy<I;sy++)
{
cout<<setiosflags(ios::right)<<setw(5);
getch();
cout<<A[lu][sy]<<"  ";
}
cout<<endl;
}

break;
}
  case '2' :
  {
  clrscr();
kertas1();
getch();
  kertas3();
cout<<" masukan ordo matrik : "; cin>>I;
cout<<" ---------------------";
cout<<"\n Elemen Matrik A ";
cout<<endl;
for (lu=0;lu<I;lu++)
{
for (sy=0;sy<I;sy++)
{
cout<<"indek["<<lu<<"]["<<sy<<"] : ";
cin>>A[lu][sy];
}
cout<<endl;
}
cout<<"---------------\n";
cout<<"Elemen Matrik B ";
cout<<endl;
for (lu=0;lu<I;lu++)
{
for (sy=0;sy<I;sy++)
{
cout<<"indek["<<lu<<"]["<<sy<<"] : ";
cin>>B[lu][sy];
}
cout<<endl;
}
//mencari hasil penjumlahan
for(lu=0;lu<I;lu++)
for(sy=0;sy<I;sy++)
T[lu][sy]=A[lu][sy]+B[lu][sy];
cout<<"\nHasil penjumlahan :\n";
cout<<"---------------------\n";
for(lu=0;lu<I;lu++)
{
cout<<setiosflags(ios::left)<<setw(2)<<" ";
for(sy=0;sy<I;sy++)
{
cout<<setiosflags(ios::right)<<setw(5);
getch();
cout<<T[lu][sy]<<" ";
}
cout<<endl;
}
break;
  }
  case '3' :
  {
  clrscr();
kertas1();
getch();
  kertas4();
  cout<<" masukan ordo matrik : "; cin>>I;
  cout<<"Elemen Matrik A ";
cout<<endl;
for (lu=0;lu<I;lu++)
{
for (sy=0;sy<I;sy++)
{
cout<<"indek["<<lu<<"]["<<sy<<"] : ";
cin>>A[lu][sy];
}
cout<<endl;
}
cout<<"---------------\n";
cout<<"Elemen Matrik B ";
cout<<endl;

for (lu=0;lu<I;lu++)
{
for (sy=0;sy<I;sy++)
{
cout<<"indek["<<lu<<"]["<<sy<<"] : ";
cin>>B[lu][sy];
}
cout<<endl;
}
//mencari hasil penjumlahan
for(lu=0;lu<I;lu++)
for(sy=0;sy<I;sy++)
K[lu][sy]=A[lu][sy]-B[lu][sy];
cout<<"\nHasil Pengurangan :\n";
cout<<"----------------------\n";
for(lu=0;lu<I;lu++)
{
cout<<setiosflags(ios::left)<<setw(2)<<" ";
for(sy=0;sy<I;sy++)
{
cout<<setiosflags(ios::right)<<setw(5);
getch();
cout<<K[lu][sy]<<" ";
}
cout<<endl;
}
break;
  }
  case '4' :
  {
clrscr();
kertas1();
getch();
kertas5();
cout<<" masukan ordo matrik : "; cin>>I;
cout<<"Elemen Matrik A ";
cout<<endl;
for (lu=0;lu<I;lu++)
{
for (sy=0;sy<I;sy++)
{
cout<<"indek["<<lu<<"]["<<sy<<"] : ";
cin>>A[lu][sy];
}
cout<<endl;
}
cout<<"---------------\n";
cout<<"Elemen Matrik B ";
cout<<endl;

for (lu=0;lu<I;lu++)
{
for (sy=0;sy<I;sy++)
{
cout<<"indek["<<lu<<"]["<<sy<<"] : ";
cin>>B[lu][sy];
}
cout<<endl;
}
//mencari hasil perkalian
for(lu=0;lu<I;lu++)
for(sy=0;sy<I;sy++)
Kali[lu][sy]=A[lu][sy]*B[lu][sy];
cout<<"\nHasil Perkalian :\n";
cout<<"--------------------\n";
for(lu=0;lu<I;lu++)
{
cout<<setiosflags(ios::left)<<setw(2)<<" ";
for(sy=0;sy<I;sy++)
{
cout<<setiosflags(ios::right)<<setw(5);
getch();
cout<<Kali[lu][sy]<<" ";
}
cout<<endl;
}
break;
}

case '5':
{
clrscr ();
kertas1();
getch();
kertas6 ();
cout<<" masukan ordo matrik : "; cin>>I;
cout<<" Elemen Matrik adalah  \n";
cout<<"\-- -- -- -- -- -- -- --\n";
for (lu=0;lu<I;lu++)
{
for (sy=0;sy<I;sy++)
{
cout<<"indek["<<lu<<"]["<<sy<<"] : ";
cin>>A[lu][sy];
}
cout<<endl;
}

cout<<"matrik A";
cout<<endl;
for (lu=0;lu<I;lu++)
{
for (sy=0;sy<I;sy++)
{
cout<<A[lu][sy]<<"  ";
getch();
}
cout<<endl;
}

cout<<"\n  Transpose matrik A";
cout<<endl;
//program utama untuk matrik transpose
for(sy=0;sy<I;sy++)
{
cout<<setiosflags(ios::right)<<setw(0)<<" ";
for (lu=0;lu<I;lu++)
{
cout<<setiosflags(ios::right)<<setw(4)<<" ";
cout<<A[lu][sy]<<"  ";

getch();
}
cout<<endl;
}
 break ;
}
case '6':
{
clrscr ();
kertas1();
getch();
kertas7 ();
cout<<"masukan ordo matrik : ";
cin>>I;
for(lu=0; lu<I; lu++)
{
for(sy=0; sy<I; sy++)
{
if(lu==sy)
cout<<"1 ";
else
cout<<"0 ";
getch();
}
cout<<endl;
}
 break ;
}
case '7' :
clrscr();
cout<<"=====================================\n";
cout<<"||         MAN JADDA WAJADDA        ||\n";
cout<<"||       DEPILIYANTO (0651.13.047)  ||\n";
cout<<"||   SIAPA YANG BERSUNGGUH SUNGGUH  ||\n";
cout<<"||         DIA AKAN BERHASIL        ||\n";
cout<<"=====================================\n\n";
cout<<"THANK :) :D \n";
goto end;
}
getch();
goto sang;
end:
}



selamat pagi menjelang siang . . :D





No comments:

Post a Comment