program matriks dengan class
#include <iostream>
#include <string>
using namespace std;
class matriku{
public:
void matriku::matrik(int i,int s);
};
void matriku::matrik (int i, int s)
{
string raptor_prompt_variable_zzyz;
int j;
int k;
int baris;
int kolom;
int matrik1[100];
int matrik2[100];
int mat_kali[100];
int jumlah[100];
if (s==1)
{
raptor_prompt_variable_zzyz ="masukan baris : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> baris;
raptor_prompt_variable_zzyz ="masukan kolom : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> kolom;
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
raptor_prompt_variable_zzyz ="isi matrik : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> matrik1[i,j];
j =j+1;
}
i =i+1;
}
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
raptor_prompt_variable_zzyz ="isi matrik : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> matrik2[i,j];
j =j+1;
}
i =i+1;
}
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
jumlah[i,j] = matrik1[i,j]+matrik2[i,j];
j =j+1;
}
i =i+1;
}
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
cout << jumlah[i,j] << endl; j =j+1;
}
i =i+1;
}
}
else
{
raptor_prompt_variable_zzyz ="masukan baris : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> baris;
raptor_prompt_variable_zzyz ="masukan kolom : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> kolom;
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
raptor_prompt_variable_zzyz ="isi matrik : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> matrik1[i,j];
j =j+1;
}
i =i+1;
}
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
raptor_prompt_variable_zzyz ="isi matrik : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> matrik2[i,j];
j =j+1;
}
i =i+1;
}
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
if (baris==kolom)
{
mat_kali[i,j] = 0;
k =1;
while (!(k>baris))
{
mat_kali[i,j] = mat_kali[i,j]+matrik1[i,k]*matrik2[k,j];
k =k+1;
}
}
else
{
cout << "tidak bisa dikali" << endl; }
j =j+1;
}
i =i+1;
}
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
cout << mat_kali[i,j] << endl; j =j+1;
}
i =i+1;
}
}
}
int main()
{
matriku x;
string raptor_prompt_variable_zzyz;
int s;
int i;
raptor_prompt_variable_zzyz ="pilih 1 pejumlahan dan 2 perkalian matrik: ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> s;
i =1;
x.matrik(i,s);
system("pause");
return 0;
}
#include <string>
using namespace std;
class matriku{
public:
void matriku::matrik(int i,int s);
};
void matriku::matrik (int i, int s)
{
string raptor_prompt_variable_zzyz;
int j;
int k;
int baris;
int kolom;
int matrik1[100];
int matrik2[100];
int mat_kali[100];
int jumlah[100];
if (s==1)
{
raptor_prompt_variable_zzyz ="masukan baris : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> baris;
raptor_prompt_variable_zzyz ="masukan kolom : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> kolom;
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
raptor_prompt_variable_zzyz ="isi matrik : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> matrik1[i,j];
j =j+1;
}
i =i+1;
}
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
raptor_prompt_variable_zzyz ="isi matrik : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> matrik2[i,j];
j =j+1;
}
i =i+1;
}
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
jumlah[i,j] = matrik1[i,j]+matrik2[i,j];
j =j+1;
}
i =i+1;
}
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
cout << jumlah[i,j] << endl; j =j+1;
}
i =i+1;
}
}
else
{
raptor_prompt_variable_zzyz ="masukan baris : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> baris;
raptor_prompt_variable_zzyz ="masukan kolom : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> kolom;
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
raptor_prompt_variable_zzyz ="isi matrik : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> matrik1[i,j];
j =j+1;
}
i =i+1;
}
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
raptor_prompt_variable_zzyz ="isi matrik : ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> matrik2[i,j];
j =j+1;
}
i =i+1;
}
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
if (baris==kolom)
{
mat_kali[i,j] = 0;
k =1;
while (!(k>baris))
{
mat_kali[i,j] = mat_kali[i,j]+matrik1[i,k]*matrik2[k,j];
k =k+1;
}
}
else
{
cout << "tidak bisa dikali" << endl; }
j =j+1;
}
i =i+1;
}
i =1;
while (!(i>baris))
{
j =1;
while (!(j>kolom))
{
cout << mat_kali[i,j] << endl; j =j+1;
}
i =i+1;
}
}
}
int main()
{
matriku x;
string raptor_prompt_variable_zzyz;
int s;
int i;
raptor_prompt_variable_zzyz ="pilih 1 pejumlahan dan 2 perkalian matrik: ";
cout << raptor_prompt_variable_zzyz << endl;
cin >> s;
i =1;
x.matrik(i,s);
system("pause");
return 0;
}
Komentar
Posting Komentar