Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Explain how to use loops to process the data stored in a two-dimensional arra

ID: 3558674 • Letter: 1

Question

1. Explain how to use loops to process the data stored in a two-dimensional array. In your explanation, include a two-dimensional array declaration and initialization.

2. Explain the difference between a parameterized constructor and a default constructor. Provide an example class that includes both types of constructors.

3. Using a personal computer as a base model, write a C++, syntactically correct class definition demonstrating composition. In the class definition, include at least the following three items that are common to a PC: a CD drive, a hard disk drive, and a power supply. You are not required to include any constructors, destructors, or additional member functions; you are only required to list the members that directly show composition and the proper access attributes.

Explanation / Answer

1.

2 dimensional array is a collection of data elements of same data type arranged in rows and columns (that is, in two dimensions). eg. int Grid[3][5];

A 2 dimensional array is declared like : Type arrayName[numberOfRows][numberOfColumn];

In order to access each element in the above declared 2 dimensional array for loop can be used :

int row, col ;
for (row = 0; row < 3; row++)
for (col = 0; col < 5; col++)
cout << Grid[row][col];

2.

Parameterized contructor : When parameters are passed to the constructor to initialise member variables.

Default construtor : If not provided, will be supplied by the compiler automatically and it will be empty. The programmer can also write the default constructor.

Eg. :

class Box{

private:

int width; int height;

public:

Box(){

cout<< "This is default constructor";

}

Box(int a, int b){ //parameterised constructor

width = a; height = b;

}

}

3.

class PersonalComputer{

private cd;

private hd;

private power_suppy;

}