help with this c++ code mat lib

Please Help In This code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96


    #include <iostream>


    using namespace std;
    class mat{
    double **data;
    int r,c,a,k,j,t;
    public:
    mat(){ r = 0; c=0; data = NULL;}
    mat(int n, int m){
    r = n ; c =m;
    data = new double*[r];
    for(int i=0;i<r;i++)
    data[i]=new double[c];
    }
    ~mat(){
    for(int i=0;i<r;i++)
    delete data[i];
    delete data;
    }
    void read()
        {
        for(int i=0;i<r;i++)
        for(int j=0;j<c;j++)
        cin>>data[i][j];
        }
    void add(mat m)
    {
        for(int i=0;i<r;i++)
        for(int j=0;j<c;j++)
        data[i][j]+=m.data[i][j];

    }

    void mul(mat m, mat &R)
    {
        for(int i=0;i<r;i++)
        for(int j=0;j<m.c;j++)
        R[i][i]=0;
        for(int k=0;k<c;k++)
        R.data[i][j]+=data[i][k]*m.data[k][j];
    }
    void trace(mat &t)
    {
        int i;
        t=0;
        for(j=0;j<r;j++)
        t=t+a[i][i];
        cout<<t;
    }
    void trans()
    {
        mat x(c,r);
        for(int i=0;i<r;i++)
        for(int j=0;j<c;j++)
        x.data[j][i]=data[j][i];
        data=x.daata[j][i];
        r=x.r;
        c=x.c;
    }
    void AddOffset(int k)
    {
        for(int i=0;i<r;i++)
        for(int j=0;j<c;j++)
        data[i][j]+=k;
    }
    void MulOffset(int k)
    {
        for(int i=0;i<r;i++)
        for(int j=0;j<c;j++)
        data[i][j]*=k;
    }
    void print()
    {
        for(int i=0;i<r;i++)
        for(int j=0;j<c;j++)
        cout<<data[i][j];
        }

    int main()
    {
    mat A(3,3);
    A.read();
    A.trace(t);
    mat B(2,3);
    B.read();
    A.add(B);
    A.trans();
    mat t(2,3);
    B.mul(A,t);
    t.print();
    return 0;
    }
Last edited on
Tell us what you need help with.
have errors when compiling
its a matrix lib.
These are easy:
- daata does not exist: data=x.daata[j][i];
- in main: t does not exist: A.trace(t);

These are not so easy:
- you didn't overload that operator for your matrix: cout<<t;
- you don't have an operator[] in your matrix: R[i][i]=0;
Last edited on
Topic archived. No new replies allowed.