Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

.11 Sprint 4:00 PM instructure-uploads.s3.amazonaws.com C 1 of 2 C.Object Orient

ID: 3597797 • Letter: #

Question

.11 Sprint 4:00 PM instructure-uploads.s3.amazonaws.com C 1 of 2 C.Object Oriented Programming Create a cless called Rational that represents a rational number. A rational number is any number that can be expressed os a ratio of two integers (a/b), with the denominater not equal to zere. 1) Use only two private member variables numeretor and denominator. Do not add any other ones 2) Create two constructors, one of which should be a default constructor 3) Add all necessary Get and Set functions 4) Create a private member helper function to store the result in the most reduced form·4/16 must be converted to 1/4 before it is stored in the object 5) If the denominator and the nominator are both negative numbers, the class removes the signs automatically. If the denominator is a negative number reverse the signs. This is done by the previous private helper function Examples: -3/-5 should be stored os 3/5 5/-7 should be stored as-5/7 6) Create a member function to add two Rational numbers (two objects of the class). 7) Add three more similar functions to subtract, multiply, and divide two Rational numbers (two object of the rational class) 8) Create a function to print the rational number in the form of a/ (1/4) 9) Add another function to print the number in the form of a floating point (25) 10) Remember, all functions are member functions, such as add) and multiply) In order to test your class in your main function, prompt the user for numerafor and the denominator for your first object. Repeat the prompt for the second object. Perform all mathematical operations by calling the functions. Print the two rational numbers in both print forms (a/b) and as a fleating point. Then, print the result of the calculations in both forms. Make sure you label all numbers printed, for instance Your first rational number is: 3/2 which is 1.5 Your second number is 5/2 which is 25, The sum of the numbers is 4/1or 4.00 Output the rest of the result the same way Nnte thnt in the nhave nmnle 3/2 5/2 R/2 r rinee etore the frnrtinn in the

Explanation / Answer

void raw_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)

{                                                                                                                                           {

        u_int length = h->len;

        u_int caplen = h->caplen;

        /* At this point we start extracting data from the packet, with the var idx keeping up with where we are in the packet */

        // Print total packet size

        printf(" Packet Length %d bytes", h->len);

                // Decode Ethernet (Layer 2) Header Info

                        int idx;                         // counter variable for indexing through packet

                        char eth_destination[6]; // var to store the ethernet destination address

                        char eth_source[6];      // var to store the ethernet source address

                        short eth_type;                  // var to store the ethernet type value

                        char eth_payload[10];    // string array to store payload description

                        char eth_bcast[6] = "0xFF";

                        // Extract Ethernet Destination Address (1st 6 bytes)

                        for ( idx = 0; idx < 6; idx++)

                        {

                                eth_destination[idx] = p[idx];

                        }

                        // Extract Ethernet Source Address (2nd 6 bytes)

                        for ( idx = 6; idx < 12; idx++)

                        {

                                eth_source[idx-6] = p[idx];

                        }

                        // Combine two byte Ethernet Type/Length field into one value

                        eth_type = p[12] * 256 + p[13];

                        // Check the packet type and increment related counter

                        if ( eth_type >= 0x600) {

                                switch ( eth_type )

                                {

                                        case 0x800: // Check to see if the type indicates that the packet is IP

                                                ctrIP++;

                                                strcpy(eth_payload, "IP");

                                                break;

                                        case 0x806: // Check to see if the type indicates that the packet is ARP

                                                ctrARP++;

                                                strcpy(eth_payload, "ARP");

                                                break;

                                        default:

                                                break;

                                }

                        }

                        // Check to see if the destination was a broadcast packet and increment related counter

                        /*

                        if ((eth_destination[0] == 0xFF ) && (eth_destination[1] == 0xFF ) && (eth_destination[2] == 0xFF ) && (eth_destination[3] == 0xFF ) && (eth_destination[4] == 0xFF ) && (eth_destination[5] == 0xFF )) {

                                ctrBCAST++;

                        }

                        */

                        // Print Ethernet (Layer 2) Header Info

                                printf("Layer Field Value ");

                                printf("ETHERNET Destination %02x:%02x:%02x:%02x:%02x:%02x ", eth_destination[0],eth_destination[1],eth_destination[2],eth_destination[3],eth_destination[4],eth_destination[5]);

                                printf(" Source %02x:%02x:%02x:%02x:%02x:%02x ", eth_source[0],eth_source[1],eth_source[2],eth_source[3],eth_source[4],eth_source[5]);

                                printf(" Type 0x%02x ", eth_type);

                                printf(" Payload %s ", eth_payload);

                // All packets will have ethernet info (decoded and printed above).

                // At this point we have to determine what kind of data is at the next layer up (layer 3) and decode/print the data accordingly.

                // This is done based on the eth_type variable.

                if ( eth_type >= 0x600) {

                        switch ( eth_type )

                        {

                                case 0x800: // IP Packet

                                        // insert code to decode and print IP (should this be a separate sub-routine?

                                        break;

                                case 0x806: // ARP Packet

                                        // insert code to decode and print ARP

                                        break;

                                default:

                                        break;

                        }

                }

                exit(0);

}