CPP 주민등록번호 분석기

실습과제 모음 2012. 7. 23. 15:24 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <iostream>

using namespace std;

int main()

{   

     char juminnumber[15];

     cout <<"주민등록번호입력(-없이입력하세요) : ";

     cin>>juminnumber;

     if(juminnumber[6]=='1' || juminnumber[6]=='2')

     {

           cout <<"당신의생년월일은"<<juminnumber[0]<<juminnumber[1]<<""<<juminnumber[2]<<juminnumber[3]<<""<<juminnumber[4]<<juminnumber[5]<<"일입니다"<<endl;

     }

     else

     {

           cout <<"당신의생년월일은"<<juminnumber[0]<<juminnumber[1]<<""<<juminnumber[2]<<juminnumber[3]<<""<<juminnumber[4]<<juminnumber[5]<<"일입니다"<<endl;

     }

     int temp = 0;

     temp = (juminnumber[7] - '0')*10;

     temp += juminnumber[8] - '0';

     if(temp<10)

     {

           cout<<"서울사람입니당"<<endl;

     }

     else if(9<temp && temp<14)

     {

           cout<<"부산사람입니당"<<endl;

     }

     else if(13<temp && temp<17)

     {

           cout<<"인천사람입니당"<<endl;

     }

     else if(22<temp && temp<26)

     {

           cout<<"강원도사람입니당"<<endl;

     }

     else if(24<temp && temp<48)

     {

           cout<<"충청도사람입니당"<<endl;

     }

     else if(48<temp && temp<67)

     {

           cout<<"전라도사람입니당"<<endl;

     }

     else if(66<temp && temp<99)                              

     {                                        

           cout<<"경상도사람입니당"<<endl;          

     }                                                        

     return 0; 

}                                                                   

 

 

 

'실습과제 모음' 카테고리의 다른 글

CPP 함수 cvr, cba, cbv  (0) 2012.07.24
CPP 실습과제 0724 배열, 함수  (0) 2012.07.24
CPP Chapter 03 실습  (0) 2012.07.23
CPP 0722 실습과제  (0) 2012.07.22
방학특강 C 언어 주말과제 0720~0723  (0) 2012.07.20

CPP Chapter 03 실습

실습과제 모음 2012. 7. 23. 13:21 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

1.     다음 조건을 논리 연산자를 이용해서 하나의 if 문으로 완성해보자.

if( x > 2 ) {

    if ( y > 2 ) {

        z = x + y;

        cout << "z = " << z << endl;

    }

}

else

{

    cout << "x = " << x << endl;

}

2.     아래 네모 안 코드의 의미를 적고 switch 내용을 if ~ else로 변경해보자.

#include <iostream>

using namespace std;

 

int main()

{

    int score;

    char grade;

    do {

        cout << "점수입력: ";

        cin >> score;

    } while ( score > 100 || score < 0 );

 

    switch(score/10)

    {

    case 10:

    case 9:

        grade = 'A';

        break;

    case 8:

        grade = 'B';

        break;

    case 7:

        grade = 'C';

        break;

    default:

        grade = 'F';

        break;

    }

 

    cout << "grade = " << grade << endl;

 

    return 0;

}

 

3.     다음 두 프로그램의 결과를 적고 결과가 다른 이유를 설명하라.

#include <iostream>

using namespace std;

 

int main()

{

    for ( int i = 0 ; i < 5 ; i++ )

    {

        cout << "i=" << i << endl;

        cout << "*********************" << endl;

    }

    return 0;

}

#include <iostream>

using namespace std;

 

int main()

{

    for ( int i = 0 ; i < 5 ; i++ ) 

        cout << "i=" << i << endl;

        cout << "*********************" << endl;

   

    return 0;

}

 

4.     다음 프로그램에서 continue 문을 사용해 3의 배수와 5의 배수만 출력하도록 완성하라.

#include <iostream>

using namespace std;

 

int main()

{

    int n;

    for( n = 0 ; n < 20 ; n++ )

    {

 

        // TODO:

 

 

    }

    return 0;

}

 

 

'실습과제 모음' 카테고리의 다른 글

CPP 실습과제 0724 배열, 함수  (0) 2012.07.24
CPP 주민등록번호 분석기  (0) 2012.07.23
CPP 0722 실습과제  (0) 2012.07.22
방학특강 C 언어 주말과제 0720~0723  (0) 2012.07.20
JRadioButtonTest  (0) 2012.07.18

C 달력 소스코드

Programming/C,CPP,CS 2012. 7. 23. 04:30 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <stdio.h>

#include <windows.h>   // 콘솔색상을바꾸기위해서선언

 

#define leapyear(year) ((year)%4==0 && ( (year)%100!=0 || (year)%400==0 )) //윤년판정매크로

 

// Console 글씨색상을바꾸는함수

void SetConsoleTextColor(int bgcolor , int color);

 

int main(void)

{

    int year, month=0;

    int totalday[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

    int lastyear, day, i;

    FILE * fp = fopen("output5.txt", "wt"); //output5.txt에출력하기위해오픈한다.

 

    printf("몇년의달력을출력하시겠습니까?: ");

    scanf("%d",&year);

    printf("몇월의달력을출력하시겠습니까?: ");

    scanf("%d",&month);

    if(month==2 && leapyear(year))  totalday[2]=29;

    lastyear = year-1;

    {

        day = (lastyear+(lastyear/4)-(lastyear/100)+(lastyear/400)+1)%7;

        for(i=1;i < month;i++)

        {

            day+=totalday[i];

            day%=7;

        }

        // console에출력

        printf("\n           ");

        SetConsoleTextColor(0x0 , 0xe);              // 노란색글씨로바꾼다.

        printf("%d%d\n",year,month);

        SetConsoleTextColor(0x0 , 0xc);              // 빨간색글씨로바꾼다.

        printf("\n  ");

        SetConsoleTextColor(0x0 , 0xf);              // 흰색글씨로복귀

        printf("월화수목금");

        SetConsoleTextColor(0x0 , 0x9);              // 파란색글씨로바꾼다.

        printf("  ");

        SetConsoleTextColor(0x0 , 0xf);              // 흰색글씨로복귀

 

        // 파일에출력

        fprintf(fp, "\n           %d%d\n",year,month);

        fprintf(fp, "\n  일월화수목금토");

 

        for(i=-day; i<totalday[month]; i++)

        {

            if((i+day)%7 == 0)

            {

                printf("\n");

                fprintf(fp, "\n");

            }

            if(i<0)

            {

                printf("    ");

                fprintf(fp, "    ");

            }

            else

            {

                // 토요일일경우에는파란색으로출력한다

                if( (i+day)%7 == 6)   SetConsoleTextColor(0x0 , 0x9);

                // 일요일일경우에는빨간색으로출력한다.

                if( (i+day)%7 == 0)   SetConsoleTextColor(0x0 , 0xc);printf("%4d",i+1);

                // 원래흰색글씨로복귀시킨다.

                SetConsoleTextColor(0x0 , 0xf);

                fprintf(fp, "%4d",i+1);

            }

        }

    }

    printf("\n\n");

    fprintf(fp, "\n\n");

    fclose(fp);

    return 0;

}

 

 

// Console 글씨색상을바꾸는함수

void SetConsoleTextColor(int bgcolor , int color)

{

    bgcolor &= 0xf;

    color      &= 0xf;

    SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE) , (bgcolor << 4) | color );

}

 

 

 

'Programming > C,CPP,CS' 카테고리의 다른 글

프로그래밍 경진대회 관련 사이트  (0) 2012.10.14
CPP 예외처리  (0) 2012.09.23
C언어 정렬 알고리즘 예제  (0) 2012.08.26
CPP 달력 소스코드  (0) 2012.07.21
정렬 알고리즘 정리  (0) 2012.07.20

CPP 0722 실습과제

실습과제 모음 2012. 7. 22. 13:17 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <iostream>
#include <string>
using namespace std;


class ImaginaryNumber
{
public:
 int real;
 int imag;
 ImaginaryNumber(int r, int i)
 {
  real = r;
  imag = i;
 }
 void Display()
 {
  if(imag > 0 )
  {
   cout << real << " +" << imag << " * i"<< endl;
  }
  else
  {
   cout << real << " " << imag << " * i"<< endl;
  }
 }
 ImaginaryNumber operator*(const ImaginaryNumber object)
 {
  // 계산    1
  // 계산결과 리턴 2
  ImaginaryNumber temp;
  temp.real = ?;
  temp.imag = ?;
  return temp;
 }
};
int main( )

 ImaginaryNumber iNum1 ( 3 , 2 ); // 3 + 2i
 ImaginaryNumber iNum2 ( 4 , -3 ); // 4 - 3i

 iNum1.Display(); // 3 +2 * i
 iNum2.Display(); // 4 +-3 * i

 ImaginaryNumber iNum3 = iNum1 * iNum2;

 iNum3.Display(); // 18 +-1 * i

 return 0;
}

 

'실습과제 모음' 카테고리의 다른 글

CPP 주민등록번호 분석기  (0) 2012.07.23
CPP Chapter 03 실습  (0) 2012.07.23
방학특강 C 언어 주말과제 0720~0723  (0) 2012.07.20
JRadioButtonTest  (0) 2012.07.18
JCheckBoxTest  (0) 2012.07.18

CPP 달력 소스코드

Programming/C,CPP,CS 2012. 7. 21. 10:30 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <iostream>
using namespace std;


int main()
{
 int year;
 int month;
 int totalDay = 0;
 int i = 1990;
 int dayOfWeek; // 0 : 월, 1: 화, .....
 int dayOfMonth; // 해당 달의 총 일수

 cout << "년도 입력 : " ;
 cin >> year;
 cout << "월 입력 : " ;
 cin >> month;

 for( ; i < year ; i++)
 {
  if( i % 4 == 0 && i % 100 != 0 || i % 400 == 0 )
  {
   totalDay += 366;
  }
  else
  {
   totalDay += 365;
  }
 }

 cout << year << "년 1월 1일 까지의 일수 " << totalDay << "요일 : ";

 switch( totalDay % 7 )
 {
 case 0:
  cout << "월요일" << endl;
  break;
 case 1:
  cout << "화요일" << endl;
  break;
 case 2:
  cout << "수요일" << endl;
  break;
 case 3:
  cout << "목요일" << endl;
  break;
 case 4:
  cout << "금요일" << endl;
  break;
 case 5:
  cout << "토요일" << endl;
  break;
 case 6:
  cout << "일요일" << endl;
  break;
 }

 for( i = 1; i < month ; i++ ) // 5
 {
  // 1 + 2 + 3 + 4
  switch(i)
  {
  case 1:
  case 3:
  case 5:
  case 7:
  case 8:
  case 10:
  case 12:
   totalDay += 31;
   break;
  case 4:
  case 6:
  case 9:
  case 11:
   totalDay += 30;
   break;
  case 2:
   if( (year % 4) == 0 && ( (year % 100) != 0 || (year % 400) == 0 ) )
   {
    totalDay += 29;
   }
   else
   {
    totalDay += 28;
   }
   break;
  }
 }

 cout << year << "년 "<< month<<"월 1일 까지의 일수 " << totalDay << "요일 : ";

 switch( totalDay % 7 )
 {
 case 0:
  cout << "월요일" << endl;
  break;
 case 1:
  cout << "화요일" << endl;
  break;
 case 2:
  cout << "수요일" << endl;
  break;
 case 3:
  cout << "목요일" << endl;
  break;
 case 4:
  cout << "금요일" << endl;
  break;
 case 5:
  cout << "토요일" << endl;
  break;
 case 6:
  cout << "일요일" << endl;
  break;
 } 


 switch(month)
 {
 case 1:
 case 3:
 case 5:
 case 7:
 case 8:
 case 10:
 case 12:
  dayOfMonth = 31;
  break;
 case 4:
 case 6:
 case 9:
 case 11:
  dayOfMonth = 30;
  break;
 case 2:
  if( (year % 4) == 0 && ( (year % 100) != 0 || (year % 400) == 0 ) )
  {
   dayOfMonth = 29;
  }
  else
  {
   dayOfMonth = 28;
  }
  break;
 }

 cout << year << "년 " << month << "월 달력 =====" << endl;
 cout << "월 화 수 목 금 토 일" << endl;
 cout << dayOfMonth << "일 입니다" << endl;

 

 for( i = 0 ; i < totalDay % 7 ; i++)
 {
  cout << "   " ;
 }
 for(i = 1; i <= dayOfMonth ; i ++ )
 {  
  printf("%2d ", i);

  if( totalDay % 7 == 6)
  {
   cout << endl;
  }
  totalDay++;  
 }


 cout << endl << endl;


 return 0;
}

 

'Programming > C,CPP,CS' 카테고리의 다른 글

프로그래밍 경진대회 관련 사이트  (0) 2012.10.14
CPP 예외처리  (0) 2012.09.23
C언어 정렬 알고리즘 예제  (0) 2012.08.26
C 달력 소스코드  (2) 2012.07.23
정렬 알고리즘 정리  (0) 2012.07.20