Sem 5‎ > ‎DCCN LAB‎ > ‎

P-2 WAP to determine if the IP address is in Class A, B, C, D, or E.

posted Nov 6, 2012, 5:58 AM by Neil Mathew   [ updated Nov 6, 2012, 6:00 AM ]
SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
 
using namespace std;
 
/*      CLASSES
 
        A:        0 - 127 ( = 128 )
        B:      128 - 191 ( =  64 )
        C:      192 - 223 ( =  32 )
        D:      224 - 239 ( =  16 )
        E:      240 - 255 ( =  16 )
*/
 
 
int main()
        {
//      clrscr();
 
        int a[4],i=0;
 
        cout<<"Enter The IP address";
        for(i=0;i<4;i++)
                cin>>a[i];
 
        cout<<"\n IP ADDRESS:"<<a[0];
        cout<<"."<<a[1]<<"."<<a[2]<<"."<<a[3]<<"\n";
 
        cout<<"The IP address is in Class: ";
 
        if(a[0]>=0 && a[0]<=127)
        cout<<"Class A";
        if(a[0]>127 && a[0]<191)
        cout<<"Class B";
        if(a[0]>191 && a[0]<224)
        cout<<"Class C";
        if(a[0]>224 && a[0]<=239)
        cout<<"Class D";
        if(a[0]>239)
        cout<<"Class E";
 
//      getch();
 
        return 1;
        }
 


OUTPUT:


Enter The IP address 220 100 8 12

 IP ADDRESS:220.100.8.12
The IP address is in Class: Class C

Comments