ADVERTISEMENT

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Friday 29 April 2016

CSE1002:PP8:Code Detection Problem

Code Detection Problem 

 For security reasons, messages are transmitted as a secret code over a transmission channel. It is usually sent as a sequence of bits, that is, 0s and 1s. Due to noise in the transmission channel, the transmitted message may become corrupted. That is, the message received at the destination may not be the same as the message transmitted. There are several techniques to check the validity of the transmitted message at the destination. One such technique is to transmit the same message twice. At the destination, both copies of the message are compared. Given a file "data.txt" with the messages that is transmitted, write a C++ program to check whether the message received at the destination is error-free. For simplicity, assume that the secret code representing the message is a sequence of digits(0 to 9) and the maximum length of the message is 250 digits. Each original message is followed by a copy message and first number in both the messages indcates the length of the message. Each character in the message is separated by a space. For example, 7 9 2 7 8 3 5 6 7 9 2 7 8 3 5 6 means that the original message is of length 7 and it is 9 2 7 8 3 5 6 and copy message is also of length 7 and it is 9 2 7 8 3 5 6. If orginal and copy message is same then print Message transmitted is ok. Print Message transmitted is not OK when th length of the original or copy message is greater than 250 or when the original message is not same as copy message.

PSEUDOCODE:

START
READ name
OPEN FILE NAME IN l
while(!I.eof())
int a=0,b,c=0,d;
I>>n;
for i->0 to n
 I>>b;
 a=10*a+b;
end for
I>>m;
for i->0 to n
 I>>d;
 c=10*c+d;
end for
if(a==c)
 PRINT OK
else
 PRINT NOTOK
end if
STOP

CODE:

#include<iostream>
#include<string>
#include<fstream>
using namespace std;
main()
{
fstream f;
char name[20];
cin>>name;
f.open(name,ios::in);
int n,m;
while(!f.eof())
{int a=0,b,c=0,d;
f>>n;
for(int i=0;i<n;i++)
 {f>>b;
 a=10*a+b;
 }
f>>m;
for(int i=0;i<m;i++)
 {
 f>>d;
 c=10*c+d;
 }
if(a==c)
 cout<<"Message transmitted ok"<<endl;
else
 cout<<"Message transmitted is not ok"<<endl;

}
}

No comments:

Post a Comment