is this true or false

When converting an algorithm into C++ code, each algorithm step must map to at least one C++ statement.
It wouldn't make much sense if a step could be done without a line of code, because in that case it wouldn't be a step at all. So I suppose the answer is true?

Unless one of the steps is something bizzare as "Make sure all your variables are of type integer". Then I guess you wouldnt need to write any code for that.

Edit: Makes sense what @Chervil said, could be the case too.
Last edited on
Something like a for loop could encompass in one line several separate operations. It would depend upon how the algorithm was expressed.
No, it is not true.

Algorithm:
step n: set y to the value of the current x
step n+1: increment the counter

Code:
y = x(i++);

Two algorithm steps, one statement
y = x(i++);
What is even going on here? what is "i". This code makes no sense.

Did you mean this? -

1
2
3
int i = 0;
int x = 5;
int y = x(i++);


This doesnt work at all.
Last edited on
You could have an algorithm step along the lines of "go back to calling function", but in C++ you can do that simply by having no more statements and it will happen at the end of the function.

A bigger question is where did this question come from? It has the feel of something someone teaching programming with very little actual programming experience might set as homework.
Topic archived. No new replies allowed.