Answer to Question #213178 in C++ for Hemambar

Question #213178

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.


1
Expert's answer
2021-07-21T01:55:27-0400
#include <iostream>

using namespace std;

class Transmitter {

private:
    unsigned int pay_load;
    unsigned int parity;
    unsigned int data_packet;

public:

    Transmitter(unsigned int n) {
        pay_load = n;
    }

    void parity_bit() {
        unsigned int n = pay_load;
        bool p = 0;
        while (n) {
            p = !p;
            n = n & (n - 1);
        }

        if (p == 1) {
            parity = 1;
        } else {
            parity = 0;
        }

        cout << "Parity is " << parity << endl;
    }

    int getpay_load() {
        return pay_load;
    }

    void dataPacket() {
        data_packet = (parity * 32768) + (pay_load - 32768);
        cout << "Data Packet is " << data_packet << endl;
    }
};


class Reciever {
private:
    unsigned int Rx_Pkt;
    unsigned int Rx_Data;
    unsigned int E_Flag;

    void calculate_Eflag() {
        unsigned int n = Rx_Pkt;
        bool p = 0;
        while (n) {
            p = !p;
            n = n & (n - 1);
        }

        if (p == 1) {
            E_Flag = 1;
        } else {
            E_Flag = 0;
        }

        if (E_Flag == 0) {
            Rx_Data = Rx_Pkt;
        } else {
            cout << "The message is corrupted" << endl;
        }
    }

};


class Tranciever : public Transmitter, public Reciever {
public:

};

int main() {
    unsigned int n;
    cout << "Enter a number : ";
    cin >> n;

    Transmitter t(n);
    t.parity_bit();
    t.dataPacket();

    Reciever r;
}

Output:
Enter a number : 5
Parity is 0
Data Packet is 4294934533

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS