Holey_yan

20150521_KUAS_VisualC++_Exam10

May 21st, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. /***************************************/
  2. /** 20150521 Exam 10                  **/
  3. /** Maker  : Yan                      **/
  4. /** E-Mail : [email protected] **/
  5. /** Date   : 2015/05/21 am.11:59      **/
  6. /***************************************/
  7.  
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. #include <iomanip>
  12.  
  13. #define MaxRange 100
  14. class Matrix{
  15.     friend ostream &operator << (ostream &, const Matrix &);
  16.     friend istream &operator >> (istream &, Matrix &);
  17.  
  18. private:
  19.     int Row;
  20.     int Col;
  21.     int DataBase[MaxRange];
  22. };
  23.  
  24. ostream &operator << (ostream &output, const Matrix &Matrix){
  25.     output << Matrix.Col << "*" << Matrix.Row << endl;
  26.     for (int i = 0; i < Matrix.Row * Matrix.Col; i++){
  27.         output << setw(4) << Matrix.DataBase[i];
  28.         if ((i + 1) % Matrix.Row == 0) {output << endl;}
  29.     }
  30.     return output;
  31. }
  32.  
  33. istream &operator >> (istream &input, Matrix &Matrix){
  34.     input >> Matrix.Row;
  35.     input >> Matrix.Col;
  36.  
  37.     int inputCount = 0;
  38.     for (int i = 0; i < Matrix.Row * Matrix.Col; i++){
  39.         input >> Matrix.DataBase[inputCount++];
  40.     }
  41.     return input;
  42. }
  43.  
  44. int main(int argc, char const *argv[]){
  45.     int Counter = 0; cin >> Counter;
  46.     for (int i = 0; i < Counter; i++){
  47.         Matrix matrix;
  48.         cin >> matrix;
  49.         cout << matrix << endl;
  50.     }
  51.     exit(EXIT_SUCCESS); return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment