Click here to Skip to main content
15,880,956 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Hackerrank:Down to Zero problem Pin
David Crow25-Mar-18 15:41
David Crow25-Mar-18 15:41 
QuestionIn type conversion of 2 different classes can i convert both ways ? Pin
Tarun Jha25-Mar-18 5:14
Tarun Jha25-Mar-18 5:14 
AnswerRe: In type conversion of 2 different classes can i convert both ways ? Pin
Victor Nijegorodov25-Mar-18 8:07
Victor Nijegorodov25-Mar-18 8:07 
GeneralRe: In type conversion of 2 different classes can i convert both ways ? Pin
Tarun Jha25-Mar-18 23:26
Tarun Jha25-Mar-18 23:26 
AnswerRe: In type conversion of 2 different classes can i convert both ways ? Pin
CPallini25-Mar-18 10:50
mveCPallini25-Mar-18 10:50 
GeneralRe: In type conversion of 2 different classes can i convert both ways ? Pin
Tarun Jha25-Mar-18 23:25
Tarun Jha25-Mar-18 23:25 
GeneralRe: In type conversion of 2 different classes can i convert both ways ? Pin
CPallini26-Mar-18 0:18
mveCPallini26-Mar-18 0:18 
QuestionAdding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha24-Mar-18 8:19
Tarun Jha24-Mar-18 8:19 
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
Victor Nijegorodov24-Mar-18 8:35
Victor Nijegorodov24-Mar-18 8:35 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha24-Mar-18 10:06
Tarun Jha24-Mar-18 10:06 
AnswerRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Richard MacCutchan24-Mar-18 21:13
mveRichard MacCutchan24-Mar-18 21:13 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha25-Mar-18 5:08
Tarun Jha25-Mar-18 5:08 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Richard MacCutchan25-Mar-18 5:32
mveRichard MacCutchan25-Mar-18 5:32 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha25-Mar-18 6:37
Tarun Jha25-Mar-18 6:37 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Richard MacCutchan25-Mar-18 7:16
mveRichard MacCutchan25-Mar-18 7:16 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha25-Mar-18 8:06
Tarun Jha25-Mar-18 8:06 
QuestionLinux C++ implementation of ioctl SOLVED Pin
Vaclav_23-Mar-18 8:50
Vaclav_23-Mar-18 8:50 
AnswerRe: Linux C++ implementation of ioctl Pin
Jochen Arndt24-Mar-18 23:39
professionalJochen Arndt24-Mar-18 23:39 
AnswerRe: Linux C++ implementation of ioctl Pin
leon de boer26-Mar-18 16:53
leon de boer26-Mar-18 16:53 
GeneralRe: Linux C++ implementation of ioctl Pin
Vaclav_4-Apr-18 5:08
Vaclav_4-Apr-18 5:08 
QuestionVS2017: Cannot debug Dll's Pin
indrekm23-Mar-18 1:13
indrekm23-Mar-18 1:13 
SuggestionRe: VS2017: Cannot debug Dll's Pin
Richard MacCutchan23-Mar-18 1:21
mveRichard MacCutchan23-Mar-18 1:21 
SuggestionRe: VS2017: Cannot debug Dll's Pin
Jochen Arndt23-Mar-18 1:25
professionalJochen Arndt23-Mar-18 1:25 
AnswerRe: VS2017: Cannot debug Dll's Pin
Randor 23-Mar-18 8:09
professional Randor 23-Mar-18 8:09 
QuestionSelect and Pick lines in OpenGL Pin
Gopi Nath22-Mar-18 19:40
Gopi Nath22-Mar-18 19:40 

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.