We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Internet Class Program???? Please HELP!!!

Dave091277 asked
Medium Priority
Last Modified: 2008-02-01
PLEASE CAN ANYBODY HELP ME????? I know that this is cheating but I have never been so desperate for help. I am at the end of my course and have got completely stuck with this assignment. I have no Idea what to do and am going to fail the course if I don't hand it in. I know that this is a lot to ask and I wouldn't do it normally but I desperalty need to get the grade.

The question is :-

Numeric address for computers on the internet are composed of four parts seperated by periods, of the form xx,yy,zz,mm, where xx, yy, zz and mm are positive integers. locally, computers are usually known by a nickname as well. You are designing a program to process a list of internet addresses, identifying all pairs of computers from the same locality (ie. with matching xx and yy components). Create a class called InternetAddress with components for the four integers and a fith copmponent to store an associated nickname of at most 20 characters. Your program should extract a list of any number of addresses and nicknames from a datafile whose name is provided by the user. The first line of the file should be the number of addresses that follow. Here is a sample of the data

3 platte
555.66.7.88 wabash green

dynamically allocate an array to hold the indicated numbers of InternetAddress objects. Fill the array and then display a list of messages identifying each pair of computers. Here is a sample message.

      Machines platte and green are on the same network.
include in your class definition friend operators >> and << and a SameNetwork member function that takes a second InternetAddress object as a parameter and returns true if the two addresses are on the same network and false otherwise. Follow the messages by a display of the full list of addresses and nicknames.
Watch Question

Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

I will not help you cheat.  But must institutions will allow you ask specific questions of experts (or seek the infomation from other sources)  If addition, most institutions would allow you to show your work to others for criticism and minor suggestions.  If that is within your school's guidlines, I would be happy to help you.

Assuming this is okay, why don't you post what you have done or if it is long, e-mail it to me at nietod@theshop.net.

If you have nothing done.  I suggest you start with the class declaration itself.  Try to figure out what data members need to be stored in the class.   Try to figure out what member procedures are need and declare them (you don't have to write them yet, just try to figure out what they are and what parameters they take.)   You may want to try to write the constructor and destructor members as well.  Then let me see what you have.

This is really very simple.  Ask concrete questions, post whatever you've done and we'll get you in shape in no time.  You can also contact me by mail if you wish (click on my handle to get the address)

As Alex said this is pretty simple and shouldn't take long (100 points would have been enough) but if it does, between the two of us you have round the clock coverage so we can keep you moving until you are done or die of exhaustion, which ever comes first.

Here quite a lot of people are helping you. Don't worry.
Try to break down the question into pieces. Think about the procedure to fulfill the task. You may solve the problem if you keep calm. My email address can be found from my homepage.
Good luck.


Thanks for all the help!! My main problem is that I have no idea where to start, we have had no tuition on file handling and only a tiny bit on making classes. I am trying to write the

Class InternetAddress

bit now. What is a constructor and destructor please??? I don't normally do this but this is the only peice of work in 4 years that has left me in such a mess. THANKS agian to all of you for the help.

>> Class InternetAddress
>>  {
>> Private:

All the data the object needs to hold.  "with components for the four integers and a fith copmponent to store an associated nickname of at most 20 characters" sounds like a good hint :-)

>> Public:

Whatever "interface" the object exposes to the outside world.  "a SameNetwork member function" sounds like a good hint.

>> };

Also, do not forget "friend operators >> and <<".

>> What is a constructor and destructor please
You can ignore them for now.  In general, a constructor is a method (member function) that constructs an object by initializing its data members, acquiring resources, etc.  Similarly, a destructor releases the aquired resources.  Your class can manage without a constructor for the time being and does not need a destructor at all.

I think I'm going to sign off and let Todd handle the rest of the interchange since he already locked the question and there is really not that much work.  For 450 points you better make him sweat hard!

I AM sweating.  Its been in the 100's in Oklahoma for a week now.

Before we go on.  Have you ever written a class before?   (Do you even know what one is?)  If not Alex's comments might not make sense.   I want to get an idea of your level of understanding before we really start.  


I did do a class for a battery a while ago. When I had sorted that (with some help from the turor) I could do stuff with the main() bit quite easily. My problem is setting up the class. After that though I have to figure out file stuff which I have never done in C++. I have used the Battery Class I did to try the begining of this.

class InternetAddress
      int numrecs;
      int x[100];
      int y[100];
      int z[100];
      int m[100];
      char nickname[100];
      InternetAddress(Int, int, int, int, int, char);


InternetAddress::InternetAddress(int number, int a, int b, int c, int d, char name)
      int count =1;
      numrecs = number;

            x[count] = a;
            y[count] = b;
            z[count] = c;
            m[count] = d;
            nickname = name;
      While(count <= numrecs)

Would this make it so that in the MAIN() bit I could read the file one line at a time and put them into the array within the class????

Lets not worry about main yet.   Lets get the class made first.  Then we'll use it.

First of all, inside you class you have arrays like

int x[100];

This is an array that will hold 100 values.  That isn't what you want.  You only need on x value, like

int x;

Your constructor builds on this.  It sets every item in these arrays to specified values.  you shouldn't need to do this.

Each InternetAddress object will store a single address.  If you need to store multiple addresses, you will create multiple InternetAddress objects.  Does that make sense?

another probem in the constructor is that you try to use an = to copy a string, like

nickname = name;

That doesn't work.  That won't even compile.  You have to use strcpy() to copy strings.  (or you can use a string class that defines operator =, but I suspect you haven't covered that yet.)

So lets work on these things.
1.  Make the class store just the data it needs, with no arrays for the address information.
2.  Change the constructor to set the non-array form of the address information
3.  Use strcpy() to copy the name.

By the way, just so you know, the do...while loop you had will never terminate.  It does not change "count" so it will go forever.  But, you will not need it all, anyways.


What do you mean when you say "Change the constructor to set the non-array form of the address information"???

I understand the array bit I think... Do you mean that when I create an InternetAddress item I would use something like :-

InternetAddress Address1(?????)

I used something like that in my battery program. Also do I need to set all of the values how I have???
Sorry for taking up so much of your time.

Sorry, for being unclear.  

You made the InternetAddress class store arrays of address information and you made the constructor initialize the arrays.  That is not needed, you only need one address per object (do you understand that?)  What I was saying is you need to change the object to store only one address (not arrays) and change the constructor to initialize just the one address (not arrays.)  Is that better?  One little thing.  You do need an array for the name.  Just not for the x,y,z stuff.  Okay?

I don't really understand the other stuff you are asking about.  Hopefully I answered it with my last comment.  If not try asking again.  (reworded.)


I have had to mail you because my connection is really slow. I changed the previous code but forgot to change

nickname= name to

nickname = strcopy(name)

I don't know if that is the correct way to do it though???

The following was sent in an E-mail.  I just want to keep a record of it.
For a class we write we can overload operators in two ways.  As members
function or non-member functions.  For example say I write a class that
stores huge integers by storing each digit in a big array, like

Class HugeInt
    char Digits[100];

I would like to do.

HugeInt H1 = 1000000000000;
int          S2 = 5;
HugeInt H2 = H1 + S2;  // get 10000000000005

If have two choices about how to write a function that adds a regullar
integer to a huge int, I could do it as a member of non-member
function.  As a member function it would look like

HugeInt HugeInt::operator +(int RhtOpp)
   HugeInt RetVal;  // Eventually holds value to be returned.
   RetVal = *this; // start with value on left side of "+"
   ///// somehow add on RhtOpp.
     return RetVal;

In this case the HugeInt on th left side of  the "+" is the object the
function got called for.  The int on the right side of the "+" is the
one passed in the parameters.  Make sense?  As a non-member function it
is written like

HugeInt operator +(HugeInt LftOpp,int RhtOpp)
   HugeInt RetVal;  // Eventually holds value to be returned.
   RetVal = LftOpp; // start with value on left side of "+"
   ///// somehow add on RhtOpp.
  return RetVal;

In this case there are two parameters.  The one on the left side of the
"+" comes first, then the one on the right side.  Big deal?  not really,
but it will be important in a bit.

When you write an overidded operator as  member function, you can
specify the type that goes on the right side only.  The type on the left
side is the class that you are writting this for.  Make sense? But when
you write a non-member function you get to specify the types on the left
and on the thr right side.

Here is the thing.  We want to write an overloaded "<<" that we can use

cout << HugeInt;

to print a HugeInt to an I/O stream.  Out first attempt should try to be
with a member function.  Member functions are nice because they can
access private members and the data we need to print (all those digits)
is private  So we try

ostream &HugeInt::operator <<(ostream &S) const
     S << Digits;
     return S;

That works, almost.  But it is backward.  We want

cout << HugeInt;

but that has to be used as

HugeInt << cout;

Why?  because the class we overloaded, Hugeint, goes on the left, and
the parameter class, the stream, goes on the right.  To get them on the
right sides we could try writting it for the stream class.   Like

ostream &ostream::operator <<(const HugeInt &H)

However, this is changing the ostream class.  It is adding a new
function to it.  We're not allowed to do that. Its not part of the
original class declaration.  So this means that the overloaded operator
can not be a member function.  (in this case, that is for  <<, for most
cases it can)  It needs to be a non-member like

ostream operator <<(ostream &S,const HugeInt &H)
    S << H.Digits;
   return S;

Now that works in that the stream is on the left and the huge int is on
the right.  The only problem is the line inside that accesses
H.Digits.  Digits is private.and this function is not a member function
so it can't access digits.  How do we get around that.  We declare this
function as a friend to HugeInt.  Then it can access HugeInt's private
members, like Digits.

That is why the assignment asked for overloaded "Friend" functions for
<< and >>.  They must be overlaoded because they will work on the type
you create.  They must be friend's because A) they can't be members of
your class and B) they have to access the class's private data.

Make sense?  do you think you can write the << function?  it should just
print out the contents of the IntenetAddress.  to the stream in the
parameters. Like

cout << "Numeric Address:  " << x << '.' << y << '.' << z << endl;
cout << "Name:   " << nickname;

Now the stream it will be printing to is not cout, it will be a stream
passed in the parameters.  Also there should be 4 numbers printed, but I
don't remember the 4th's name.  It didn't start with "w", I don't think,
but there's nothing after "z".  But you get the idea.

This is what we ended up with.  This doesn't meet the requirements but may be all that gets done before the deadline.
 class InternetAddress
                        int x;
                        int y;
                        int z;
                        int m;
                        char nickname[21];

                        InternetAddress::InternetAddress(int a, int b, int c, int d, char *name)
                                strcpy(nickname, name);

                                strcpy(nickname, "");

                        int InternetAddress::SameNetwork(const InternetAddress &Otheraddress)
                                 return (x == Otheraddress.x)&&(y == Otheraddress.y);

friend ostream  & operator <<(ostream &S, const InternetAddress &IA);


ostream & operator<< (ostream &S, const InternetAddress &IA)

                return S;

void main()
        InternetAddress IA1(1, 2, 3, 4, "Bill");
        InternetAddress IA2(1, 2, 4, 7, "Fred");

        if (IA1.SameNetwork(IA2))
                cout<<"Not the same";


Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.