Assalamu'alaikum
tanpa panjang lebar, dahulu Bu Yuli memberi tugas, buatlah matrik array bla . . bla. . bla. .
input, output, transpose, diagonal, perkalian, dll
nah setelah serangkaian percobaan, akhirnya . . .nek ada trouble<error> kasih komentar di bawah . .
oye???
source code : :
#include <iostream>
#include <conio>
#include <stdlib>
main(){
typedef matrik33[3][3];
int pilih,max,min;
int a,b,x;
menu:
clrscr();
cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
cout<<"----MATRIK--3*3--MATRIK--3*3--MATRIK--3*3--MATRIK--3*3--MATRIK--3*3--MATRIK----"<<endl;
cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
cout<<"\n\nMENU : "<<endl;
cout<<"1.Input matrik";
cout<<"\n2.Output matrik";
cout<<"\n3.Penjumlahan matrik";
cout<<"\n4.Pengurangan matrik";
cout<<"\n5.Transpose matrik";
cout<<"\n6.Diagonal matrik";
cout<<"\n7.Nilai maksimal dan minimal matrik";
cout<<"\n8.Perkalian matrik dengan konstanta";
cout<<"\n9.Perkalian dua matrik";
cout<<"\n10.Keluar program";
cout<<"\n\nmasukkan pilihan : ";
cin>>pilih;
if(pilih==1){
clrscr();
input:
clrscr();
cout<<"MENU INPUT : ";
cout<<"\n1.Input matrik A";
cout<<"\n2.Input matrik B";
cout<<"\n3.Kembali ke menu utama";
cout<<"\nmasukkan pilihan : ";
cin>>pilih;
cout<<endl;
if(pilih==1){
for(int a=0;a<3;a++){
for(int b=0;b<3;b++){
cout<<"array ["<<a<<"]["<<b<<"] = ";
cin>>K[a][b];
}
}
getch();
goto input;
}
else if(pilih==2){
for(int a=0;a<3;a++){
for(int b=0;b<3;b++){
cout<<"array ["<<a<<"]["<<b<<"] = ";
cin>>L[a][b];
}
}
getch();
goto input;
}
else if(pilih==3){
goto menu;
}
else {
cout<<"\nPilihan anda salah . . .\n";
cout<<"ERROR";
getch();
goto input;
}
}
else if(pilih==2){
clrscr();
output:
clrscr();
cout<<"MENU OUTPUT : ";
cout<<"\n1.Output matrik A";
cout<<"\n2.Output matrik B";
cout<<"\n3.Kembali ke menu utama";
cout<<"\nmasukkan pilihan : ";
cin>>pilih;
if(pilih==1){
cout<<"\nmatrik A\n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto output;
}
else if(pilih==2){
cout<<"\nmatrik B\n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto output;
}
else if(pilih==3){
goto menu;
}
else {
cout<<"\npilihan anda salah . . .\n";
cout<<"ERROR";
getch();
goto input;
}
}
else if(pilih==3){
clrscr();
jumlah:
clrscr();
cout<<"MENU JUMLAH: ";
cout<<"\n1.Matrik A + matrik B";
cout<<"\n2.Kembali ke menu utama";
cout<<"\nmasukkan pilihan : ";
cin>>pilih;
if(pilih==1){
cout<<"\nmatrik A \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nmatrik B \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nmatrik A + matrik B \n";
for(int a=0;a<3;a++){
for(int b=0;b<3;b++){
M[a][b]=K[a][b]+L[a][b];
}
}
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<M[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto jumlah;
}
else if(pilih==2){
goto menu;
}
else {
cout<<"\nPilihan anda salah . . .\n";
cout<<"ERROR";
getch();
goto input;
}
}
else if(pilih==4){
clrscr();
kurang:
clrscr();
cout<<"MENU KURANG: ";
cout<<"\n1.Matrik A - matrik B";
cout<<"\n2.Kembali ke menu utama";
cout<<"\nmasukkan pilihan : ";
cin>>pilih;
if(pilih==1){
cout<<"\nmatrik A \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nmatrik B \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nmatrik A - matrik B \n";
for(int a=0;a<3;a++){
for(int b=0;b<3;b++){
N[a][b]=K[a][b]-L[a][b];
}
}
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<N[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto kurang;
}
else if(pilih==2){
goto menu;
}
else {
cout<<"\nPilihan anda salah . . .\n";
cout<<"ERROR";
getch();
goto input;
}
}
else if(pilih==5){
clrscr();
transpose:
clrscr();
cout<<"MENU TRANSPOSE : ";
cout<<"\n1.Transpose matrik A";
cout<<"\n2.Transpose matrik B";
cout<<"\n3.Kembali ke menu utama";
cout<<"\nmasukkan pilihan : ";
cin>>pilih;
if(pilih==1){
cout<<"\nsebelum transpose : \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nsetelah transpose : \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
T[a][b]=K[b][a];
cout<<T[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto transpose;
}
if(pilih==2){
cout<<"\nsebelum transpose : \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nsetelah transpose : \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
T[a][b]=L[b][a];
cout<<T[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto transpose;
}
else if(pilih==3){
goto menu;
}
else {
cout<<"\nPilihan anda salah . . .\n";
cout<<"ERROR";
getch();
goto transpose;
}
}
if(pilih==6){
clrscr();
diagonal:
clrscr();
cout<<"MENU DIAGONAL : ";
cout<<"\n1.Diagonal matrik A";
cout<<"\n2.Diagonal matrik B";
cout<<"\n3.Kembali ke menu utama";
cout<<"\nmasukkan pilihan : ";
cin>>pilih;
if(pilih==1){
cout<<"\nmatrik A \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\ndiagonal matrik A \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
if(a==b){
cout<<K[a][b]<<"\t";
}
}
}
getch();
goto diagonal;
}
if(pilih==2){
cout<<"\nmatrik A \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\ndiagonal matrik B \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
if(a==b){
cout<<L[a][b]<<"\t";
}
}
}
getch();
goto diagonal;
}
else if(pilih==3){
goto menu;
}
else {
cout<<"\nPilihan anda salah . . .\n";
cout<<"ERROR";
getch();
goto diagonal;
}
}
if(pilih==7){
clrscr();
maxmin:
clrscr();
cout<<"MENU MAKSIMAL/MINIMAL :";
cout<<"\n1.Maksimal/minimal matrik A";
cout<<"\n2.Maksimal/minimal matrik B";
cout<<"\n3.Kembali ke menu utama";
cout<<"\nmasukkan pilihan : ";
cin>>pilih;
if(pilih==1){
cout<<"\nmatrik A \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
max=0;
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
if (K[a][b]>max){
max=K[a][b];
}
}
}
cout<<"\nmax = "<<max;
getch();
min=K[0][0];
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
if (K[a][b]<min){
min=K[a][b];
}
}
}
cout<<"\nmin = "<<min;
getch();
goto maxmin;
}
else if(pilih==2){
cout<<"\nmatrik B \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
getch();
max=0;
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
if (L[a][b]>max){
max=L[a][b];
}
}
}
cout<<"\nmax = "<<max;
getch();
min=L[0][0];
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
if (L[a][b]<min){
min=L[a][b];
}
}
}
cout<<"\nmin = "<<min;
getch();
goto maxmin;
}
else if(pilih==3){
goto menu;
}
else {
cout<<"\nPilihan anda salah . . .\n";
cout<<"ERROR";
getch();
goto maxmin;
}
}
if(pilih==8){
clrscr();
konstanta:
clrscr();
cout<<"MENU KALI KONSTANTA : ";
cout<<"\n1.Perkalian matrik A";
cout<<"\n2.Perkalian matrik B";
cout<<"\n3.Kembali ke menu utama";
cout<<"\nmasukkan pilihan : ";
cin>>pilih;
if(pilih==1){
cout<<"\nmatrik A \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
cout<<"\nmasukkan konstanta = ";
cin>>x;
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
O[a][b]=K[a][b]*x;
}
}
cout<<"\nsetelah dikali "<<x<<endl;
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<O[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto konstanta;
}
if(pilih==2){
cout<<"\nmatrik B \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
cout<<"\nmasukkan konstanta = ";
cin>>x;
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
O[a][b]=L[a][b]*x;
}
}
cout<<"\nsetelah dikali "<<x<<endl;
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<O[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto konstanta;
}
else if(pilih==3){
goto menu;
}
else {
cout<<"\nPilihan anda salah . . .\n";
cout<<"ERROR";
getch();
goto konstanta;
}
}
if(pilih==9){
clrscr();
kalimatrik:
clrscr();
cout<<"MENU KALI MATRIK : ";
cout<<"\n1.Matrik A * matrik B";
cout<<"\n2.Kembali ke menu utama";
cout<<"\nmasukkan pilihan : ";
cin>>pilih;
if(pilih==1){
cout<<"\nmatrik A \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nmatrik B \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
X[a][b]=0;
for(int c=0;c<3;c++){
X[a][b]=X[a][b]+K[a][c]*L[c][b];
}
}
}
cout<<"\nmatrik A * matrik B \n";
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
cout<<X[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto kalimatrik;
}
else if(pilih==2){
goto menu;
}
else {
cout<<"\nPilihan anda salah . . .\n";
cout<<"ERROR";
getch();
goto kalimatrik;
}
}
else if(pilih==10){
cout<<"\nmakasih ya . . ^_- \n";
goto end;
}
else {
cout<<"\nPilihan anda salah . . .\n";
cout<<"ERROR";
getch();
goto menu;
}
end:
getch();
}
4 komentar:
typedef matrik33[3][3];
menghasilkan nilai statis,,,
harusnya dinamis pak,,,
user bebas meninputkan batas baris dan kolom matriks tsb
pusing aku liatnya,tp makasih ya chasan
hehehehe....
maap, lama ga OL
oke2 maturnuwun saran2e..
edisi revisi tersedia input dinamis simetris
gan, mhn bantuannya kok nggk ngerun sih pny abang, sy pake dev c++, yg error d bag. typedef matrik33
Posting Komentar