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

Remember \"The Matrix\" movie where the machines \"grow\" humans to provide a so

ID: 3808965 • Letter: R

Question

Remember "The Matrix" movie where the machines "grow" humans to provide a source of power? Assuming that the two classes, a Matrix and a Human Cell, have been already defined, write code to implement a friend overloaded output operator for the Matrix class, which will output the Matrix instance's "name ", followed by the list of Human Cells plugged in. The Matrix holds a handle to a dynamic rectangle array of Human Cells called "battery The attributes "rows " and "columns" hold the size of the rectangle matrix, in terms of Human Cells. Assume that the Cell lot is full - there is a Human plugged in every spot Assume that the output operator for a Human Cell class has been provided, and that it outputs a Human's name and age, an needed for the report Matrix Name: Blue Lagoon Cell [1][1]: Andy, 22 Cell [1][2]: Anna, 18

Explanation / Answer

//Assuming the basic class details, since its not provided.

class Matrix
{
   string name;
   HumanCell **cells; //[row][col]
   public:
   int row,col;
   friend Matrix operator<<(Matrix m);
   string getName()
   {
       return name;
   }

}
//friend output operator overload function
Matrix operator<<(Matrix m)
{

//print matrix name
   cout<<"Matrix name: "<<m.getName();
//print the details of each cell

for(int i=0; i<row; i++)
   {
       for (int j =0; j< col; j++)
       {
           cout<<"Cell["<<i<<"]["<<j<<"]: ";
           cout<<m.cells[i][j];//Calling the overload operator of output function of HumanCell class
           cout<<" ";
       }
   }
}