// Object-Oriented Programming and VC ++ implementation -- liwei_2_3 (sum of row elements and diagonal lines of the matrix)
// -- Object-Oriented Programming and VC ++ implementation
// -- Liwei_2_3
// -- Calculate the sum of the row elements and diagonal lines of the matrix.
// -- 11/5/2005 sat. Morning
// -- Computer lab
# Include <iostream>
Using namespace STD;
Const int size = 2;
Void matrix1 (int * seq, int * result_p, Int & cross_p );
Void matrix2 (INT seq [size] [size], int * result_p, Int & cross_p );
Void matrix3 (INT (* SEQ) [size], int * result_p, Int & cross_p );
Int main ()
{
Int array [size] [size];
Int result [size], cross = 0; // result stores the result of adding row elements; Cross stores the result of adding diagonal elements.
Int I, J;
Cout <"Please enter numbers" <size * size <":" <Endl;
For (I = 0; I <size; I ++) // data input
{
Result [I] = 0; // remember to initialize
For (j = 0; j <size; j ++)
Cin> array [I] [J];
}
// Matrix1 (* array, result, Cross); // The row address cross is a reference parameter.
// Matrix2 (array, result, Cross); // transmits an array
Matrix3 (array, result, Cross); // transmits an array
Cout <Endl <"================================== ========== "<Endl;
For (I = 0; I <size; I ++) // data output
Cout <"row" <I <"sum is:" <result [I] <Endl ;;
Cout <Endl <"Cross sum:" <cross <Endl;
Return 0;
}
Void matrix1 (int * seq, int * result_p, Int & cross_p)
{
Int I, J;
For (I = 0; I <size; I ++)
For (j = 0; j <size; j ++)
{
Result_p [I] = result_p [I] + * (SEQ + I * size) + J );
If (I = J)
Cross_p = cross_p + * (SEQ + I * size) + J );
}
}
Void matrix2 (INT seq [size] [size], int * result_p, Int & cross_p)
{
Int I, J;
For (I = 0; I <size; I ++)
For (j = 0; j <size; j ++)
{
Result_p [I] = result_p [I] + seq [I] [J];
If (I = J)
Cross_p = cross_p + seq [I] [J];
}
}
Void matrix3 (INT (* SEQ) [size], int * result_p, Int & cross_p) // array pointer
{
Int I, J;
For (I = 0; I <size; I ++)
For (j = 0; j <size; j ++)
{
Result_p [I] = result_p [I] + * (SEQ + I) + J );
If (I = J)
Cross_p = cross_p + * (SEQ + I) + J );
}
}