Hi, I have been asked for an exam question to implement the
constructor, copy constructor and destructor for the following class
that describes an n-by-n matrix containing n squared integer values.
(Eg. a matrix of n rows and n colums):
import <iostream.h>
class myMatrix
{
private:
int **data; //pointer to array of n pointers, which in turn
point to n
arrays that contain matrix data
int size; //size of matrix
public:
//contructor, matrix elements are initialized with defaultValue
myMatrix(int matrixSize, int defaultValue);
//copy constructor
myMatrix(const myMatrix &v);
//destructor
~myMatrix
};
I'm a bit lost on what "int **data" is. How do you actually use this to
create the constructor? I didn't even know you could declare something
like that. Hopefully someone can sort me out here??? Thanks!!! 4 2051
Once again I feel the need to defend the fact that if you read my post
you will see that I am asking about what the "int **dat" declaration
means? I am putting it in context not asking soneone to do the
question.
It is a past exam question, not a homework question and I will gain no
marks from doing it. I just want to know what to do if something
similar is asked again.
The difference between me and the 1000's of other people posting here
is that I have been honest and said that I am using the information for
a question at college.
If you don't want to help thats fine but I don't see the point in
disencouraging other people from doing so.
pat wrote: Hi, I have been asked for an exam question to implement the constructor, copy constructor and destructor for the following class that describes an n-by-n matrix containing n squared integer values. (Eg. a matrix of n rows and n colums):
import <iostream.h>
There is no keyword "import" in C++, and iostream.h is an old pre-standard
header that shouldn't be used anymore.
class myMatrix {
private: int **data; //pointer to array of n pointers, which in turn point to n arrays that contain matrix data int size; //size of matrix
public: //contructor, matrix elements are initialized with defaultValue
myMatrix(int matrixSize, int defaultValue);
//copy constructor myMatrix(const myMatrix &v);
//destructor ~myMatrix
();
};
I'm a bit lost on what "int **data" is.
This is a pointer to a pointer to int. The comment explains quite accurately
what it's used for in this case.
How do you actually use this to create the constructor?
First, dynamically allocate an array of n pointers to int. Then, for each of
them, allocate an array of n int.
I didn't even know you could declare something like that.
You can declare pointers to any type, including pointers. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: adeleinandjeremy |
last post by:
I am taking a second programming course in Java and am currently
attempting to apply what I have learned using Python instead. One
thing that is puzzling me is how to use an iterator.
I am...
|
by: Martyn Lawson |
last post by:
Hi,
I am currently working as an Analyst on a .NET Web Project using ASP.NET and
C#.NET.
I have a couple of, at least what should be, quick questions:
1. My understanding of UML says that...
|
by: Kerry Sanders |
last post by:
I am working on a project for work where I need a specialized type
converter to convert the value of a string which is edited in a grid
back to the underlying object type from the cell. The value...
|
by: markpark |
last post by:
Hi : I had the following question on a C++ test and I don't think I got
it
right and I was hoping someone could answer it. I am very new to C++
so I'm sorry if ths is not a good question. ( I...
|
by: sophie |
last post by:
Hi, I have been asked for an exam question to implement the
constructor, copy constructor and destructor for the following class
that describes an n-by-n matrix containing n squared integer...
|
by: phl |
last post by:
hi,
My question is:
1. To avoid possible memory leaks, when you use this pattern, after you
have dealth with the unmanaged resources and before you take your
object off the finalize queue,...
|
by: Abhishek Srivastava |
last post by:
Hi,
Somebody recently asked me to implement the sizeof operator, i.e. to
write a function that accepts a parameter of any type, and without
using the sizeof operator, should be able to return...
|
by: ecestd |
last post by:
I did implement the copy constructor but still have a problem with
it. It is not working. What could be wrong?
#include "QueueP.h"
#include <cassert // for assert
#include <new // for...
|
by: chromis |
last post by:
Hi,
I'm writing a contacts section for a cms on a website, I've decided to write the section in OO code. So far I have my Contacts object and a page structure I would use for a procedural site.
...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |