2011-05-16 5 views
0

나는 프로그램을 가져 와서 일부분을 생략했다. 아직도 의사 코드로 간주되는지 확실하지 않습니다. 여기있어.이것을 의사 코드로 변경하는 방법

#include "mbed.h" 

const int BUFFERSIZE = 1024; 
int buffer[BUFFERSIZE]; 
int UTC[10]; 
int lat[10]; 
int ns; 
int lon[10]; 
int ew; 
int posfix; 
int numsats[2]; 

Serial pc(p9, p10); 
Serial gps(p13, p14); 

int findStart(int pos) 
{ 
    for(int i = pos; i < BUFFERSIZE; i++) 
    { 
     if buffer[pos to pos+5] == “$GP” 
      return pos + 5; 
     else 
      return BUFFERSIZE; 

    } 
    return BUFFERSIZE; 

} 

bool code(int pos, char c[3]) 
{ 
    if(buffer[pos to pos + 2]==c) 
     return true; 
else 
     return false; 
    return false; 
} 

void loadVariables(int pos) 
{ 
    assign variables based on relative position to pos 
} 

void displayVariables() 
{ 
    for every variable 
     print description + value; 
} 


void parsebuffer() 
{ 
    int pos = 0; // current read position in the buffer 

    while (pos < BUFFERSIZE - 1) 
    { 
     pos = findStart(pos); 
     if(pos > BUFFERSIZE - 50) return; 

     bool codeknown = true; 
     if (found “GGA”) 
     { 

      pc.printf("Found GGA\r\n"); 
      loadVariables(pos+3); 
      displayVariables(); 
     } 
     else if (found “GLL”) 
     { 
      pc.printf("Found GLL\r\n"); 

     } 
     else 
      codeknown = false; 

     if(!codeknown) 
     print code found 
    } 
} 

int main() { 

    pc.baud(4800); 
    pc.format(8,Serial::None,1); 

    gps.baud(4800); 
    gps.format(8,Serial::None,1); 
    pc.putc(0x0c); 

    while(1) { 

     put data from GPS into array 

     parsebuffer(); 
     pc.printf("\r\npress a key to continue\r\n");  
     pc.getc(); 
    } 
} 
+0

큰 문제. –

+0

이것은 의사 코드에 대한 아이디어를 줄 수 있습니다 http://www.coderookie.com/2006/tutorial/the-pseudocode-programming-process/ –

+0

의사 코드는 다음과 같은 몇 가지 다른 것을 의미 할 수 있습니다. "코드와 같이 막연하게 보이는 코드가 있습니다. 프로그램의 의도를 분명히하지만 모든 컴파일러에서 "~"로 컴파일되지 않을 수 있습니다. 프로세스의 각 원자 부분에 대한 영어 텍스트 설명이 있습니다 (예 : '가격 배열의 모든 값을 루프하여 화면에 인쇄'). 의사 코드 란 의사 코드가 의미하는 바를 설명하고 왜 의사 코드를 원하는지 명확하게하려는 것입니다. – Chris

답변

1

의사 코드는 코드와 자연 언어 사이에 아무것도입니다. 나는 그것을 사용하는 방법에 자유를주기 위해 그렇게 엄격하게 정의되지 않는다면 더 유익하다고 주장한다. 내가 할 일에 대한 내 생각을 느슨하게하거나, 내가 어떻게하고 싶은지에 관해 생각할 때 특정 코드가 수행해야하는 작업의 짧은 버전을 만들기 위해 직접 사용합니다. 내 대답은 네가하는 일을 암기/정의하는 데 도움이된다면 그렇다.

일부 언어에서는 의사 코드에 두 개의 슬래시를 추가하여 주석 처리합니다. 앞에 코드를 추가하고 싶다면, 앞에 TODO를 추가하십시오.

//TODO make a function to compute the average height of sample. 

//for every individual 
// obtain the height, store heights in some variable. 
//compute average of all heights 
관련 문제