CMPS 2433 Short Program Using Bitwise Operations


2 attachmentsSlide 1 of 2attachment_1attachment_1attachment_2attachment_2

Unformatted Attachment Preview

CMPS 2433 Discrete Structures and Analysis
Program 1 Spring 2022
Due Wednesday, Feb. 2, 2022
Patriot is a company that manufactures gate operators. There is a circuit board in the housing which
contains a set of programming dipswitches that are manually set by the owner. These dipswitches are
used to customize the operation of the gate. Each switch corresponds to a setting that is either on or
Within a C++ program, a separate flag (bool variable) could be used to represent each condition. If
there were 10 conditions (or states), 10 different variables would be required.
Being the efficient programmer that you are, you decide to save memory space by using a single variable
and using bitwise operators to manage the options.
Starting with the rightmost bit, suppose there are 8 dipswitches representing these options:
Sensor Enter (There is a sensor that will automatically open the gate and allow visitors onto the property.)
Soft Open (The gate opening speed will gradually diminish as it opens.)
Soft Close (The gate opening speed will gradually diminish as it closes.)
Automatic Close (The gate will close automatically after a visitor enters/exits.)
Sensor Exit (There is a sensor that will automatically open the gate and allow visitors to exit the property.)
Intercom keypad (The intercom is enabled allowing visitors to signal the base station in the house.)
Pin Lock (When on, disables the ability to manually operate the gate.)
Photo Beam (When on, senses objects in the way of gate open/close and automatically reverses.)
Name your source code: lastname_firstname_1*.cpp (where * is replaced by A or B)
Name your output file: lastname_firstname_gate*.out (where * will be replaced by A or B)
Display your name as the first line of output.
Option A (Last name begins with A – M)
Input will be from the file named “gateoptions.dat”
The file will consist of an unknown number of integers ranging from 0 to 255. You will examine the bits
in the binary format of this number. You will use bitwise operators to determine which options are on
and which are off. For each number read in, describe each option as on/off. Also, for the first integer
read in, you will toggle all 8 bits using a bitwise operator and output the base ten value for that result.
Read until the end of file.
Sample input:
Corresponding output:
Catherine Stringfellow
Gate #1
Sensor Enter: OFF
Soft Open: ON
Soft Close: ON
Automatic Close: OFF
Sensor Exit: OFF
Intercom Keypad: OFF
Pin Lock: OFF
Photo Beam: OFF
If options on the first gate are toggled, value of flag would be 249.
Gate #2
Sensor Enter: OFF
Soft Open: OFF
Soft Close: OFF
Automatic Close: OFF
Sensor Exit: OFF
Intercom Keypad: OFF
Pin Lock: ON
Photo Beam: OFF
Option B (Last name begins with N-Z)
Input will be from the file named “on_off.dat”
There will be exactly ten lines of data.
For each gate, you will read in a series of 8 occurrences of on or off. The first on or off will used to set
the leftmost bit (Photo Beam). The last on or off on the line will be used to set the rightmost option
(Sensor Enter). Based on those values, you will use bitwise operators to appropriately set the bits of the
single variable. The resulting base ten number will be sent to the output file, along with the gate
For the first line of data ONLY, after determining the flag, toggle the PHOTO BEAM bit only and output
the resulting value of the flag.
Sample input:
off off off off off off off off
on off off on off off on on
Corresponding output:
Catherine Stringfellow
Gate #1 FLAG is 0
If the PHOTO BEAM bit is toggled, the flag would be 128.
Gate #2 FLAG is 147
Programming Assignment 1
NAME _____________________________
Turned in Feb. 2, 11am: on Time ______________
Turned in:
 Printout of .cpp file for program (4)
 Printout of input files (2)
 Opens/Closes files per my slides (4)
 Has correct loop structure for option (5)
A-M: while ! eof loop
N-Z: for loop
 Has inner for loop (5)
__________/ 100 points

Printout of output files (2)
.cpp file uploaded to D2L (2)
 Reads each gate’s value (8)
 Prints each dipswitch’s status (16)
 prints toggled message for gate 1 (8)
 reads dipswitch values for each gate (8)
 prints out gate value (16)
 prints toggled message for gate 1 (8)
User Interface (I/O Formatting):
 Good prompts (2)
 Asked user for name of files (2)
 Printed heading (name) (1)

Labeled all output (3)
Used blank lines and spacing (pretty) (2)
Design/Applied Concepts covered in class:
 Used bitwise logic (15)
 Used file I/O (4)

Used functions (5)

Good choice of identifiers (1)
Good indentation (1)
Good choice of control structures (ie
switches, loops, etc.) (1)
 Good comments (5)
• Top of every file
• Prototypes for functions
• Internal code
 Good use of blank lines/spacing (2)

Purchase answer to see full

Programming Code

bitwise operations

Discrete Structures and Analysis

User generated content is uploaded by users for the purposes of learning and should be used following Studypool’s honor code & terms of service.

Reviews, comments, and love from our customers and community:

Article Writing

Keep doing what you do, I am really impressed by the work done.



PowerPoint Presentation

I am speechless…WoW! Thank you so much!

Stacy V.

Part-time student

Dissertation & Thesis

This was a very well-written paper. Great work fast.

M.H.H. Tony


Annotated Bibliography

I love working with this company. You always go above and beyond and exceed my expectations every time.

Francisca N.


Book Report / Review

I received my order wayyyyyyy sooner than I expected. Couldn’t ask for more.

Mary J.


Essay (Any Type)

On time, perfect paper

Prof. Kate (Ph.D)


Case Study

Awesome! Great papers, and early!

Kaylin Green


Proofreading & Editing

Thank you Dr. Rebecca for editing my essays! She completed my task literally in 3 hours. For sure will work with her again, she is great and follows all instructions

Rebecca L.


Critical Thinking / Review

Extremely thorough summary, understanding and examples found for social science readings, with edits made as needed and on time. Transparent

Arnold W.




Joshua W.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>