edisi revisi
versi input dinamis simetris
#include <iostream>
#include <conio>
#include <stdlib>
main(){
int K['r']['s'],L['r']['s'],M['r']['s'],N['r']['s'],O['r']['s'],T['r']['s'],X['r']['s'];
int pilih,max,min;
int a,b,x,r,s;
clrscr();
welcome:
clrscr();
cout<<"Program Matriks";
cout<<"\n---------------\n";
cout<<":: baris :: = ";
cin>>r;
cout<<":: kolom :: = ";
cin>>s;
menu:
clrscr();
cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
cout<<" matrik "<<r<<" * "<<s<<" "<<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<<"\n\n11.Setel ulang baris dan kolom matrik";
cout<<"\n12.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<r;a++){
for(int b=0;b<s;b++){
cout<<"array ["<<a<<"]["<<b<<"] = ";
cin>>K[a][b];
}
}
getch();
goto input;
}
else if(pilih==2){
for(int a=0;a<r;a++){
for(int b=0;b<s;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<r;a++){
for (int b=0;b<s;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto output;
}
else if(pilih==2){
cout<<"\nmatrik B\n";
for (int a=0;a<r;a++){
for (int b=0;b<s;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 output;
}
}
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<r;a++){
for (int b=0;b<s;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nmatrik B \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nmatrik A + matrik B \n";
for(int a=0;a<r;a++){
for(int b=0;b<s;b++){
M[a][b]=K[a][b]+L[a][b];
}
}
for (int a=0;a<r;a++){
for (int b=0;b<s;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 jumlah;
}
}
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<r;a++){
for (int b=0;b<s;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nmatrik B \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nmatrik A - matrik B \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
N[a][b]=K[a][b]-L[a][b];
}
}
for (int a=0;a<r;a++){
for (int b=0;b<s;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 kurang;
}
}
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){
if(r==s){
cout<<"\nsebelum transpose : \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nsetelah transpose : \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
T[a][b]=K[b][a];
cout<<T[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto transpose;
}
if(r!=s){
cout<<"\nmatrik anda tidak dapat mengeksekusi operasi ini\n";
cout<<"karena ordo matrik anda tidak mendukung\n";
getch();
goto transpose;
}
}
if(pilih==2){
if(r==s){
cout<<"\nsebelum transpose : \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nsetelah transpose : \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
T[a][b]=L[b][a];
cout<<T[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto transpose;
}
if(r!=s){
cout<<"\nmatrik anda tidak dapat mengeksekusi operasi ini\n";
cout<<"karena ordo matrik anda tidak mendukung\n";
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){
if(r==s){
cout<<"\nmatrik A \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\ndiagonal matrik A \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
if(a==b){
cout<<K[a][b]<<"\t";
}
}
}
getch();
goto diagonal;
}
if(r!=s){
cout<<"\nmatrik anda tidak dapat mengeksekusi operasi ini\n";
cout<<"karena ordo matrik anda tidak mendukung\n";
getch();
goto kalimatrik;
}
}
if(pilih==2){
if(r==s){
cout<<"\nmatrik A \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\ndiagonal matrik B \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
if(a==b){
cout<<L[a][b]<<"\t";
}
}
}
getch();
goto diagonal;
}
if(r!=s){
cout<<"\nmatrik anda tidak dapat mengeksekusi operasi ini\n";
cout<<"karena ordo matrik anda tidak mendukung\n";
getch();
goto kalimatrik;
}
}
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<r;a++){
for (int b=0;b<s;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
max=0;
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
if (K[a][b]>max){
max=K[a][b];
}
}
}
cout<<"\nmax = "<<max;
getch();
min=K[0][0];
for (int a=0;a<r;a++){
for (int b=0;b<s;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<r;a++){
for (int b=0;b<s;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
getch();
max=0;
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
if (L[a][b]>max){
max=L[a][b];
}
}
}
cout<<"\nmax = "<<max;
getch();
min=L[0][0];
for (int a=0;a<r;a++){
for (int b=0;b<s;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<r;a++){
for (int b=0;b<s;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
cout<<"\nmasukkan konstanta = ";
cin>>x;
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
O[a][b]=K[a][b]*x;
}
}
cout<<"\nsetelah dikali "<<x<<endl;
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
cout<<O[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto konstanta;
}
if(pilih==2){
cout<<"\nmatrik B \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
cout<<L[a][b]<<"\t";
}
cout<<endl;
}
cout<<"\nmasukkan konstanta = ";
cin>>x;
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
O[a][b]=L[a][b]*x;
}
}
cout<<"\nsetelah dikali "<<x<<endl;
for (int a=0;a<r;a++){
for (int b=0;b<s;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){
if(r==s){
cout<<"\nmatrik A \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
cout<<"\nmatrik B \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
cout<<K[a][b]<<"\t";
}
cout<<endl;
}
getch();
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
X[a][b]=0;
for(int c=0;c<r;c++){
X[a][b]=X[a][b]+K[a][c]*L[c][b];
}
}
}
cout<<"\nmatrik A * matrik B \n";
for (int a=0;a<r;a++){
for (int b=0;b<s;b++){
cout<<X[a][b]<<"\t";
}
cout<<endl;
}
getch();
goto kalimatrik;
}
if(r!=s){
cout<<"\nmatrik anda tidak dapat mengeksekusi operasi ini\n";
cout<<"karena ordo matrik anda tidak mendukung\n";
getch();
goto kalimatrik;
}
}
else if(pilih==2){
goto menu;
}
else {
cout<<"\nPilihan anda salah . . .\n";
cout<<"ERROR";
getch();
goto kalimatrik;
}
}
else if(pilih==11){
goto welcome;
}
else if(pilih==12){
cout<<"\nmakasih ya . . ^_- \n";
goto end;
}
else {
cout<<"\nPilihan anda salah . . .\n";
cout<<"ERROR";
getch();
goto menu;
}
end:
getch();
}
Edisi Revisi : Matrik 2 Dimensi Input Dinamis Simetris
Jumat, 19 November 2010
0 komentar:
Posting Komentar