input: def MatrixOperations(matrix_class):
      """
      Develop a class in Python to perform various matrix operations like addition, subtraction, multiplication and transpose.
  
      Example:
      matrix_class = Matrix(2, 2, [1, 2, 3, 4])
      matrix_class.add(Matrix(2, 2, [4, 3, 2, 1]))
      print(matrix_class)  # Should print "5 5 \n5 5 \n"
      matrix_class.sub(Matrix(2, 2, [4, 3, 2, 1]))
      print(matrix_class)  # Should print "1 2 \n3 4 \n"
      matrix_class.mul(Matrix(2, 2, [2, 0, 0, 2]))
      print(matrix_class)  # Should print "2 4 \n6 8 \n"
      matrix_class.transpose()
      print(matrix_class)  # Should print "2 6 \n4 8 \n"
      """
output:     
      class Matrix:
          def __init__(self, rows, cols, data):
              self.rows = rows
              self.cols = cols
              self.data = data
  
          def add(self, other):
              if self.rows != other.rows or self.cols != other.cols:
                  raise ValueError("Matrices must have the same dimensions for addition.")
              self.data = [self.data[i] + other.data[i] for i in range(len(self.data))]
  
          def sub(self, other):
              if self.rows != other.rows or self.cols != other.cols:
                  raise ValueError("Matrices must have the same dimensions for subtraction.")
              self.data = [self.data[i] - other.data[i] for i in range(len(self.data))]
  
          def mul(self, other):
              if self.cols != other.rows:
                  raise ValueError("Number of columns in the first matrix must be equal to the number of rows in the second matrix.")
              result = []
              for i in range(self.rows):
                  for j in range(other.cols):
                      sum = 0
                      for k in range(self.cols):
                          sum += self.data[i * self.cols + k] * other.data[k * other.cols + j]
                      result.append(sum)
              self.data = result
              self.cols = other.cols
  
          def transpose(self):
              new_data = [0] * len(self.data)
              for i in range(self.rows):
                  for j in range(self.cols):
                      new_data[j * self.rows + i] = self.data[i * self.cols + j]
              self.data = new_data
              self.rows, self.cols = self.cols, self.rows
  
          def __str__(self):
              return "\n".join([" ".join(map(str, self.data[i * self.cols:(i + 1) * self.cols])) for i in range(self.rows)])
  