Tuesday, September 28, 2010

windows programming

windowsw.programming

wndows.programming

windows programming

windows.programming

windows.programming

Windows.Programming


windows programming c++

http://www.winprog.org/tutorial/simple_window.html

windows programming

Rand 랜덤넘버

rand


function
<cstdlib>
int rand ( void );

Generate random number

Returns a pseudo-random integral number in the range 0 to RAND_MAX.

This number is generated by an algorithm that returns a sequence of apparently non-related numbers each time it is called. This algorithm uses a seed to generate the series, which should be initialized to some distinctive value using srand.

RAND_MAX is a constant defined in <cstdlib>. Its default value may vary between implementations but it is granted to be at least 32767.

A typical way to generate pseudo-random numbers in a determined range using rand is to use the modulo of the returned value by the range span and add the initial value of the range:

( value % 100 ) is in the range 0 to 99
( value % 100 + 1 ) is in the range 1 to 100
( value % 30 + 1985 ) is in the range 1985 to 2014

Notice though that this modulo operation does not generate a truly uniformly distributed random number in the span (since in most cases lower numbers are slightly more likely), but it is generally a good approximation for short spans.

Parameters

(none)

Return Value

An integer value between 0 and RAND_MAX.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* rand example: guess the number */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main ()
{
int iSecret, iGuess;

/* initialize random seed: */
srand ( time(NULL) );

/* generate secret number: */
iSecret = rand() % 10 + 1;

do {
printf ("Guess the number (1 to 10): ");
scanf ("%d",&iGuess);
if (iSecret<iGuess) puts ("The secret number is lower");
else if (iSecret>iGuess) puts ("The secret number is higher");
} while (iSecret!=iGuess);

puts ("Congratulations!");
return 0;
}


Output:

Guess the number (1 to 10): 5
The secret number is higher
Guess the number (1 to 10): 8
The secret number is lower
Guess the number (1 to 10): 7
Congratulations!


In this example, the random seed is initialized to a value representing the second in which the program is executed (time is defined in the header <ctime>). This way to initialize the seed is generally a good enough option for most randoming needs.

cTime

C Time Library

This header file contains definitions of functions to get and manipulate date and time information.

Functions

Time manipulation


Conversion:


Macros



types


 

Add 3 number


Question : how to add 3 number with C++

void main()
{
    int num1, num2, num3;
    printf("세 개의 정수값을 입력하세요.\n");
    printf("num1 -> ");
    scanf("%d", &num1);
    printf("num2 -> ");
    scanf("%d", &num2);
    printf("num3 -> ");
    scanf("%d",&num3);
    printf("덧셈의 결과는 다음과 같습니다.\n");
    printf("%d + %d + %d= %d", num1, num2,num3, (num1 + num2 + num3));
//세가지를 더한다.
    //%d로 모양이 변한다.
}


10진수를 16진수로
16진수를 10진수로

void main()
{
    char key;
    int data;
    printf("10진수->16진수 변환 프로그램입니다.\n\n");
    printf("10진수를 16진수로 바꾸려면 a키를 누르고,\n");
    printf("16진수를 10진수로 바꾸려면 b키를 누르세요.\n");
    printf("a나 b키를 누르세요. : ");
    scanf("%c", &key);
    //입력을 &key 에 입력을 한다.
    printf("변환할 숫자를 입력하세요. : ");

    if(key == 'a') {
        scanf("%d", &data);
        printf("10진수 값 : %d --> 16진수 값 : %x\n", data, data);
    }
    else if(key == 'b') {
        scanf("%x", &data);
        printf("16진수 값 : %x --> 10진수 값 : %d\n", data, data);
    }
    else
        printf("a와 b값만을 사용해야 합니다.");
   
}



srand


functions
<cstdlib>
void srand ( unsigned int seed );

Initialize random number generator

The pseudo-random number generator is initialized using the argument passed as seed.

For every different seed value used in a call to srand, the pseudo-random number generator can be expected to generate a different succession of results in the subsequent calls to rand.
Two different initializations with the same seed, instructs the pseudo-random generator to generate the same succession of results for the subsequent calls to rand in both cases.

If seed is set to 1, the generator is reinitialized to its initial value and produces the same values as before any call to rand or srand.

In order to generate random-like numbers, srand is usually initialized to some distinctive value, like those related with the execution time. For example, the value returned by the function time (declared in header <ctime>) is different each second, which is distinctive enough for most randoming needs.

Parameters

seed
An integer value to be used as seed by the pseudo-random number generator algorithm.


Return Value

(none)

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* srand example */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main ()
{
printf ("First number: %d\n", rand() % 100);
srand ( time(NULL) );
printf ("Random number: %d\n", rand() % 100);
srand ( 1 );
printf ("Again the first number: %d\n", rand() %100);

return 0;
}


Output:

First number: 41
Random number: 13
Again the first number: 41


pointer


C++ pointer.

&variable = address

pVariable = address

*pVariable = valuje

int main(void)

{
    int a = 10;
    int*pA = &a;

    double e  = 3.14;
    double*pE = &e;

   
    printf("*pA:%d\n", *pA);
    //if I put the * infront of variable
    //it display same value of original variable
    printf("pA:%d\n",*pA);
    //value
    //this display the address of variable


    printf("&a: %d\n", &a);
    printf("pA: %d\n",pA);
    printf("*pA: %d\n",*pA);
    //this is return the valuje of
    //address

    //address  &a 주소
    //address  pA 주소
    //value *pA

    return 0;
}


Sunday, September 26, 2010

12-1 포인터란 무었인가?

포인터란 우었인가?

무었이 포인터 인가.

변수의 개념

포인터란 변수다.


포인터 와 포인터 변수.

개념.


무었을 저장하기위한 변수 인가.

메모리의 주소 값을 저장하기 위한 변수

포인터는 상수가 될수 없는가?

이정도 되는 범위에서

변수가 상수화 되는 것


변수의 정의 

A 형 포인터(ㅁ*): : A 형 변수의 주소값을 저장
포인터 선언시 사용되는 연산자

int main (void)
//메인함수 의 되돌리는 것은 정수형이 고 입력하는 것은 없이 실행만 한다.
{
int *a; //a 라는 이름의 int 형 포인터
char*b;// b 라는 이름의 char 형 포인터
double* c;// c 라는 이름의 double 형 포인터

  • 포인터 는 변수다
  • 포인터는 무엇을 저장하기 위한 변수 인가.
  • 메모리의 주소값을 저장하기 위한 변수이다.
  • 변수는데이터를 저장한다.
  • 변수가 메모리의 주소값을 저장을 하기위한 변수이다.
  • 포인터도 상황에 따라서 상수가 될수 있다.
  • 변수가 상수화 되는 과정.
프로그래밈은 말과 그림으로 이해를 한다.
눈으로 이해를 한다면, 익숙해저 있다. 위험한것.

말 로써 풀어서 이해할수 있어야 한다.


int main(void)
{
  char c = 'a';
 int n = 7;
 double d = 3.14;

 
}

8Bit: 메모리의 주소값을 8비트를 사용한다. 0000 0000

16bi

32bit: 주소값을 이용해서.

64bit :

메모리의 번지수가 많아지면 성능이 좋아진다.

2^32  = 4 Giga

주소값을 저장 변수.

8bit - 1byte
32bit -4byte.

포인터의 크기는 변해왔다.

오늘날의 시스템은 4바이트로 표현된다.

..포인터는 ...변수를 가리킨다.
..선언하는 방법

..황용하는 방법.

이라는 포인터가 무었을 가르킨다.

선언하는 방법, 활용하는 방법들.

포인터를 선언하는 방법

포인터를 활용하는 방법


무엇을 가르킬수 있는 포인터 인가?


,int *a;
// a 라는 이름의 int형 포인터


활용하는 방법


& 번지 엠퍼센트 .연산자.
* 에스트릭트연산자.

& 연산자:  변수의 주소 값 변환

* 연산자 : 포인터가 가리키는 메모리 참조.


int main(void)
{
int a = 2005;
int *pA = &a;
print("%d,",a); //직접 접근
print("%d",*pA);//간접 접근



곱셈
선언
접근

구분하는 방법

int main(void)
{
int a = 2005;
int*pA =&a;

printf("pA




12장 마지막 강의

포인터에 다양한 타입이 존재하는 이유

#include<stdio.h>

int main(void)

{

int a = 10;
int *pA = &a;
double e = 3.14;
double *pE =&e;

printf("%d%f",*pA,*pE0;
return 0;
}












http://esl.about.com/library/quiz/blgrammarquiz.htm

report format

1. Introduction 3
2. Learning Process 4
2.1. Increase Knowledge 4
2.1.1. Make a note for something 4
2.1.2. High light in a textbook 4
2.1.3. Listening something or read it, 4
2.2. Memorising and reproducing 4
2.2.1. Make a list of similar things 4
2.2.2. Say it or write it over and over; 4
2.2.3. Test yourself/by someone else test you 4
2.3. Applying 5
2.3.1. Practice applying it, initially in simple way 5
2.3.2. Looks for example 5
2.3.3. Work on project that requires this new knowledge 5
2.3.4. Use formulae to solve problems or do calculation 5
2.3.5. Practice using the knowledge in short answers or essay 5
2.4. Understading 5
2.4.1. Think about new knowledge 5
2.4.2. Consider how the new knowledge relates to what you know 5
2.4.3. Write about it in your own word to clarify it for yourself 5
2.4.4. Break it into parts and work out the part connected with each other 6
2.4.5. Talk about it 6
2.4.6. Draw a concept map or mind map or other diagram connecting it with other 6
2.5. Seeing something in a different way 6
2.5.1. Diagram connecting it with other related knowledge engage in debates 6
2.5.2. Look for ideas and information that might show it wrong or inadequate 6
2.5.3. Think actively about the implications in relation to your own experience. 6
2.6. Changing as a person 6
2.6.1. Find out about what this means for others 7
2.6.2. Consider whether this makes a difference 7
2.6.3. Look for how this changes other things you know 7
2.6.4. Change your ways of behaving / or understanding because of what you know see your self and your relationship to other differently. 7
3. Conclusion 8
4. References 9
5. 10

function in C

I understand the usage of function of C today.

I did not know that why main() is start first

and why other method() has to initialized before the main function.

after this I can see the reason.

what is the process of computer is reading when programmer wrote the code.

  • what compiler will read frist.
  • what will be wrong if programmer did not initialized the non main function.
function is important thing in the programming of C

ken choi blog dash board

http://www.blogger.com/home

Saturday, September 25, 2010

C 언어의 핵심 ! 함수

1. Introduction 3
2. Learning Process 4
2.1. Increase Knowledge 4
2.1.1. Make a note for something 4
2.1.2. High light in a textbook 4
2.1.3. Listening something or read it, 4
2.2. Memorising and reproducing 4
2.2.1. Make a list of similar things 4
2.2.2. Say it or write it over and over; 4
2.2.3. Test yourself/by someone else test you 4
2.3. Applying 5
2.3.1. Practice applying it, initially in simple way 5
2.3.2. Looks for example 5
2.3.3. Work on project that requires this new knowledge 5
2.3.4. Use formulae to solve problems or do calculation 5
2.3.5. Practice using the knowledge in short answers or essay 5
2.4. Understading 5
2.4.1. Think about new knowledge 5
2.4.2. Consider how the new knowledge relates to what you know 5
2.4.3. Write about it in your own word to clarify it for yourself 5
2.4.4. Break it into parts and work out the part connected with each other 6
2.4.5. Talk about it 6
2.4.6. Draw a concept map or mind map or other diagram connecting it with other 6
2.5. Seeing something in a different way 6
2.5.1. Diagram connecting it with other related knowledge engage in debates 6
2.5.2. Look for ideas and information that might show it wrong or inadequate 6
2.5.3. Think actively about the implications in relation to your own experience. 6
2.6. Changing as a person 6
2.6.1. Find out about what this means for others 7
2.6.2. Consider whether this makes a difference 7
2.6.3. Look for how this changes other things you know 7
2.6.4. Change your ways of behaving / or understanding because of what you know see your self and your relationship to other differently. 7
3. Conclusion 8
4. References 9
5. 10

C 언어의 핵심 ! 함수

1. Introduction 3
2. Learning Process 4
2.1. Increase Knowledge 4
2.1.1. Make a note for something 4
2.1.2. High light in a textbook 4
2.1.3. Listening something or read it, 4
2.2. Memorising and reproducing 4
2.2.1. Make a list of similar things 4
2.2.2. Say it or write it over and over; 4
2.2.3. Test yourself/by someone else test you 4
2.3. Applying 5
2.3.1. Practice applying it, initially in simple way 5
2.3.2. Looks for example 5
2.3.3. Work on project that requires this new knowledge 5
2.3.4. Use formulae to solve problems or do calculation 5
2.3.5. Practice using the knowledge in short answers or essay 5
2.4. Understading 5
2.4.1. Think about new knowledge 5
2.4.2. Consider how the new knowledge relates to what you know 5
2.4.3. Write about it in your own word to clarify it for yourself 5
2.4.4. Break it into parts and work out the part connected with each other 6
2.4.5. Talk about it 6
2.4.6. Draw a concept map or mind map or other diagram connecting it with other 6
2.5. Seeing something in a different way 6
2.5.1. Diagram connecting it with other related knowledge engage in debates 6
2.5.2. Look for ideas and information that might show it wrong or inadequate 6
2.5.3. Think actively about the implications in relation to your own experience. 6
2.6. Changing as a person 6
2.6.1. Find out about what this means for others 7
2.6.2. Consider whether this makes a difference 7
2.6.3. Look for how this changes other things you know 7
2.6.4. Change your ways of behaving / or understanding because of what you know see your self and your relationship to other differently. 7
3. Conclusion 8
4. References 9
5. 10

Report 001 WHILE LOOP

1. Introduction 3

while loop,

while loop is method that let variable move in routine.
There are three different type of while loop,
while loop is required WHILE
CONDITION, CONTENT. depend on the condition content can be repeated
as it is command


2. Learning Process 4



2.1. Increase Knowledge 4

I have listened the Video of C programming Chapter 7
Loop Section.

2.1.1. Make a note for something 4


while 기본원리 와 의미

while (반복조건)

반복내용

"반복의 조건" 이 만족되는 동안
"반복 내용"을 반복 실행하라.
while ( repeated condition)
{
repeated content
}

while( i <>
{
printf("Hello World!\n");
i++;
}

"i<10>
"printf()와 i++" 을 반복 실행하라


while( i <>


2.1.2. High light in a textbook 4


7장. 다양한 형태의 반복문
7-1 반복문이란?
반복문의 기능
특정 영역을 특정 조건이 만족하는 동안에 반복 실행하기 위한 문장
세 가지 형태의 반복문
while문에 의한 반복
do ~ while문에 의한 반복
for문에 의한 반복
7-2 while문에 의한 문장의 반복
while문의 기본 원리와 의미
예제 hello_while.c 참조
예제 nine_nine.c 참조
7-2 while문에 의한 문장의 반복
while 문의 중괄호
반복하고자 하는 영역이 둘 이상의 문장으로 구성되는 경우에 필수


무한 루프(반복)
반복의 조건으로 true가 오면 발생

7-2 while문에 의한 문장의 반복
while 문의 중첩
while문 안에 while문을 포함시킨다는 뜻
반복 구조 내에서 또 하나의 반복 구조 형성
예제 nested_while.c, two_to_nine.c 참조
7-2 while문에 의한 문장의 반복
while문의 순서도
7-3 do~while문에 의한 문장의 반복
do~while문과 while문의 차이점
do~while문은 일단 한번 실행하고 나서 조건 검사를 진행
예제 nine_nine2.c, add_end.c 참조
7-3 do~while문에 의한 문장의 반복
do~while문의 순서도
7-4 for문에 의한 문장의 반복
for문의 기본 원리와 의미
초기문, 조건문, 증감문 모두를 기본적으로 포함!
가장 많이 사용되는 반복문

for문과 while문의 비교

반복 과정의 이해
예제 add_ton.c, mean.c 참조
예제 nested_for.c, two_to_nine2.c 참조






2.1.3. Listening something or read it, 4



2.2. Memorising and reproducing 4



2.2.1. Make a list of similar things 4


for 문의 기본윈리 와 의미

-초기문, 조건문,증감문 모두를 기본적으로 포함
-가장 많이 사용되는 반복문


반복문

특정 영역

세가지 형태 반복문


while
do ~ while
for

기본 원리와 의미

while

반복조건

반복내용

while 문의 중괄호

무한루프(반복)

반복조건

True

while

중첩

반복구조

nested_while.c

do~while 과 while 의 차이점

초기문,조건문, 증감문

반복문



2.2.2. Say it or write it over and over; 4



2.2.3. Test yourself/by someone else test you 4


2.3. Applying 5


2.3.1. Practice applying it, initially in simple way 5


2.3.2. Looks for example 5






hello_while.c

nine_nine.c



while( i< i =" 0," j =" 0;" num =" 0;" j=" 0;" i =" 0;" i="0;" i="0;i<2;i++)" i =" 0;" i =" 0;">



2.3.3. Work on project that requires this new knowledge 5


2.3.4. Use formulae to solve problems or do calculation 5

WHILE ( 반복조건)
반복내용

FOR (초기문;조건문;증가문)
{
반복내용
}


2.3.5. Practice using the knowledge in short answers or essay 5


2.4. Understading 5


2.4.1. Think about new knowledge 5


2.4.2. Consider how the new knowledge relates to what you know 5

내가 코딩을 하는데 있어서 필요한 것이 포함되어 있다.ㅣ

LOOP는 PHP 코딩을 하는데 있어서, 리스트를 나타내게 하거나.

이것을 반복이 되게 나타낸다.

2.4.3. Write about it in your own word to clarify it for yourself 5

코딩을 하다 보면은 어떤것을 계속해서 반복적으로 나타내야 하는경우가 있다.

이런 반복을 컴퓨터가 제어를 하게 만드는것이 루틴,루프이다.

이것에는 3가지 종류가 있는데. 이것을 이해하려면 이것에 대한 구조를 알아야 한다.
초기문, 조건문, 증가문 을 파악할수 있다면, FOR LOOP 와 WHILE LOOP를 구분할수가 있다.
그리고, 두가지 다른 방식을 이해할수 있다.


2.4.4. Break it into parts and work out the part connected with each other 6


2.4.5. Talk about it 6


2.4.6. Draw a concept map or mind map or other diagram connecting it with other 6


2.5. Seeing something in a different way 6

만족이 되는것을 반복해서 계속해서 한다. 만약에 참인경우에.
어느순간에 참이 되는조건을 어긋낼때에는 그것이더이상 되지 않는다.




2.5.1. Diagram connecting it with other related knowledge engage in debates 6



2.5.2. Look for ideas and information that might show it wrong or inadequate 6


2.5.3. Think actively about the implications in relation to your own experience. 6




2.6. Changing as a person 6


2.6.1. Find out about what this means for others 7

This is useful for other programming and it will be useful creating the routine programming.

2.6.2. Consider whether this makes a difference 7

Loop While make me to help write essential programming code.

2.6.3. Look for how this changes other things you know 7



2.6.4. Change your ways of behaving / or understanding because of what you know see your self and your relationship to other differently. 7


wikipedia, PHP code souorce may have lots of for , while, do while routine programming
code. It may think to me understand the how they written by routine system.

3. Conclusion 8


I understand the concept and usage of the LOOP in C programming

I can used this technique in C, C++, JAVA, Javascript, PHP, action script.



4. References 9

열혈강의 C programming Ch 7




5. 10

배움의 즐거움

1. Introduction 3
2. Learning Process 4
2.1. Increase Knowledge 4
2.1.1. Make a note for something 4
2.1.2. High light in a textbook 4
2.1.3. Listening something or read it, 4
2.2. Memorising and reproducing 4
2.2.1. Make a list of similar things 4
2.2.2. Say it or write it over and over; 4
2.2.3. Test yourself/by someone else test you 4
2.3. Applying 5
2.3.1. Practice applying it, initially in simple way 5
2.3.2. Looks for example 5
2.3.3. Work on project that requires this new knowledge 5
2.3.4. Use formulae to solve problems or do calculation 5
2.3.5. Practice using the knowledge in short answers or essay 5
2.4. Understading 5
2.4.1. Think about new knowledge 5
2.4.2. Consider how the new knowledge relates to what you know 5
2.4.3. Write about it in your own word to clarify it for yourself 5
2.4.4. Break it into parts and work out the part connected with each other 6
2.4.5. Talk about it 6
2.4.6. Draw a concept map or mind map or other diagram connecting it with other 6
2.5. Seeing something in a different way 6
2.5.1. Diagram connecting it with other related knowledge engage in debates 6
2.5.2. Look for ideas and information that might show it wrong or inadequate 6
2.5.3. Think actively about the implications in relation to your own experience. 6
2.6. Changing as a person 6
2.6.1. Find out about what this means for others 7
2.6.2. Consider whether this makes a difference 7
2.6.3. Look for how this changes other things you know 7
2.6.4. Change your ways of behaving / or understanding because of what you know see your self and your relationship to other differently. 7
3. Conclusion 8
4. References 9
5. 10

Friday, September 24, 2010

BASIC CODE 009; WHILE LOOP


BASIC CODE 009: WHILE LOOP

while 기본원리 와 의미

while (반복조건)

반복내용

"반복의 조건" 이 만족되는 동안
"반복 내용"을 반복 실행하라.

while ( repeated condition)
{
repeated content
}

while( i <>
{
printf("Hello World!\n");
i++;
}

"i<10>
"printf()와 i++" 을 반복 실행하라


while( i < 10 )
{
printf("Hello World!\n");
i++;
}


Wednesday, September 22, 2010

Game Code. Tetris. 001

Tetris


#include

#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
#define ESC 20
#define BX 5
#define BY 1
#define BW 10
#define BH 20

void DrawScreen();
void DrawBoard()
BOOL DrawBoard()

void DrawScreen();
void DrawBoard();
BOOL ProcessKey();
void PrintBrick(BOOL Show);
int GetAround(int x, int y,int b,int r);
BOOL MoveDown();
void TestFull();

Struct Point {
int x,y;
};

Poinjt Shape[][4][4]={
{{0,0,1,0,2,0,-1,0},{0,0,0,1,0,-1,0,-2},{0,0,1,0,2,0,-1,,0},{0,0,0,1,0,-1,0,-2},

}

enum{EMPTY,BRICK,WAll};
char*arTile[]={",","■","□"};
int board[BW+2][BH=2];
int nx,ny;
int brick,rot;

void main()
{
int nFrame, nStay;
int x,y;

setcursortype(NOCURSOR);
randomize();
cirscr();
for(x=0;x board[x][y] = (y ==0|| y ==BH+1||x ==0 || x== BW+1) ? WALL:EMPTY;
}

}

DrawScreen();
nFrame =20;

for(;1;) {
brick = random(sizeof(Shape)/sizeof(Shape[0]));
nx = BW/2;
ny = 3;
rot = 0;
PrintBrick(TRUE);

if(GetAround(nx,ny,brick,rot) != EMPTY)break;
nStay = nFrame;
for(;2;){
if (--nStay ==0){
nStay = nFrame;
if(MoveDown())break;
}
if(ProcessKey()) break;
delay(1000/20);
}
}
cirscr();
gotoxy(30,12);put("G A M E O V E R");
setcursortype(NORMAL CURSOR);
}

void DrawScreen()

{
int x, y;
for(x = 0; x gotoxy(BX+x+2,BY=y);
puts(arTile[board[x][y]]);
}
}
gotoxy(50,3);puts("Tetris Ver 1.0");
gotoxy(50,5);puts("left; move, up; rotate, below; down");
gotoxy(50,6);puts("blank:down complete");

}

void DrawBoard()
{
int x y;

for (x =1; x for (y =1; y gotoxy(BX+x+2,BY+y);
puts(arTile[board[x][y]]);

}
}
}

BOOL ProcessKey()
{
int ch,trot;

if(kbhit()){
ch=getch();
if(ch ==0xE01 || ch == 0){
ch = getch();
switch (ch){
case LEFT:
if(GetAround(nx-1,ny,brickm,rot)==EmPTY){

PrintBrick(FALSE);

nx--;
break;
case RIGHT:
if(GetAround(nx+1,ny,brick,rot)==EMPTY){
PrintBrick(FALSE);
nx++;
PrintBrick(TRUE);
}
break;
case UP:
trot=(rot ==3 ? 0:rot+1);
if(GetAround(nx,ny,brick,trot) == EMPTY){
PrintBrick(FALSE);
rot = trot;
PrintBrick(TRUE);
}

break;
case DOWN:

if(MoveDown()){
return TRUE;
}
breaK;
}
}else{
switch(ch){
case'':
while(MoveDown() === FALSE){;}
return TRUE;
}
}
}

return FALSE;
}

void PrintBrick(BOOL Show)
{

int i;

for(i=0; i<4; i++){
gotoxy(BX+(Shape[brick][rot][i].x+nx)*2.BY+Shape[brick][rot][i],y+ny);
put(arTile[Show? BRICK:EMPTY]);
}
}

int GetAround(int x, int y, int b,int r)
{

int GetAround(int x, int y, int b, int r)
{
int i,k =EMPTY;

for (i=0; i<4; i++){

k = max(k,board[x+Shape[b][r][i],x][y+Shape[b][r][i],y]);
}
return k;
}


BOOL MoveDown{}

{
if(GetAround(nx,ny+1,brick,rot) != EMPTY){
TestFull();
return TRUE;
}
PrintBrick(FALSE);
ny++;
PrintBrick(TRUE);
return FALSE;
}


void TestFull()
{
int i,x,ty;

for (i =0; i<4;i++){
board[nx+Shape[brick][rot][i],x][ny+Shape[brick][rot][i],y]=BRICK;

}

for (y =1,y for(x =1; x if(board[x][y]!= BRICK)break;
}
if(x ==BW+1){
for(ty =y; ty>1; ty--) {
for (x=1; x board[x][ty]=board[x][ty-1]
}
}
DrawBoard();
delay(200);
}
}

}


* programming 파악하는 팁

1)전역변수의 역활을 파악한다
2)함수의 구조 분석
3)프로그램 선두에 매크로들이 정의 되어 있다.(left,right)
4)BX,BY ,매크로 는 게임판의 좌상단 이다.
5),BW,BH 는 게임판의 폭과 높이 이다



BW




BH


소스 곳곳에서 이 매크로들을 참조하여 출력위치를 결정한다.

만약 위치난 크기를 바꾸고 싶다면 이 매크로의 값을 변경하면 된다.


#define define 으로 매크로 상수를각각 정의하는것과 기능적으로
동일하지만 중복되지 않는 일련의 값이므로 열거 멤버로 선언하는것이

더 좋다.



arTile 배열은 공간, 벽돌, 벽의 모양을 정의하는 크기 3의 문자열

배열, 각 타일은 2개의 문자로 구성.


7가지 함수

DrawScreen
DrawBoard
Processkey
PrintBrick
GetAround
MoveDown
TestFull

C++ Basic Code "find the random number" 008

#include
void main()
{int num;int input;
randomize();
for(;;){
num= random(100)+1; print ("\what is the number that I created.\n"); do{ printf("please enter the number(end with 999):"); scanf("%d",&input); if(input =999){ exit(0); }
if(input ==num){ printf("this is correct,\n"); } else if(input>num){ printf("this is smaller than what you input.\n"; }ele{ printf("please enter the number that greater than.\n"); } } while(input!=num); }}

Reference 001 Book for programming 3

TEXTS AND SUPPORTING MATERIALS
Recommended references include:
· C++ Programming - Program Design Including Data Structures, D.S.Malik (2009),
Thomson, ISBN 1-4239-0222-X
· Programming in Objective-C 2.0, Stephen Kochan (2009), Addison-Wesley, ISBN 0-
321-56615-7
· Objective-C Pocket Reference, A. Duncan (2002), O’Reilly, ISBN 0-596-00423-0
· Cocoa: Programming for OS X, A. Hillegass, (2004), Addison Wesley, ISBN 0-321-
21314-9
· Data Structures and Algorithm in C++, Michael T Goodrich et al, (2004), John Wiley &
Sons, ISBN 0-471-42924-4
· Data Structures and Program Design in C++, Robert L Kruse & Alexander J Ryba,
(1999), Prentice Hall, ISBN 0-13-768995-0
· Data Structures and Algorithms in Java, Adam Drozdek, USA 2001, Brooks/Cole, ISBN
0-534-37668-1
· A Framework for Program Design and Data Structures, 2nd edition, K. A. Lambert and
M. Osborne, Brooks/Cole, Canada 2004, ISBN 0-534-339285-7
Other reference and support material will be listed on the course web site (accessible through

Sunday, September 19, 2010

note 002

One of the classic examples of using recursion is calculating a factorial of a number. Here's a typical implementation of this function:


int factorial (int num)
{
if (num==1)
return 1;
return factorial(num-1)*num; // recursive call
}

factorial() calls itself recursively, subtracting 1 from num on each call, until it equals 1. As always, you can use iteration instead of recursion:


int factorial (int num)
{
int result=1;
for (int i=1; i<=num; ++i)
result=result*=i;
return result;
}

Combat.003+1.Factorial.Souce






#include stdio.h
#include iostream

using namespace std;


int factorial(int);

void main(void) {
int number;

cout << "Please enter a positive integer: ";
cin >> number;
if (number < 0)
cout << "That is not a positive integer.\n";
else
cout << number << " factorial is: " << factorial(number) << endl;
}

int factorial(int number) {
int temp;

if(number <= 1) return 1;

temp = number * factorial(number - 1);
return temp;
}

Note 001 Recursive

#include
int fibonacci(int n);
int factorial(int n);

int main()
{
int num, result;
while(1){
printf("0ÀÌ»ó ¼ýÀÚ¸¦ ÀÔ·ÂÇϼ¼¿ä. (0:Á¾·á): ");
scanf("%d", &num);
// ÇǺ¸³ªÄ¡ ÇÔ¼ö È£Ãâ
result = fibonacci(num);
printf("Fibonacci(%d) = %d\n", num, result);
// ÆÑÅ丮¾ó ÇÔ¼ö È£Ãâ
result = factorial(num);
printf("Factorial(%d) = %d\n\n", num, result);
// numÀÌ 0À̸é Á¾·áÇÑ´Ù.
if(num==0)
break;
}
return 0;
}

// ÇǺ¸³ªÄ¡ ÇÔ¼ö
int fibonacci(int n)
{
int result;
// Á¤ÀÇ¿¡ ÀÇÇÏ¿© nÀÌ 0À̸é 0À», 1À̸é 1À» ¹ÝȯÇÑ´Ù.
if(n==0)
result=0;
else if(n==1)
result=1;
// nÀÌ 1º¸´Ù Å« °æ¿ì¿¡´Â
// ¹Ù·Î ¾ÕÀÇ µÎ ¼ö¸¦ ´õÇÑ °ªÀ» ¹ÝȯÇÑ´Ù.
// ¹Ù·Î ¾ÕÀÇ µÎ ¼ö ¶ÇÇÑ ÇǺ¸³ªÄ¡ ¼ö¿­ÀÇ ¼ö À̹ǷÎ
// Àç±Í·Î È£ÃâÇÑ´Ù.
else
result=(fibonacci(n-2)+fibonacci(n-1));
return result;
}

// ÆÑÅ丮¾ó ÇÔ¼ö
int factorial(int n)
{
int result;
// Á¤ÀÇ¿¡ ÀÇÇÏ¿© nÀÌ 0 ¶Ç´Â 1À̸é 1À» ¹ÝȯÇÑ´Ù.
if(n==0 || n==1)
result=1;
// nÀÌ 1º¸´Ù Å« °æ¿ì¿¡´Â
// ¹Ù·Î ¾ÕÀÇ ¼ö¿Í nÀ» °öÇÏ¿© ¹ÝȯÇÑ´Ù.
// ¹Ù·Î ¾ÕÀÇ ¼ö ¶ÇÇÑ ÆÑÅ丮¾óÀÇ °á°ú À̹ǷÎ
// Àç±Í·Î È£ÃâÇÑ´Ù.
else
result=n * factorial(n-1);
return result;
}



http://kr.blog.gugi.yahoo.com/duduzoa/folder/9.html



int factorial(int n)
{
if(n <= 1) return 1; // 1 ÀÎ °æ¿ì 1À» ¸®ÅÏÇÏ¿© ´äÀ¸·Î ÁØ´Ù.
else return ( n*factorial(n-1)); // 1 ÀÌ»óÀÎ °æ¿ì ¼ýÀÚ¸¦ Çϳª ³·Ã߾ ´Ù½Ã factorialÇÔ¼ö¸¦ ºÎ¸¥´Ù.
}
void main()
{
int n;
scanf("%d", &n); // ¿øÇÏ´Â ¼ýÀÚ¸¦ ¹Þ¾Æ n¿¡ ÀúÀåÇÑ´Ù.
printf("%dÀÇ ÆÑÅ丮¾ó°ªÀº" , factorial(n)); // factorialÇÔ¼ö¸¦ ºÎ¸¥´Ù.
}
Ãßõ(0) ½ºÅ©·¦ (0) Àμâ






http://ask.nate.com/knote/view.html?num=19874


³×ÀÌÆ® Áö½Ä¿¡¼­ ³ª¿Â. C/C++



¾Æ·¡ÀÇ ÇÁ·Î±×·¥Àº °ø°£º¹Àâµµ(SC: Space Complexity) ¸é¿¡¼­
Àç±Í(Recursive) ¾Ë°í¸®Áòº¸´Ù ¿ì¼öÇÑ ¹Ýº¹(Iterative)¾Ë°í¸®ÁòÀ»
»ç¿ëÇÏ¿© ÆÑÅ丮¾ó °è»êÀ» ±¸ÇöÇÑ ¼Ò½ºÀÔ´Ï´Ù.

13! ÀÌ»óÀÇ °ªÀº 4¹ÙÀÌÆ® Á¤¼ö ÀÚ·áÇü(int)¿¡ ÀúÀåÀÌ ºÒ°¡´ÉÇÒ Á¤µµ·Î
Å«¼ö°¡ µÇ´Âµ¥, À̶§¿¡´Â 0¿µÀ¸·Î È­¸é Ç¥½ÃÇϵµ·Ï ¹æ¾î ÇÁ·Î±×·¡¹ÖÀÌ
±¸ÇöµÇ¾î ÀÖ½À´Ï´Ù.


//----------------------------------//
// *** ÆÑÅ丮¾ó °è»ê ÇÁ·Î±×·¥ *** //
// "Factorial.cpp" //
// ... Using Visual C++ 6.0 ... //
// ------------------------------ //
// ÆÑÅ丮¾ó °è»êÀ» ¹Ýº¹ °è»ê //
// ¾Ë°í¸®ÁòÀ¸·Î ±¸ÇöÇÑ Pgm ÀÔ´Ï´Ù //
//----------------------------------//

//////////////////////////////////////
// ¼±Çàó¸® Áö½ÃÀÚ
#include // printf(), scanf(), gets()
#include // atoi()
#include // getch()


//////////////////////////////////////
// »ç¿ëÀÚ Á¤ÀÇ ÀÚ·áÇü ¼±¾ðºÎ
typedef unsigned int UINT;


//////////////////////////////////////
// Àü¿ªº¯¼ö ¼±¾ðºÎ
UINT InputValue, // »ç¿ëÀÚ°¡ ÀÔ·ÂÇÑ Á¤¼ö ÀúÀå
OutputValue=1; // ó¸® °á°ú ÀúÀå


//////////////////////////////////////
// ÇÔ¼ö ¼±¾ðºÎ
void Input(void); // »ç¿ëÀÚÀÇ ÀÔ·ÂÀ» ó¸®ÇÏ´Â ÇÔ¼ö
void Factorial(UINT); // ÆÑÅ丮¾óÀ» °è»êÇÏ´Â ÇÔ¼ö
void Output(void); // °è»êµÈ °á°ú¸¦ Ãâ·ÂÇÏ´Â ÇÔ¼ö


//////////////////////////////////////
// ÇÔ¼ö Á¤ÀǺÎ
void Input(void)
{
// »ç¿ëÀÚÀÇ ÀԷ ó¸®
char InputStr[3];
printf("\n\n\t\t ÆÑÅ丮¾ó °è»êÇÒ Á¤¼ö¸¦ ÀÔ·ÂÇϽÿÀ : ");
gets(InputStr); // ÀÔ·Â Á¤¼ö¸¦ ¹®ÀÚ¿­·Î ÀԷ¹ޱâ
InputValue = atoi(InputStr); // ¹®ÀÚ¿­À» Á¤¼ö·Î º¯°æÇϱâ

// ¹æ¾î ÇÁ·Î±×·¡¹Ö
while (InputValue < 1)
printf("\n\t\t ÀÔ·Â ¿À·ù !!! ÀÚ¿¬¼ö¸¦ ÀÔ·ÂÇϽÿÀ : "),
gets(InputStr),
InputValue = atoi(InputStr);
}

void Factorial(UINT n)
{
// ¹æ¾î ÇÁ·Î±×·¡¹Ö
if (InputValue == 1) return;

if (InputValue > 12) // 13! ºÎÅÍ´Â Á¤¼öÇü ÀÚ·á¿¡ ÀúÀå ºÒ°¡
{
OutputValue = 0;
return;
}

// ¹Ýº¹ °è»ê ¾Ë°í¸®ÁòÀ» ÀÌ¿ëÇÑ °è»ê
for (UINT i=2; iOutputValue *= i;
}

void Output(void)
{
// °è»ê °á°ú Ãâ·Â
printf("\n\n\t\t °è»ê °á°ú : %d! = %d", InputValue, OutputValue);

// »ç¿ëÀÚÀÇ È®ÀÎ
printf("\n\n\n\t\t Press Any Key To Exit ...");
getch();
}


//////////////////////////////////////
// ¸ÞÀÎÇÔ¼ö Á¤ÀǺÎ
void main(void)
{
Input();
Factorial(InputValue);
Output();
}





#include
main()
{

int limit;
int factorial;
int i;

printf("\n±¸ÇϰíÀÚ ÇÏ´Â factorial (ÀÔ·Âex:1~10) : ");
scanf("%d",&limit);
factorial = 0;
for (i=limit;i>=1;i--){

factorial = factorial * i;

}

printf("%d! = %ld\n",limit, factorial);
return 0;
}



ÀÚ ^^ ÀÏ´Ü Àú·¸°Ô Å«°Ç Çʿ䰡 ¾ø°í¿ä..

¿ø·¡ ÆÑÅ丮¾óÀÌ

10! À̶ó¸é 10x9x8x7x6x5x4x3x2x1 À̱⠶§¹®¿¡

±ò²ûÇÏ°Ô for¹®ÀÌ ^^

±×¸®°í Ãâ·Â¹®ÀÌ ¿©·¯°³ ³ª¿À´Â°Ç whil¹® ¾ÈÂÊ¿¡ ½è±â ‹š¹®ÀÔ´Ï´Ù ^^

±×¸®°í int Çüµµ ºñÁÖ¾ó C++¿¡¼­´Â ¸Þ¸ð¸®¿¡¼­ Å©°Ô ÀâÈ÷±â ¶§¹®¿¡.. ¾Æ¸¶ 9ÀÚ¸®Àΰ¡ 11ÀÚ¸®Àΰ¡±îÁö Áö¿øµÉ²®´Ï´Ù..

±×·¯¹Ç·Î unsigned long ±îÁö´Â ¾È°¡µµ µË´Ï´Ù ^^

µ¥ÀÌÅͰ¡ 10¹Û¿¡ ¾ÈµÇÀÚ³ª¿ä ^^;;







//1¿¡¼­ 10»çÀÌÀÇ ¾çÀÇ Á¤¼ö(n)À» ÀÔ·Â¹Þ¾Æ n!(factorial)À» ±¸ÇÏ´Â ÇÁ·Î±×·¥À»
//ÀÛ¼ºÇÏ´Â °ÍÀÔ´Ï´Ù.(Á¶°ÇÀº for,while,do~while¹®À» ÀÌ¿ë)

#include
main()
{
unsigned long limit ;
unsigned long factorial = 1;
int i;

printf("\n±¸ÇϰíÀÚ ÇÏ´Â factorial (ÀÔ·Âex:1~10) : ");
scanf("%d",&limit);

i = 1;
while (i<=limit)
{
factorial *= i;
printf("%d! = %ld\n",limit, factorial);
}

return 0;
}

Á¦ÀÏ ³­°¨ÇѰԿä ÇϳªÀÇ Á¤¼ö¸¦ ÀÔ·Â ¹Þ¾Æ¼­ ±× °ª¿¡ ÇØ´çµÇ´Â ÆÑÅ丮¾ó °ªÀÌ ³ª¿À°Ô Çϴ°ǵ¥ ¾î¶»°Ô ÇØ¾ß µÉÁö ¤Ñ¤Ñ ³Ñ º¹ÀâÇÕ´Ï´Ù



ÆÑÅ丮¾ó °è½Â À̶õ?

ÆÑÅ丮¾ó À» »ç¿ëÇÏ¸é ´õ Å« ÀÚ¸®ÀÇ °á°ú°ªÀ» ³ªÅ¸³¾¼ö ÀÖ´Ù.





#include
#include
using namespace std;

int main()
{
vector* vecData = new vector;

int length = 40000; // °á°ú°ªÀÇ ÀÚ¸®¼ö

vecData->reserve(length);
vecData->assign(length, -1);
int n = 1000;
int carry = 0;

(*vecData)[0] = 1;
int offset = 1;
for(int i=2;i <= n;i++){
for(int j=0;j < offset;j++){
(*vecData)[j] = (*vecData)[j] * i + carry;
carry = 0;
if((*vecData)[j] > 9){
if((*vecData)[j+1] == -1){
offset++;
(*vecData)[j+1] = 0;
}
carry = (*vecData)[j] / 10;
(*vecData)[j] = (*vecData)[j] % 10;
}
}
}

for(int i=0;i < offset;i++){
cout << (*vecData)[offset-i-1];
}

delete vecData;
return 0;
}




///////////////////////////////////////////////////////////////////////////



Source Code

#include

int factorial(int);

void main(void) {
int number;

cout << "Please enter a positive integer: ";
cin >> number;
if (number < 0)
cout << "That is not a positive integer.\n";
else
cout << number << " factorial is: " << factorial(number) << endl;
}

int factorial(int number) {
int temp;

if(number <= 1) return 1;

temp = number * factorial(number - 1);
return temp;
}
////////////////////////////////////////////////////////////////////////////////////


http://groups.engin.umd.umich.edu/CIS/course.des/cis400/cpp/factorial.html


http://groups.engin.umd.umich.edu/CIS/course.des/cis400/cpp/factorial.html


Reference:

http://en.wikipedia.org/wiki/Recursion_(computer_science)



Mastering recursive programming



http://www.ibm.com/developerworks/linux/library/l-recurs.html

Organizaing

http://www.bfoit.org/itp/Recursion.html

http://www.cprogramming.com/tutorial/lesson16.html



would it be possible to use the recursive programming with action script

java script.

C++

C

PHP

Combat.003 - Initialisation of Variable






//initialization of variables
#include stdio.h
#include iostream
using namespace std;

int main()

{
int a = 5; //initial value = 5;
int b = 2; //initial value is 2
int result; //initial value undetermined

a = a+3;
result = a- b;
cout << "This is the answer we are looking for\n";
cout <<"\n";
cout <<"\n";
cout <<"\n";
cout<< result;
cout <<" thanks\n";
cout <<"\n";
cout <<"\n";
return 0;
}

Combat 002 - Triangle


Combat.001



007 hello world - perpect code

#include // include the standard input/output header file
int main() // our program starts here
{
printf("Hello World!"); // print "Hello World!" into the console
return 0;
}

Saturday, September 18, 2010

006 Initialization of variable

//initialization of variables
#include using namespace std;

int main()

{
int a = 5; //initial value = 5;
int b = 2; //initial value is 2
int result; //initial value undetermined

a = a+3;
result = a- b;
cout << "This is the answer we are looking for\n";
cout <<"\n";
cout <<"\n";
cout <<"\n";
cout<< result;
cout <<" thanks\n";
cout <<"\n";
cout <<"\n";
return 0;
}

List -Basic Code

001 printf 김탁구 구마준

002 namespace cout

003 namespace std cout

004 drawing traingle for loop x 2

005 cout "I am a C++ Programmer","Hello"

update will be post at comment box below

BASiC CODE 005: printf C++

/*my second program in C++
with more comments*/

#include
using namespace std;

int main()
{
cout<<"Hello World\n";
//Print Hello World
cout<<"I am a C++ Program\n";
//print I am a C++ program
//return 0;
}

C++ source Code .drawing traingle

purpose:

1) creating project
2) write script
3) compile
4) get used with ide, source editor

Next

변수
연산자

#include



void main()

{

int i,j;



for (i=1;i<=15;i=i+1) {

for (j=0;j
printf("*");

}

printf("\n");

}

}
함수의 이름:

eg. void main()

함수안의 명령
command inside of function;

eg: printf("korean\n"0;


print 함수를 쓰겠다는 선언

eg. #include

프로그래밍의 시작점

eg. void main()


natural 명령어
"문자열을 출력하라."

C++ Baisc Code 003 cout

/*this is a simple c++program
call this file sample.cpp
This is show how to use the namespace
*/
#include
using namespace std;

//A c++ program begins at main().
int main()
{
cout<<"C++ is power programming.";

return 0;
}

C++ Basic Code 002

//this is a simple c++ program.
//call this file samle.cpp


#include
using namespace std;

//A c++ program begins at main().
int main()
{
cout<<"C++ is power programming";
return 0;
}

Basic; difference b/w void and int

when void and int is used for the return type

for the main programming,

it does not come out so differently

C++ Basic Source Code 001

#include
//code 2

void main(void)
{
printf(" C programming is fun to do\n");
printf("김탁구\n");
printf("구마준\n");
printf("유경\n");
printf("팔봉 빵집\n");
}

Function structure basic

//header file
//return data type
//function name
//input data type
//start function
//function content
//end function


#include

int main(void)
{
printf("this is my life" );
return 0;
}

C++ practice

1) F7 compile
2) Ctrl + F5 Exectute


Remember the sequence of the order

F7 is comes first,

Friday, September 17, 2010

Lesson.1 Hello C

This is review of the C programming study that I have learned from university.

I have been learned C++ programming to create the 3D video console game in 2010.

It is time for me to refresh the idea of C++ and achieve dept of understanding.

my goal is find my self actualisation to develop my potential, talent in programming.


/*Hello.c*/


#include

int main(void)

{
printf("Hello, world!\n");
return 0;
}


*key point to use the visual studio express 2008 is

how to execute
how to compile

compile -> F7
excute -> Ctrl + F5

*creating project in empty

visual C++ -> win32-> win32 console application

workspace is box to contain the project

*creating the source code

click Source file folder-> (add) file -> source code.

if extension is saved with .c then it is saved as C programming.

cpp will saved as C++

Introduction
Example Code
short cut key
creating in VC



short cut key

Ctrl + F5

F7

required action by user

execute

compile