Functions and Member functions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rijaalu
    New Member
    • Jan 2010
    • 2

    Functions and Member functions

    What are required functions and member functions to enable the following program producing the correct result.(Only need to write the declarations for functions and member functions).



    #include <iostream>
    using namespace std;



    class cat { friend istream& product>>(istre am &a,cat &b); private: int row, col,colc, *data;
    friend ostream& product<<(ostre am& a, cat &b);
    public: cat() { row = col = 0; data = 0;
    }

    cat(int r, int c) {row = r; col = c; data = new int [row*col];}
    cat(cat &a ) { row=a.row; col = a.colc; data = new int [row*col];
    for (int i=0; i< row*col; i++) data[i]=a.data[i];

    }

    ~cat()

    {
    if (data !=0) delete [] data;

    }

    void showMatrix()
    {
    int w=0, j;
    for (int i = 0; i<row; i++)
    {
    for (j=0; j<col; j++)

    {
    cout<<data[w] << ' '; w++;
    }

    cout<<endl;
    }

    cout <<endl;
    } };


    cat product(cat &a, cat &b)
    {
    cat tmp( a.row, b.col);
    int s, i, j;

    for (i=0; i<a.row; i++)
    for (j=0; j<b.col; j++)
    for (tmp.data[i*b.col+j] = 0, s=0; s<a.col; s++)

    tmp.data[i*b.col+j] +=a.data[i*a.col+s]*b.data[s*b.col+j];
    return tmp;

    }

    int main() { int m, n ,k;

    cout<< "enter row no. of the matrix A: "; cin >>m;
    cout<<"enter column no. of the matrix A: "; cin >>n;
    cout<<"enter column no. of the matrix B: "; cin >>k; cat a (m, n); cat b(n, k);

    istream& product>>(istre am &a,cat &b); ostream& product<<(ostre am& a, cat &b); cat c; c=a* b; ostream& product<<(ostre am& c);

    system("pause") ;
    return 0;

    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You might try compiling the code and when the compiler says it needs a member function, you could add it to the class. You won't need to actually write the function but just get the signature in the class.

    When you have resolved all compile errors, you will have done what was required.

    The build will die in the link becuse you haven.t actually written the mmebr functions but that wasn't required abyway.

    Comment

    Working...