Sunday, July 12, 2009

How can i make c++ code from any pseudocode.?

I want to write c++ code from a given pseudocode? How can i do that. Please Explain.

How can i make c++ code from any pseudocode.?
I will first give you the C++ codes then explain it in a step-by-step manner:





void MAXIMA(int n, int *P)


{


for(i=1; i%26lt;=n; i++)


{


maximal = true;


for(j=1; j%26lt;=n; j++)


{


if ((i == j) %26amp;%26amp; (P[i]-%26gt;x %26lt;= P[j]-%26gt;x) %26amp;%26amp; (P[i]-%26gt;y %26lt;= P[j]-%26gt;y))


{


maximal = false; break;


}


if(maximal == true)


{


cout%26lt;%26lt;P[i];


}


}


}


}





Ok...


1. Remember that MAXIMA is not a keyword therefore it may be a variable or a function name. In your pseudocode, MAXIMA is paired with open and close parenthesis therefore it is a method / function.


2. Inside the parenthesis for function name MAXIMA, is a variable n of type integer and a pointer of type integer. I consider that pointer an integer because it stores an integral value of elements in array.


3. Inside such function is a for loop. This confuses me for a second because I thought that there are two different for loops. But when I noticed that the second for loop has this condition " if(i==j) and P[i].x %26lt;= P[j].x)...", this concludes that the second for loop should be placed inside the first for loop. P[j].x and P[j].y are my evidences.


4. for the first for loop, maximal should be assigned with a boolean value true


5. On the second for loop, two "if" statements must be placed. It should not be a nested-if because there is no "else" in your pseudocode.


6. Copy the entire condition set in your pseudocode for your first if statement.


7. Same is true with the second if statement.


8. Output P[i] should be 'cout%26lt;%26lt;P[i];' because our return type is void. Considering that your pseudocode does not have a return type.





Hope it helps...
Reply:That's just not an answerable question. Pseudocode should be translatable into any language you know. If you can't translate the pseudocode then either the pseudocode is bad or you don't know the language (c++) you are translating to.
Reply:Learn the constructs of the language, and it should be clearer as to how you would proceed. No one can really answer that for you. But here is a helpful example.





e.g.





Pseudo code:





FUNCTION 1:


IF input is LESS THAN 3


THEN GOTO FUNCTION 2





FUNCTION 2:


PRINT "HEY"





C++:





function one(int input)


{


if(input %26lt; 3)


two();


}





function two()


{


cout %26gt;%26gt; "Hey" %26gt;%26gt; endl;


}
Reply:You cannot do it, you have to translate it manually or ask an programming expert to code it for you . Check websites like http://askexpert.info/
Reply:You will need to learn C++ , I suggest you download microsoft Visuall C++ and go from there

flowers uk

No comments:

Post a Comment