CS205 S22 Assignment 1
Classes | Typedefs | Functions
assign1_mat.h File Reference

Provided struct and functions for SUSTech CS205 (s22) assignment 1. More...

Go to the source code of this file.

Classes

struct  matrix
 Structure to store a matrix with integers. More...
 

Typedefs

typedef struct matrix matrix
 Structure to store a matrix with integers. More...
 

Functions

matrix create_matrix_all_zero (int row, int col)
 
void delete_matrix (matrix mat)
 
matrix copy_matrix (matrix mat)
 
void set_by_index (matrix mat, int row, int col, int val)
 
int get_by_index (matrix mat, int row, int col)
 
int scalar_multiplication (matrix mat_a, int x, matrix mat_res)
 

Detailed Description

Provided struct and functions for SUSTech CS205 (s22) assignment 1.

The functions defined in this header have been implemented, you NEED NOT modify this file, and DON'T submit this to Blackboard

Author
gdjs2
chris
Date
2022-03-01

Typedef Documentation

◆ matrix

typedef struct matrix matrix

Structure to store a matrix with integers.

In this assignment, **int**s are stored in the matrix

Function Documentation

◆ copy_matrix()

matrix copy_matrix ( matrix  mat)

Hard copy a matrix

Parameters
matthe matrix to be copied
Returns
a copy of the mat

◆ create_matrix_all_zero()

matrix create_matrix_all_zero ( int  row,
int  col 
)

Create a matrix filled with zeros

Parameters
rowthe height (row) of the matrix
colthe width (col) of the matrix
Returns
a matrix filled with zeros, size: row * col

◆ delete_matrix()

void delete_matrix ( matrix  mat)

Free the memory pointed by m_data in matrix mat You MUST destroy every matrix before the program exits properly

Parameters
matthe matrix you not longer need

◆ get_by_index()

int get_by_index ( matrix  mat,
int  row,
int  col 
)

Get the value in the entry at row and col of mat

Parameters
matthe matrix to be affected
Returns
value of mat[row, col]
Attention
if row or col is out of bounds, retval will be 0xdeadbeef

◆ scalar_multiplication()

int scalar_multiplication ( matrix  mat_a,
int  x,
matrix  mat_res 
)

Scalar multiplication of a matrix and an integer If the size of mat_res does not match the size of mat_a, DO NOT modify the data in mat_res

Parameters
mat_athe matrix
xthe constant integer
mat_resthe matrix in which the result should be stored
Returns
1 if the size of mat_res does not match the size of mat_a, 0 otherwise

◆ set_by_index()

void set_by_index ( matrix  mat,
int  row,
int  col,
int  val 
)

Set the entry at row and col of mat to the value of val

Parameters
matthe matrix to be affected
valvalue will be set to mat[row, col]
Attention
if row or col is out of bounds, no action will be taken