2011-05-16 99 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

这是一个很大的问题。 – 2011-05-16 13:11:21

+0

这可能会让你对伪代码有所了解http://www.coderookie.com/2006/tutorial/the-pseudocode-programming-process/ – 2011-05-16 13:15:16

+0

伪代码对于我来说可能意味着几种不同的东西:“这里有些代码看起来很模糊,明确了程序的意图,但不能在任何地方的任何编译器中进行编译“to”这里是过程中每个原子部分的一些英文文本描述,例如'遍历价格阵列中的所有值并将它们打印到屏幕上'“。你可能想澄清你的意思是伪代码,为什么你想要它。 – Chris 2011-05-16 13:19:16

回答

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