CMPS 2433 Short Program Using Bitwise Operations

CMPS 2433 Discrete Structures and AnalysisProgram 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
off.
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:
0.
1.
2.
3.
4.
5.
6.
7.
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:
6
64
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
number.
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)
Solution:
 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)
A-M:
 Reads each gate’s value (8)
 Prints each dipswitch’s status (16)
 prints toggled message for gate 1 (8)
N-Z
 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)
Readability/Algorithm/Style
 Good comments (5)
• Top of every file
• Prototypes for functions
• Internal code
 Good use of blank lines/spacing (2)

Calculate your order
275 words
Total price: $0.00

Top-quality papers guaranteed

54

100% original papers

We sell only unique pieces of writing completed according to your demands.

54

Confidential service

We use security encryption to keep your personal data protected.

54

Money-back guarantee

We can give your money back if something goes wrong with your order.

Enjoy the free features we offer to everyone

  1. Title page

    Get a free title page formatted according to the specifics of your particular style.

  2. Custom formatting

    Request us to use APA, MLA, Harvard, Chicago, or any other style for your essay.

  3. Bibliography page

    Don’t pay extra for a list of references that perfectly fits your academic needs.

  4. 24/7 support assistance

    Ask us a question anytime you need to—we don’t charge extra for supporting you!

Calculate how much your essay costs

Type of paper
Academic level
Deadline
550 words

How to place an order

  • Choose the number of pages, your academic level, and deadline
  • Push the orange button
  • Give instructions for your paper
  • Pay with PayPal or a credit card
  • Track the progress of your order
  • Approve and enjoy your custom paper

Ask experts to write you a cheap essay of excellent quality

Place an order