Class Matrik c++


    Join 4Shared Now! Join 4Shared Now! Join 4Shared Now! Join 4Shared Now!
    malam malam binggung mau ngapain.. daripada binggung mendingan belajar c++ aja lah.. sekarang kita mencoba membuat kelas matrik, jadi inget waktu kuliah disuruh maju ngerjain kelas matrik.. ya walaupun gak selesai yang penting udah nyoba, kali ini program ini udah selesai hehe 🙂

<#include
using namespace std;

class Matriks
{
private :
int **mat;
int sizex;
int sizey;
void getInput();
void printMatriks();
public :
Matriks();
void init();
void printTranspose();
};

Matriks::Matriks()
{
sizex = 0;
sizey = 0;
}

void Matriks::getInput()
{
do{
cout <> sizex;
}while(sizex < 1);
do{
cout <> sizey;
}while(sizey < 1);

mat = new (int*)[sizex];
for(int i =0; i< sizex;i++)
mat[i] = new int[sizey];

for(int i = 0; i < sizex;i++)
for(int j = 0; j < sizey; j++)
{ cout <<"mat["<<i+1<<"]["<<j+1<> mat[i][j];
}
}

void Matriks::printMatriks()
{
cout<<"Matriks masukan :\n\n";
for(int i = 0; i < sizex; i++)
{for(int j = 0; j < sizey ; j++)
cout<<mat[i][j]<<" ";
cout<<"\n";}
cout<<"\n\n";
}

void Matriks::printTranspose()
{
cout<<"Tranpose : \n\n";
for(int i = 0; i < sizey;i++)
{
for(int j = 0; j < sizex; j++)
{
cout<<mat[j][i]<<" ";
}
cout<<"\n";
}
}

void Matriks::init()
{
getInput();
printMatriks();
}

int main(int argc, char** argv)
{
Matriks M;

M.init();
M.printTranspose();

return 0;
}

Join 4Shared Now!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: