solve the assignment

Write your question here.
solve the assignment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  Let’s create a class called VectorOfVectors that can stores n vectors . Whenever we instantiate an object of this class we pass as parameter the number of vectors this object will store (all one dimensional), an array containing the initial value that we want each vector to be initialized with (optional) and size of each vector (all vectors will have the same size). The following object declarations are valid:
int a[3]={10,0, 3};
     VectorOfVectors v(3, a, 10); //it stores 3 vectors, all of size 10, //with           first vector initialized to 10, //second 0 and third 3.
     VectorOfVectors v(0,10); //it stores only 1 vector of size //10 //initialized with 0.
Since we know that C++ stores multi-dimensional arrays in row major order, let’s implement our class in same way. We will have a one dimensional dynamic array as private data member of our class that will store all the vectors in row major order. Note that you cannot use 2 dimensional static or dynamic arrays here. You would also need to determine other data members that your class needs. Make sure you don’t make extra/redundant variables but only the ones that are necessary. VectorOfVectors will have the following interface at least (i.e. you might need to add other functions):
public:
bool insert(int value, int vectorNo); //inserts the value in vectorNo //mentioned
bool remove(int vectorNo, int index); //removes the value from the index //of the vector no mentioned
bool change(int vectorNo, int index, int newValue); //changes the value of the index //of the mentioned vector no.
void printAll(); //prints all values in 2D format
bool get(int vectorNo, int index, int &value); //returns the value at index in //vector No in value variable
void removefromVectors(int value); //removes the row and column //containing the value and //compacts it
removefromVectors(15) Example :
The empty cells can be filled with -1.
2 3 5  6  10 22
3 3 12 15 20 21 
6 8 10 11 30 34 
2 7 9 10 13 15



2 3 5 10 - -
6 7 10 30 - -
----
Note that each vector in the object stores non-negative integers arranged in ascending order. Whenever we need to insert an element and the required vector is out of space, we increase the size of all vectors by ½ of the original size. So in a way vectors are symmetric.
what problem are you having or do you just want someone to write this ?
1. You didn't bother to edit out the "Write your question here."
2. You wrote no more than three words.
3. You pasted a ton of badly-formatted code.

That's 3 to 0, buddy; try again.
I can't understand this. i am new in c++. and i don't know how to programme this in VS 2010. Please help me from where i learn visual c++. and how to programme this. Thanks
This should get you started.

Note that I wasn't sure about insert or remove. I couldn't tell if each vector should remain the same size, or if each vector can have a different size. The latter case is significantly more complicated.

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
class VectorOfVectors
{
public:
    VectorOfVectors(int nb_vectors, int init[], int size); // init must have nb_vectors elements
    VectorOfVectors(int nb_vectors, int size);
    ~VectorOfVectors();
private:
    int* m_data;
    int m_nbVectors;
    int m_size;

public:
    bool change(int vectorNo, int index, int newValue);    
    bool insert(int value, int vectorNo);
}


VectorOfVectors::VectorOfVectors(int nb_vectors, int init[], int size) : m_nbVectors(nb_vectors), m_size(size)
{
    m_data = new int[ nb_vectors * size ];

    for (int i = 0; i < nb_vectors; ++i)
        for (int j = 0; j < size; ++j)
	    change(i, j, init[ i ]);
}

VectorOfVectors::VectorOfVectors(int nb_vectors, int size) : m_nbVectors(nb_vectors), m_size(size)
{
    m_data = new int[ nb_vectors * size ];
    for (int i = 0; i < nb_vectors; ++i)
        for (int j = 0; j < size; ++j)
	    change(i, j, 0 );
} 

VectorOfVectors::~VectorOfVectors()
{
    delete m_data[];
}

bool VectorOfVectors::change(int vectorNo, int index, int newValue)
{
    if (vectorNo >= m_nbVectors) return false;
    if (index    >= m_size     ) return false;

    m_data[ vectorNo * m_size + index ] = newValue;
    return true;
}


Last edited on
Visual C++ supports standard C++ (Specifically, VS2010 supports C++03), so there isn't anything IDE-specific you need to learn except for how to compile.

A beginner generally starts with "Hello World", not with dynamic memory allocation so I don't buy that you have no idea how to use Visual C++.
Thank you so much Stewbond
Topic archived. No new replies allowed.