I had already picked up a couple other books prior to the suggested ones... one of them is an Ivor Horton book, but it's the "Beginning Visual C++ 6".. I've consulted it a little bit so far...
I had already picked up a couple other books prior to the suggested ones... one of them is an Ivor Horton book, but it's the "Beginning Visual C++ 6".. I've consulted it a little bit so far...
That default constructor seems odd to me...
Maybe something like:
thenCode:public: matrix();
then you can define other constructors if the user specifies valuesCode:matrix::matrix() { r=10; c=10; v=0; }
im not exactly sure how your method would work...if it works
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
That thought had crossed my mind, but I was under the impression that I needed to mirror the way that the default constructor looked in the .h file (which was provided by the book for this problem)?Code:matrix::matrix() { r=10; c=10; v=0; }
try changing the .h file so that the matrix constructor has no arguments ( matrix() )
edit:: oh i also mean change the cpp file to what i said before as well
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
JaWib didn't follow the thread very carefully, and he doesn't appear to understand your assignment, and anyways the constuctor is fine. Your constructor has default parameter values, so it plays a dual role. It serves as a constructor that takes three int parameters, and it also serves as a default constructor: if you call the constructor with no arguments, the default values will be used.
However, the whole issue with your constructor that you've failed to address is that a constructor is used to initialize the data members of your class. Your constructor was declared to accept three parameters of type int, yet your class doesn't have three data members of type int. So, there appears to be some kind of discrepancy.
"I had already picked up a couple other books prior to the suggested ones... one of them is an Ivor Horton book, but it's the "Beginning Visual C++ 6"
I don't know if your class is going to be covering Visual C++, and if it's not, I would exchange Beginng Visual C++ for Beginning C++, which is a more comprehensive text on C++. However, they are both good books, and I have them both. The first 12 chapters of Beginning Visual C++ is a condensed version of Beginning C++, so it's more cursory.
Last edited by 7stud; 05-23-2003 at 12:41 AM.
Visual C++ is what the course that I am taking requires us to use, so that's why I leaned towards getting the book with Visual C++ 6.0 focus. I read all of chapter 8 in that book last night (where classes are first introduced) and about 1/2 of Chapter 9. I can definitely tell the difference in quality of writing versus the required text for my course. The concepts are starting to crystalize a bit now..
Visual C++ is both a compiler and a method for Windows programming. You can study C++ and use Visual C++ as your compiler, but never get into Windows Programming with Visual C++, which involves using the Microsoft Foundation Classes(MFC) to create Windows as the means of interacting with the user of your program. For instance, a lot of people don't like MFC, and don't use it for Windows Programming--they use the Windows API directly. I think "Beginning C++" is a much better C++ reference than "Beginning Visual C++", but either one is undoubtedly much better than your current text.
Last edited by 7stud; 05-23-2003 at 03:37 PM.
I had a question regarding this statement:
"However, the whole issue with your constructor that you've failed to address is that a constructor is used to initialize the data members of your class. Your constructor was declared to accept three parameters of type int, yet your class doesn't have three data members of type int. So, there appears to be some kind of discrepancy"
The default constructor is the following:
This is the default constructor provided by the textbook for this problem, but I do see what you're saying (I think). It has three integers in it, but there are not 3 data members in the class to correlate the integers with, right? I am not sure how I am supposed to handle this if that is the case, because we are supposed to use the interface provided in the book (which is basically the matrix.h stuff that I posted before).Code:Matrix(int r=10, int c=10, int v=0);
On a good note, I did get the code to compile and display a 1 when I initialize a variable with the class Matrix.. such as:
That code displays a "1" in my console window and I am not sure why. I imagine it has something to do with my difficulties in setting up the default constructor, but I am not sure what I need to do to fix this..Code:Matrix A; cout << A.NumberRows;
Thanks!
Not really. That is a constructor that takes 0, 1, 2, or 3 arguments, but no matter how many arguments you send to the function it ALWAYS has three parameters--or values--that presumably you will do something with in the body of the constructor.The default constructor is the following:
Matrix(int r=10, int c=10, int v=0);
If you define your constructor like this:
Matrix::Matrix(int r, int c, int v){
}
then why would you declare it with any parameters? Since you aren't doing anything with the values you would declare the constructor like this:
Matrix();
and define it like this:
Matrix::Matrix()
{
}
Exactly. So, that's a big hint your definition of the constructor is totally wrong, and until you get that straightened out, there's no use proceeding. The parameters of your constructor probably have something to do with the data member:I am supposed to handle this if that is the case, because we are supposed to use the interface provided in the book
IntList *Values;
What's an IntList?
Last edited by 7stud; 05-23-2003 at 11:27 PM.
The IntList is another class that was defined earlier in the book that (I am presuming) was designed with this assignment in mind. It of course has its own .h and .cpp file for it as well, but I don't know how well it would assist matters if I were to paste that here?
Ok, here's the deal: Your constructor has three int parameters you have to do something with. And your class has these data members:
int NumRows; // Row size of matrix
IntList *Values; // pointer to rows
If you assign one of the parameters to NumRows, that leaves you with two other int parameters that need to be put to use. Values is a pointer to an IntList. So, if you create an IntList object in your constructor and assign the address to Values, then your constructor has taken care of initializing both of your data members. What I'm guessing is that to create an IntList object, you need two int parameters--which would correspond to the two remaining int parameters of your constructor. Make sense?
That does make sense... the IntList does take two ints into it so that would make perfect sense... I think that helps..
Thanks!