473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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>>(istream &a,cat &b); private: int row, col,colc, *data;
friend ostream& product<<(ostream& 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>>(istream &a,cat &b); ostream& product<<(ostream& a, cat &b); cat c; c=a* b; ostream& product<<(ostream& c);

system("pause");
return 0;

}
Jan 10 '10 #1
1 1287
weaknessforcats
9,208 Expert Mod 8TB
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.
Jan 12 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Wenjie | last post by:
Hello, I read someone posted assertions that even the (public) member function is not static, there are probably only one copy of the code in the executable. Then except the...
11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
12
by: Anthony Jones | last post by:
Just a bit of background: I'm one of a group of FORTRAN programmers, looking to switch to C++. We are trying to write a few simple examples to demonstrate the power of the language to our manager,...
23
by: Timothy Madden | last post by:
Hello all. I program C++ since a lot of time now and I still don't know this simple thing: what's the problem with local functions so they are not part of C++ ? There surely are many people...
22
by: ypjofficial | last post by:
Is there any possibility of invoking the member functions of a class without creating an object (or even a pointer to ) of that class. eg. #include <iostream.h> class test { public: void...
12
by: addinall | last post by:
Hi guys and gals, Haven't been in here for a good decade or so! I'm having a braid-dead moment that is lasting for a couple of days. Declaring pointers to functions witrhin structures and...
13
by: JohnQ | last post by:
The implementation of classes with virtual functions is conceptually easy to understand: they use vtables. Which begs the question about POD structs: how are they associated with their member...
2
by: Angus | last post by:
I have a member function, int GetLogLevel() which I thought I should change to int GetLogLevel() const - I made the change and it works fine. But in the function I am creating buffers and of...
5
by: Tim Frink | last post by:
Hi, I'm experimenting with function pointers and found two questions. Let's assume this code: 1 #include <iostream> 2 class A; 3 4 //////////////////////////////////////////// 5 class B
7
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.