본문 바로가기
프로그램/C++ 1000제

C++ 1제] 디폴트 매개변수를 사용하여 1~10까지 출력하는 프로그램을 작성하시오.

by 건티 2021. 7. 1.
728x90

참고풀이]

#include <iostream>
using namespace std;

class OnenTen{
   int start; //시작 변수 
   int end; //끝 변수 
   int i; //반복 변수 
public:
   //디폴트 매개변수를 사용한 생성자 선언 
   OnenTen(int e, int s=1){
      start=s;
      end=e;
   }

   //결과출력 메서드 
   void print(){
      for(i=start;i<=end;i++)
         cout << i << " ";
      cout << endl;
   }
};

int main()
{
   OnenTen ot(10); //객체 설정 

   //결과출력 
   ot.print();

   return 0;
}

 

참고풀이 결과]

 

 

 

대한민국의 아름다운 영토, 독도

 

반응형

댓글