Question: Use of advanced C + + code techniques, in this assignment, is prohibited. Limit commands to those discussed in the current and previous chapters, labs,
Use of advanced C code techniques, in this assignment, is prohibited. Limit commands to those
discussed in the current and previous chapters, labs, and lectures.
Do not share your code. If you get help or discuss this assignment with another individual, include
their names in the header comments.
Each time you indent code, use four spaces. Never use TAB characters in source code or program
output.
Do not use the break or continue statements within selection or repetition structures other
than switch structures.
Submit questions regarding this assignment at least to hours before it is due to allow time for
a response that you can implement.
Problem description
In the context of binary matrices, the evenness or oddness of the number of ones in each row and column of a
matrix determines whether it is balanced or corrupt.
More specifically, if a binary matrix is balanced, then each row and each column has an even number of ones, or
equivalently, the sum of each row and column is an even number. If a binary matrix is not balanced, then there
is at least one row or column with an odd number of ones, and the matrix is considered corrupt.
This is useful in certain applications, such as errorcorrecting codes, because it can be used to detect errors in
data transmission. For example, if a transmitted message is represented as a balanced binary matrix, then any
errors in the transmission will result in a matrix that is not balanced, indicating that an error has occurred, ie
it's corrupt.
For example, the matrix shown below is balanced:
In this matrix, each row and column has an even sum. Specifically, the rows have sums of and and the
columns have sums of and
Your task is to create a program that reads in a matrix and checks whether it is balanced. If the matrix is not
balanced, your program should determine whether it can become balanced by changing only one bit. If it is
impossible to balance the matrix by changing one bit, the matrix should be classified as "corrupt."
Input
The input stream will consist of one or more test cases. For each test case, the first line will contain a single
integer indicating the size of the matrix. The matrix will be provided in the
subsequent lines, with integers per line. The matrix will only consist of and and no other integers will
be present. The end of the input will be indicated by a value of for
Output
For every matrix in the input stream, output one line. If the matrix is already balanced, then print "Balanced". If
balance can be achieved by changing a single bit, then output "Toggle bit ij where is the row number and is
the column number of the bit to be modified. Otherwise, output "Corrupt".
Sample input file pabinputtxt
Sample output
paesb paesbinpute.txt
Balanced
Toggle bit
corrupt
Steps
Read the input, including the matrix size and the binary matrix.
Check if the matrix is balanced by calculating the sum of ones in each row and column.
If the matrix is balanced, print "Balanced" and proceed to the next test case.
If the matrix is not balanced, determine if changing a single bit can achieve balance.
If a single bit change achieves balance, print "Toggle bit ij with the row and column indices of the
modified element.
If balance cannot be achieved by changing a single bit, print "Corrupt".
Repeat steps for each test case in the input stream.
Specific program requirements
DO use only language features introduced in chapters lecture, or sample solutions.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
