Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,007 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,385 people online right now. Registration is fast and FREE... Join Now!




Matrix

 
Reply to this topicStart new topic

Matrix

ritamita
27 Nov, 2006 - 08:59 PM
Post #1

New D.I.C Head
*

Joined: 21 Nov, 2006
Posts: 8


My Contributions

how to use class to write a NXN matrix which having elements Aij=i*j / (i+j-1)



User is offlineProfile CardPM
+Quote Post

Xing
RE: Matrix
28 Nov, 2006 - 01:20 AM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 4 times
Dream Kudos: 1575
My Contributions
Take a two dimensional array inside class as private member. Initilialise it in constructor. The use a method as setValue() which changes the value of array using the formula you gave using two for loops.
User is offlineProfile CardPM
+Quote Post

ritamita
RE: Matrix
1 Dec, 2006 - 08:53 AM
Post #3

New D.I.C Head
*

Joined: 21 Nov, 2006
Posts: 8


My Contributions
i writing this codings ,but it seems that the scalar doesn't work. The elements of matrix are still 1. does any one know the problem?>

//////////////////////////////////////////////////////////////////
Matrix::Matrix()
{
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
M[i][j] = 1;
}


// operator functions


Matrix Matrix::operator*( double aij )
{
Matrix temp;
int i, j;
for(i=1; i <= 3; i++)
for(j=1; j <= 3; j++)
aij = (i*j)/(i+j-1);
temp.M[i][j] = aij* M[i][j];

return temp;
}

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 08:41PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month