473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Check for parity property in matrix using C++

Your job is to write a C++ program that reads in a matrix and checks if
it has the parity property. If not, your program should check if the parity
property can be established by changing only one bit. If this is not possible
either, the matrix should be classified as corrupt.
1Stolen from Miguel A. Revilla, Error Correction, http://online-
judge.uva.es/p/v5/541.html, accessed 1 Nov, 2005
1
The Input
The input file will contain one or more test cases. The first line of each test
case contains one integer n (n < 100), representing the size of the matrix.
On the next n lines, there will be n integers per line. No other integers than
0 and 1 will occur in the matrix. Input will be terminated by a value of 0
for n.
The input file will be called data.txt and will be stored on the a: drive.
You should hard code this into your assignment.
The Output
For each matrix in the input file, print one line. If the matrix already has
the parity property, print OK. If the parity property can be established by
changing one bit, print Change bit (i,j) where i is the row and j the
column of the bit to be changed. Otherwise, print Corrupt.
There should be no other output from your program and your program
should terminate when all matrices have been processed.2
If your input and output does not conform to these specifications you will
be penalised a full a grade.
Sample Input
4
1 0 1 0
0 0 0 0
1 1 1 1
0 1 0 1
4
1 0 1 0
0 0 1 0
1 1 1 1
0 1 0 1
4
1 0 1 0
0 1 1 0
1 1 1 1
2If you use ”system(”PAUSE”)” in your program the system will write ”Press any key
to continue” to the screen. This is allowed and will not be penalised.
2
0 1 0 1
0
Sample Output
OK
Change bit (2,3)
Corrupt
Sep 14 '07 #1
4 3942
sicarie
4,677 Expert Mod 4TB
I'm sorry, I missed your question in there? What part do you need help with?
Sep 14 '07 #2
I'm sorry, I missed your question in there? What part do you need help with?
I dont know how to write a code to calculate the 1 in a matrix
Sep 14 '07 #3
sicarie
4,677 Expert Mod 4TB
I dont know how to write a code to calculate the 1 in a matrix
Well, I think you're getting ahead of yourself there - you should really create an algorithm for the project before you begin coding it. That will help you get the concepts down, and then it will also help you code more quickly (when you reach that point).

If you were given a sheet of paper with those test cases, and all you had to work with was a pencil and a blank sheet of paper, how would you solve that problem (doing the really annoying thing as all your math classes said and "showing your work")?
Sep 14 '07 #4
JosAH
11,448 Expert 8TB
Your job is to write a C++ program that reads in a matrix and checks if
it has the parity property.
That's not my job; are you guessing what everybody's job is? Guess again.

kind regards,

Jos
Sep 14 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: snacktime | last post by:
Is there a module that sets the parity of a string? I have an application that needs to communicate with a host using even parity So what I need is before sending the message, convert it from...
2
by: Petr Jakes | last post by:
Hi, I am trying to set-up communication to the coin change-giver from my Linux box using the Python code. The change giver uses MDB (Multi Drop Bus) serial protocol to communicate with the...
15
by: Herbert Haas | last post by:
Hi everyone, is there a simple and fast method to check the parity of a word (e. g. a 4-byte integer)? That is I want to know whether the number of ones are even or odd. Of course I could do...
2
by: Peter Oliphant | last post by:
OK, I'm mixing old style with new style, so sue me... : ) Will under old syntax, I'm able to create a SerialPort instance. But, when I try to convert the Parity proerty to a String*, I get the...
0
by: Loren | last post by:
I am using parity error checking as I receive data into the input buffer from the comm port. The data I receive consists of a parity error, followed by received data, followed by a parity error. ...
0
by: Rogoras | last post by:
I use termios.h and have following problem: My computer comunicates to host computer usig serial RS232. Host is using parity bit as wake up bit and 8 data bits. In other words parity bit is...
0
by: Radu Crisan | last post by:
Hi all, i have this RS232 settings public static string portName; public static Int16 baudRate = 19200; public static Parity parity = Parity.Mark; public static Int16 dataBits = 8; public...
5
by: Ken JS | last post by:
How do I find the Parity Check Matrix, when I’m given the generator matrix? e.g. | 1 0 0 1 1 | G = | 0 1 0 1 2 | | 0 0 1 1 3 | Can anybody teach me how to find the Parity Check...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.