Let us learn C in Code pseudocode

Hi, everyone, this chapter just shows a very important method to handle the problem before coding .  In our daily life, we often depend on the schedule to do something which has been planed. The schedules are often wrote by ourselves to plan the further event. Is there the same way in code? Surely,  the "schedule" in C code is named pseudocode . Pseudocode belongs to a high-level description of a computer program. The pseudocode is intended for programmer reading rather than the machine reading. Using the pseudocode ,we can abstract the problem to a concrete one and  make the program easily understand  , so we can translate the pseudocode  into the programming code more efficiently.

Now let us analyze this situation , after we finish the pseudocode description , convert it to programming code.

0), Record the student whose grade is higher than 60 . note PASSED ,or FAILED

If the grade is higher than or equals to 60

   print PASSED

else the grade is lower than 60

  print FAILED

end


main()
{
  int student1 = 90;
  int student2 = 60;
  int student3 = 50;

  if(student1 >= 60)
  {
     printf("PASSED\n");
  }
  else
  {
     printf("FAILED\n");
  }

  if(student3 >= 60)
  {
     printf("PASSED\n");
  }
  else
  {
     printf("FAILED\n");
  }

  if(student1 >= 60)
  {
     printf("PASSED\n");
  }
  else
  {
     printf("FAILED\n");
  }

}



1), Divided one value by another one and show the result. (When we meet the division , what we cared is whether the denominator  is zero or not.)

If the one (denominator is zero)

  warn the denominator is zero and jump out the calculation.

else 

   divide one by the other and record the result

   then print the result

end

As the pseudocode ,we convert it to programming as below.

main()
{
  float a = 10;
  float b = 2.0;
  float c = 0.0;
 
  float nominator = 0.0;
  float denominator = 0.0;
  
  nominator = a;
  denominator = c;
  if(denominator == 0)
  {
     printf("Error! The denominator is ZERO!\n");
  }
  else
  {
     c = nominator/denominator;
     printf("The result is %f \n",c);
  }

}



2) In chapter "Let us C in Code <7> operators" , there is listed question labeled 1) about the presents, can you describe it use the pseudocode ?

The question detailed as this  " 1) My friend Jen. will have the birthday, i really want to give her a present,  but it really depends on the time and the money, if i have free time i can prepare a home made present, but if i don't have enough time , so just buy a present. How can i handle this situation? "

If i have free time

   I will prepare a home made present

else if i don't have time

  Just buy a present 

end


This question just is an example for us to get the description of pseudocode step by step. If there are some concrete value ,we can translate the pseudocode to programming code as above question. But here, we can't . It dosen't matter, you can set some related value by yourself ,then code it.


Conclusion:

The pseudocode just a high-level description language .this language's purpose is used to make us (our human ) clear about the program before coding. Actually, the pseudocode  just is  text based , next chapter we will learn another method to describe the program ,that method is more visible and more efficiency than the pseudocode.

Ok , time's limited!  Thanks everyone!  I hope you enjoy this chapter. See you next chapter!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章