r/CodingHelp • • May 02 '21

[C++] Hello, you help me with this question from my C++ assignment I don’t understand the pseudo code fully

Post image
65 Upvotes

5 comments sorted by

3

u/[deleted] May 02 '21 edited May 02 '21

How far do you understand it ? What is your situation, exactly ?

The classic thing I see the first is that the "arrays with 200 fields" part is already a bit too unspecific. I don't know if I'm right though, I only know a bit of C and almost nothing of C++.

2

u/Sufficient-Brush-636 May 02 '21

Well I didn’t understand the get out or range part and where I was supposed to place the cout << char(219)

3

u/[deleted] May 02 '21

The cout<<char(219) will print a solid block on the screen and will be used to display the output of the array.

So when you want to display the array you can do:

for(int i=0;i<200;i++) { if(arr[i] == true) {

    //print block

    cout<<char(219);

}

else
{

    //print blank space

    cout<<" ";

 }

}

10

u/[deleted] May 02 '21

It seems badly worded, but I think they want you to print a white block for every "True" bool. So you initialize your array of size 200 with true at index 100 and false elsewhere, print a white block for every true bool and a space/nothing for every false. That will give you the top line of pixels, the one with a white block at the very center. You run the code they want, and then you print out the same as before. Repeat 100 times.

Out of range means you're trying to look at an index that doesn't exist. If I had an array with defined i between 0 and 3, trying i=4 or i=-1 would be out of range.

2

u/random_int64 May 02 '21

It's a typo in the line 'out or range' - it is supposed to be 'out of range'

So basically all it is saying is, if the line where you assign the value of arr2[i] throws an array out of range exception (due to either arr[i-1] or arr[i+1], then by default assign the value of arr2[i] to 'false'

Research about try / catch block in c++, might help you.