url : http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=289101637

 

// ConsoleApplication5.cpp: 콘솔 응용 프로그램의 진입점을 정의합니다.
//

#include "stdafx.h"
#define ARR_SIZE_R 3
#define ARR_SIZE_C 4
class Mat{
public:
 int A_RRY[ARR_SIZE_R][ARR_SIZE_C];
 int B_RRY[ARR_SIZE_R][ARR_SIZE_C];
 int sum_RRY[ARR_SIZE_R][ARR_SIZE_C];
 Mat(); // 생성자
 void summation();
};
Mat::Mat() { // 데이터 초기화
 this->A_RRY[ARR_SIZE_R][ARR_SIZE_C] = { 0, };
 this->B_RRY[ARR_SIZE_R][ARR_SIZE_C] = { 0, };
 this->sum_RRY[ARR_SIZE_R][ARR_SIZE_C] = { 0, };
}
void Mat::summation() {
 for (int R = 0; R < ARR_SIZE_R; R++) {
  for (int C = 0; C < ARR_SIZE_C; C++) {
   sum_RRY[R][C] = A_RRY[R][C] + B_RRY[R][C];
  }
 }
}
int main(void) {
 Mat* s = NULL;
 s = new Mat;
 //std::cout << "s => " << s << std::endl;
 // 값 입력
 // A 행렬
 for (int _R = 0; _R < ARR_SIZE_R; _R++) {
  //std::cout << "test" << std::endl;
  for (int _C = 0; _C < ARR_SIZE_C; _C++) {
   std::cout << "s-> A_RRY [" << _R << "][" << _C << "] =>  ";
   std::cin >> s->A_RRY[_R][_C];
  }
 }
 // B 행렬
 for (int _R = 0; _R < ARR_SIZE_R; _R++) {
  for (int _C = 0; _C < ARR_SIZE_C; _C++) {
   std::cout << "s-> B_RRY [" << _R << "][" << _C << "] =>  ";
   std::cin >> s->B_RRY[_R][_C];
  }
 }

 s->summation(); // _________________ f: summation call

 for (int _R = 0; _R < ARR_SIZE_R; _R++) {
  for (int _C = 0; _C < ARR_SIZE_C; _C++) {
   std::cout.setf(std::ios::right);
   std::cout << std::setw(3) << s->sum_RRY[_R][_C];
   if (_C == ARR_SIZE_C - 1) {
    
    std::cout << std::endl;
   }
   else {
    std::cout << "  ";
   }
  }
 }
 delete s;
 return 0;
}

 

'언어 > c++' 카테고리의 다른 글

c++, for  (0) 2017.07.08
c++, swap  (0) 2017.07.02
문자열 escape  (0) 2017.07.02
c++ , size, length  (0) 2017.07.02
c++ 문자열 파싱, substr  (0) 2017.07.02