CAS Community   >   Resources   >  

Array_of_bits-01
Interactive demo! 2D Array - Flipping bits

Creates and displays 2D array of values, allowing user to flip them between 0 and 1

Phil Gardner

Created by Phil Gardner
last edited Mar 14 2021 by Phil Gardner



Used as an interactive demo for GCSE students, allowing them to experiment with 2D arrays of values. Teacher can display on board or students can run the code themselves.

Can compile and run using C++ on Raspberry Pi, Apple Mac, Linux PC or Windows PC (latter used CodeBlocks). Alternatively can paste code into replit.com

Source code allows you to choose size of array - change the values for NUM_ROWS or NUM_COLS to alter the size of the array. These constants are used throughout the program. Students are able to change these.

File 1 is the simpler version. File 2 has extra validation check to make sure that row and column numbers that you type in are valid integers. Uses a do-while loop to insist upon this until you give it a valid integer.

Array will be filled with 0 values (all bool values set to false).

Enters an infinite loop, displaying that array and asking the user for a row and column.

If the user enters row and column within range then that particular bit gets flipped using NOT.

Program counts how many bits are set to 1 and detects whether the array is all 0s, all 1s or a mixture of 1s and 0s.

More programs on blog here.

Downloaded 160 times.

Download

This resource has attached files: to access these files, please tick the box below to assent to the license terms
License: The resources on CAS website are under Creative Commons Attribution-Share Alike 3.0 licence unless otherwise specified by the resource creators.

You must confirm that you have read and agree the licence's ToS before you can download the attachments of this resource.

I have read the licence agreement of this resource and agree to abide by its terms and conditions.

Feedback and Comments


Available when logged in (join via the front page, for free):
  • View 0 comments on this resource.
  • View resource history, links to related resources.
  • Leave feedback for the author(s), or help by editing the resource.
Categories:


© 2021 BCS, The Chartered Institute for IT Registered charity: No. 292786
Using the websiteDisclaimer of liabilityCookies policyPrivacy notice