0% found this document useful (0 votes)
24 views

Koding Program

This C++ program defines a class called "matriks" to represent a matrix. The class contains private member variables to store the number of rows and columns of the matrix and a 2D array to store the matrix elements. Friend functions are used to overload input and output operators to accept user input for the matrix and display the output. The main function creates a matrix object, gets input, stores elements in the object using the class member function, and prints the output matrix.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Koding Program

This C++ program defines a class called "matriks" to represent a matrix. The class contains private member variables to store the number of rows and columns of the matrix and a 2D array to store the matrix elements. Friend functions are used to overload input and output operators to accept user input for the matrix and display the output. The main function creates a matrix object, gets input, stores elements in the object using the class member function, and prints the output matrix.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Koding Program
#include <cstdlib>
#include <iostream>
using namespace std;
class matriks{
public:
friend istream& operator>>(istream&, matriks&);
friend ostream& operator<<(ostream&, matriks&);
void masuk_data();
matriks();
private:
int x[10][10],n,m;
};
matriks::matriks(){
cout<<"PROGRAM MATRIKS | MICHAEL SIMATUPANG"<<endl;}
istream& operator>>(istream& in, matriks& a){
cout<<"Masukkan banyak baris :"; in>>a.n;
cout<<"Masukkan banyak kolom :"; in>>a.m;}
void matriks::masuk_data(){
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
cout<<"Masukkan data ke ["<<i+1<<"]["<<j+1<<"] :";
cin>>x[i][j];
}}
}
ostream& operator<<(ostream& out,matriks& b){
out<<"Banyak baris ="<<b.n<<endl;
out<<"Banyak kolom ="<<b.m<<endl;
out<<"Matriks X ="<<endl;
for(int i=0; i<b.n; i++){
out<<"\t";
for(int j=0; j<b.m; j++){
out<<b.x[i][j]<<"\t";
}cout<<endl;
}
}
int main(int argc, char *argv[])
{
matriks arif;
cin>>arif;
arif.masuk_data();
cout<<arif;
system("PAUSE");
return EXIT_SUCCESS;
}

2. Tampilan Program

3. Penjelasan Program/ Keterangan

You might also like