Click here to Skip to main content
13,625,272 members

ATL / WTL / STL

 
PinnedHOW TO ANSWER A QUESTION Pin
Chris Maunder16-Jul-09 3:09
adminChris Maunder16-Jul-09 3:09 
PinnedHow to get an answer to your question Pin
Chris Maunder16-Jul-09 3:05
adminChris Maunder16-Jul-09 3:05 
QuestionMFC VC2015 How to build from command line both settings: Use Shared DLL and Use Static DLL Pin
Member 1024558723hrs 31mins ago
professionalMember 1024558723hrs 31mins ago 
AnswerRe: MFC VC2015 How to build from command line both settings: Use Shared DLL and Use Static DLL Pin
Jochen Arndt2hrs 44mins ago
mvpJochen Arndt2hrs 44mins ago 
GeneralRe: MFC VC2015 How to build from command line both settings: Use Shared DLL and Use Static DLL Pin
Member 1024558756mins ago
professionalMember 1024558756mins ago 
QuestionHow to use CUDA programming to calculate and process the correct number Pin
Member 1378925119-Apr-18 21:35
memberMember 1378925119-Apr-18 21:35 
AnswerRe: How to use CUDA programming to calculate and process the correct number Pin
Richard MacCutchan19-Apr-18 21:54
protectorRichard MacCutchan19-Apr-18 21:54 
Rant[REPOST] How to use CUDA programming to calculate and process the correct number Pin
Richard Deeming20-Apr-18 1:10
mvpRichard Deeming20-Apr-18 1:10 
QuestionHide context menu on CScrollBar in MFC. Pin
Sampath57918-Apr-18 3:07
memberSampath57918-Apr-18 3:07 
AnswerRe: Hide context menu on CScrollBar in MFC. Pin
Victor Nijegorodov18-Apr-18 10:10
memberVictor Nijegorodov18-Apr-18 10:10 
GeneralRe: Hide context menu on CScrollBar in MFC. Pin
Sampath57919-Apr-18 2:10
memberSampath57919-Apr-18 2:10 
AnswerRe: Hide context menu on CScrollBar in MFC. Pin
Jochen Arndt19-Apr-18 3:05
mvpJochen Arndt19-Apr-18 3:05 
GeneralRe: Hide context menu on CScrollBar in MFC. Pin
Sampath57919-Apr-18 17:24
memberSampath57919-Apr-18 17:24 
QuestionHow to use .Def File Pin
tasumisra10-Apr-18 19:57
membertasumisra10-Apr-18 19:57 
AnswerRe: How to use .Def File Pin
Richard MacCutchan10-Apr-18 21:02
protectorRichard MacCutchan10-Apr-18 21:02 
GeneralRe: How to use .Def File Pin
tasumisra10-Apr-18 21:17
membertasumisra10-Apr-18 21:17 
GeneralRe: How to use .Def File Pin
Richard MacCutchan10-Apr-18 21:21
protectorRichard MacCutchan10-Apr-18 21:21 
GeneralRe: How to use .Def File Pin
tasumisra11-Apr-18 0:19
membertasumisra11-Apr-18 0:19 
GeneralRe: How to use .Def File Pin
Richard MacCutchan11-Apr-18 1:41
protectorRichard MacCutchan11-Apr-18 1:41 
GeneralRe: How to use .Def File Pin
tasumisra16-Apr-18 18:53
membertasumisra16-Apr-18 18:53 
QuestionRe: How to use .Def File Pin
Richard MacCutchan16-Apr-18 20:50
protectorRichard MacCutchan16-Apr-18 20:50 
QuestionAdding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha23-Mar-18 21:17
memberTarun Jha23-Mar-18 21:17 
here ih the code below i have tried to add two matrix objects and assign it to the third object but it doesn't give expected result and the rather some garbage value.

include <iostream>
using namespace std;

class matrix{
    int **p;    //pointer to Matrix
    int d1, d2;

public:
    //matrix(){}                  //default constructor
    matrix(int x=20, int y=20);       //parameterised

    void get_element();
    void put_element();
    int checkAdd(matrix &);                                     //to check the feasibility of the operation

    //Rule of three
    matrix operator + (matrix &);
    void operator = (matrix );

    ~matrix(){
        for (int i = 0; i < d1; i++)
            delete p[i];
        delete p;
    }
};

matrix temp;                    //global matrix temp

//=============================================

void matrix::operator = (matrix obj){

    this->d1 = obj.d1;
    this->d2 = obj.d2;
    for(int i=0; i<d1; i++)
        for(int j=0; j<d2; j++)
            this->p[i][j] = obj.p[i][j];

    //put_element();
    //return(*this);
}

matrix matrix::operator+(matrix &obj){
    if(checkAdd(obj)==0)
    {
        //matrix temp;
        for(int i=0; i<obj.d1; i++)
            for(int j=0; j<obj.d2; j++)
                temp.p[i][j] = this->p[i][j] + obj.p[i][j];


        //temp.put_element();
        return(temp) ;
    }

    cout<<"coloumn and rows of both matrix are not equal !"<<endl;
    return (*this);
}

matrix ::matrix(int x, int y)
{
    d1 = x;
    d2 = y;
    p = new int *[d1];                  //creates an array of pointers

    for(int i=0; i<d1; i++)
        p[i] = new int [d2];            //creates row for each row
}

int matrix::checkAdd(matrix &obj){
    if((this->d1 == obj.d1) && (this->d2 == obj.d2))
        return 0;
    else return 1;
}

void matrix::get_element(){
    for(int i=0; i<d1; i++)
        for(int j=0; j<d2; j++){
            cout<<"m["<<i<<"]["<<j<<"] = ";
            cin>>p[i][j];
        }
    //cout<<"Following is your Matrix : \n\n";
    //put_element();
}

void matrix::put_element(){
    cout<<"\n\n";
    for(int i=0; i<d1; i++){
        for(int j=0; j<d2; j++){
            cout<<p[i][j]<<"\t";
        }
        cout<<endl;
    }

}

//=============================================

int main(){
    matrix A(3, 2), B(3, 2), C;                     //matrix objects a constucted

    cout<<"Enter matrix elements row by row \n\n";
    A.get_element();
    A.put_element();

    B.get_element();
    B.put_element();

    C = A + B;
    cout<<"\n\n";
    C.put_element();

    return 0;
}


thank you
AnswerRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Richard MacCutchan23-Mar-18 23:34
protectorRichard MacCutchan23-Mar-18 23:34 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha24-Mar-18 3:58
memberTarun Jha24-Mar-18 3:58 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Richard MacCutchan24-Mar-18 4:31
protectorRichard MacCutchan24-Mar-18 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.180712.1 | Last Updated 16 Jul 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid