Create a class called Transmitter. It has three unsigned int private data members: pay_load,
parity and data_packet; It has one function called parity_bit(). It calculates parity bit by XORing
all pay_load bits and assign the value to parity. By using function get pay_load(), pay_load is got.
data_packet is calculated by multiplying parity_bit with 32768 and add the product with (pay_load
– 32768). Create another class called Receiver. It has unsigned int private data members Rx_Pkt
, Rx_Data and E_Flag. Rx_Data is got from Rx_Data as given below. First E_Flag is calculated
from Rx_Pkt by XORing all bits. If E_Flag is zero, then Rx_Data = Rx_Pkt – 32768, Else a
message should warn about corrupted packet. Derive a class called Tranceiver from the above two
classes and check the functionalities. Use any other functions if needed.
#include <iostream>
using namespace std;
class Transmitter{
private:
unsigned int pay_load,parity,data_packet;
public:
void parity_bit(){
parity = 0;
while (pay_load)
{
parity = !parity;
pay_load = pay_load & (pay_load - 1);
}
data_packet=parity*32768;
}
};
class Receiver{
private:
unsigned int Rx_Pkt, Rx_Data,E_Flag;
void check_Packet(){
if (E_Flag==0){
Rx_Data = Rx_Pkt-32768;
}
else
cout<<"\nCorrupted packet\n";
}
};
class Tranceiver: public Transmitter, public Receiver{
};
int main()
{
Transmitter t1;
t1.parity_bit();
return 0;
}
Comments
Leave a comment