Create a class to process internet addresses xx.yy.zz.mm from a data file and identify machines in the same locality (xx.yy) by their nickname

What will be an ideal response?


```
class InternetAddress {
public:
InternetAddress () {}
InternetAddress (int, int, int, int, const string&);
string getnickname() const; // accessor
bool sameNetwork (const InternetAddress&); // test if same network

private:
int xx, yy, zz, mm; // internet address conponents
string nickname;

friend istream& operator>> (istream&, InternetAddress&);
friend ostream& operator<< (ostream&, const InternetAddress&);
};

int main()
{
string infilename;
int size, actsize;
InternetAddress* addresses; // array of addresses
char badChar; // input error check character
int i; // loop control

cout << endl << "Enter name of internet address data file => ";
cin >> infilename;
ifstream infile (infilename.c_str(), ios::in);

infile >> size;
addresses = new InternetAddress [size]; // dynamically allocate array

for (i = 0; (i < size && !infile.fail()); ++i)
infile >> addresses[i];

if (infile.eof()){
cout << endl << "Unexpected end of data file!" << endl;
actsize = i - 1;
cout << "Only using first " << actsize << " addresses."
<< endl << endl;
} else if (infile.fail()){
infile.clear();
infile >> badChar;
cout << endl << "Error in data file at => " << badChar
<< " <<<" << endl;
actsize = i - 1;
cout << "Only using first " << actsize << " addresses."
<< endl << endl;
} else {
actsize = size;
cout << endl<< "Data read " << actsize
<< " addresses successfully!" << endl << endl;
}

for (i = 0; i < (actsize - 1); ++i)
for (int j = i + 1; j < actsize; ++j)
if (addresses[i].sameNetwork(addresses[j]))
cout << "Machines "
<< addresses[i].getnickname()
<< " and "
<< addresses[j].getnickname()
<< " are on the same local network."
<< endl;
cout << endl << "Machines tested:" << endl;
for (i = 0; i < actsize; ++i)
cout << addresses[i] << endl;

cout << endl;

delete[] addresses; // return memory to heap

return 0;
}

```

Computer Science & Information Technology

You might also like to view...

If the member variables of the base class are marked as protected, who can access those variables?

What will be an ideal response?

Computer Science & Information Technology

A Canvas is a layout container that allows you to position controls by defining explicit coordinates from the Canvas’s ________ corner.

a) lower-left b) lower-right c) upper-left d) upper-right

Computer Science & Information Technology

Which layer provides flow control and ensures data reliability from source to destination?

A. Physical B. Data Link C. Network D. Transport

Computer Science & Information Technology

A hand drawn or computer generated page ____ indicates what a finished page will look like.

A. mockup B. plan C. sample D. none of the above

Computer Science & Information Technology