c data structure assignment 1

1. For this problem, you will be asked to write some code to accomplish a particular task given the code fragment below. Each task will depend on the tasks that came before it. Your code must be syntactically correct.

int i1 = 100;_x000D_
int i2 = -8;_x000D_
int i3 = 15;   _x000D_
_x000D_
int *p1, **p2, ***p3;_x000D_

a.) Set p1 to point to i1.

b.) Using p2 change the value of i1 to the value of i2 (you may not use i1).

c.) Using p3 make p1 point to i3 (you may not use p1).

2. Consider the code fragment below. It is supposed to construct a 3×4 (3 rows 4 columns) 2-level array of integers and set each value to zero. However, as given it does not. Add the proper dereferences (*) or references (&) to make this code work properly:

int rows,  col1,  col2,  col3;_x000D_
rows = new int [3]; // Create 3 pointers to columns _x000D_
col1 = new int [4]; // Create first row with 4 elements _x000D_
col2 = new int [4]; // Create second row with 4 elements _x000D_
col3 = new int [4]; // Create third row with 4 elements_x000D_
( rows+0)= col1[0]; //Pointtofirstrow _x000D_
( rows+1)= col2[0]; //Pointtosecondrow _x000D_
( rows+2)= col3[0]; //Pointtothirdrow_x000D_
( rows+0)= col1[0]; //Pointtofirstrow _x000D_
( rows+1)= col2[0]; //Pointtosecondrow _x000D_
( rows+2)= col3[0]; //Pointtothirdrow_x000D_
 for (int i = 0; i<3; i++)_x000D_
    for (int j = 0; j<4; j++)_x000D_
           ( ( rows+i)+j) = 0;   //rows[i][j]=0; 

3. For this problem, you will be asked to write some code to accomplish a particular task given the code fragment below. Each task may depend on the tasks that came before it. Your code must be syntactically correct. Note none of your operations may affect S::m_unique.

class S {_x000D_
      public:_x000D_
           S(int init, int id) :m_num(init)_x000D_
               { m_unique = new int(id);} _x000D_
           S() :m_num(0) _x000D_
               { m_unique = new int(-1);}_x000D_
           ~S()_x000D_
               { delete m_unique; }_x000D_
           ..._x000D_
           void set(int num) _x000D_
               { m_num = num;}_x000D_
           int get() _x000D_
               { return m_num; }_x000D_
      private:_x000D_
           int m_num;_x000D_
           int *m_unique;_x000D_
                              };_x000D_
_x000D_
      S d1, d2(4,2), d3(-15,3);_x000D_
      S *sp1, **sp2, ***sp3;

a) Set sp1 to point to d1.

b) Using sp2 change the value of m_num in d1 to the value of m_num in d2 (you may not use d1).

c) Using sp3 make sp1 point to d3 (you may not use sp1).

4. Referring to the object S in previous problem:

a) Implement a copy constructor for the object S. Assume this is done inside the class definition.

b) Overload the assignment operator for the object S. Assume this is done inside the class definition.

 
Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code “Newclient” for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.


Posted

in

by

Tags: