Off Topic: The Flood
This topic has moved here: Subject: Can someone explain programming classes/objects to me?
  • Subject: Can someone explain programming classes/objects to me?
Subject: Can someone explain programming classes/objects to me?

Life can be dangerous
╔╗╔══╦╦╦╦╗
║║║╔╗║║║║║
║╚╣╠╣║║║║╚╗
╚═╩╝╚╩══╩═╝

Ok I am new to programming I am using c++. I don't understand how classes work. I am trying to make 3 classes one called person to store a person first and last name. Another one called address to store his zip code, state and street and one last class called mail which ties everything together and includes their name and address, how would I go about doing the mail class? I tried to put the classes "person" and "address" under the mail class but it doesn't work. What do I do? what am I not getting?

  • 12.20.2012 1:55 PM PDT
  • gamertag: [none]
  • user homepage:

Writer's Corner
6/15/2011 11:39 PM: bobcast [2597260] issued a 3 day ban expiring on 6/18/2011 11:39 PM.
Reason: A Bungie.net Forum Moderator has banned you for violating the code of conduct and/or rules of the forum in the thread below
http://www.bungie.net/Forums/posts.aspx?postID=61704535
Inappropriate. Went a little to far with the butt hole tearing.

Give up now and get laid instead.

  • 12.20.2012 1:55 PM PDT

Per Audacia Ad Astra

Can't you just make a 3D array, or a struct?

  • 12.20.2012 1:55 PM PDT

did you inverse the gravity boosters ?

  • 12.20.2012 1:55 PM PDT

Life can be dangerous
╔╗╔══╦╦╦╦╗
║║║╔╗║║║║║
║╚╣╠╣║║║║╚╗
╚═╩╝╚╩══╩═╝


Posted by: Bungie Sam
Can't you just make a 3D array, or a struct?


It is part of the assignment I use classes. I need to then store this information for 3 different people.

  • 12.20.2012 1:59 PM PDT

On the Left

Godshatter: I can go all the way with someone without being attracted to them.
CamCamm: How does that work?
Godshatter: I'm easily aroused by anything that moves. It's a curse.
Brain says 'No, that's ugly', body says 'ugly is fine with me'.


Posted by: masterchief200

Posted by: Bungie Sam
Can't you just make a 3D array, or a struct?


It is part of the assignment I use classes. I need to then store this information for 3 different people.

Do you need to use them all in classes?

  • 12.20.2012 2:02 PM PDT

Life can be dangerous
╔╗╔══╦╦╦╦╗
║║║╔╗║║║║║
║╚╣╠╣║║║║╚╗
╚═╩╝╚╩══╩═╝


Posted by: Razgriz Berkut

Posted by: masterchief200

Posted by: Bungie Sam
Can't you just make a 3D array, or a struct?


It is part of the assignment I use classes. I need to then store this information for 3 different people.

Do you need to use them all in classes?


Yes. Everything must be in classes.

  • 12.20.2012 2:04 PM PDT

Posted by: Bungie Sam
Can't you just make a 3D array, or a struct?
Classes are much better, you can use them like a 3D array (though more likely as an array of objects of that class) or a structure.

Give me a second OP, let me take a look.

  • 12.20.2012 2:04 PM PDT

On the Left

Godshatter: I can go all the way with someone without being attracted to them.
CamCamm: How does that work?
Godshatter: I'm easily aroused by anything that moves. It's a curse.
Brain says 'No, that's ugly', body says 'ugly is fine with me'.

I recommend using a class called

class Shipping_Address

Since it looks like youre trying to that. 3 people, name of store, and the shipping location.

inside the class you make your private section

string Name
int num_Address
string st_Name, City, State, StoreName

then you use the functions you want in the public section

getName()
getAddress()
and any other function you need to get and output information

Then in your Main function you will do this

Shipping_Address information[3];

This way you make a class that holds all the information, and in the main you make 3 informations in an array

I know i didnt EXPLAIN classes, but I showed you on how to start :P

[Edited on 12.20.2012 2:08 PM PST]

  • 12.20.2012 2:07 PM PDT

Join the Halo Haven group!

easily the best explanation out there.

  • 12.20.2012 2:07 PM PDT

RIP Logan ~B.B.

Think of an object in programming just like you think of an object IRL. The easiest example I usuallly use to describe it is a box. A box has physical properties. A box has a height, a width, a length, weight, color, etc. When you think about properties (or instance variables) in a class, they are just like the physical properties of a box. Methods are an operation you can perform with that object. IRL, I could open the box, spin the box, shred the box, fill the box. Your class methods are something that can be done with that object.

It helps to imagine programming objects as real things, and it will make more sense.

  • 12.20.2012 2:09 PM PDT

Okay, so here's what you need to do:

class Mail
{
person thePerson;
address theAddress;

public void initialize(Insert neccessary variables as arguments)
{
//Call Method to initialize thePerson and pass along neccessary arguments
//Call Method to initialize theAddress and pass along neccessary arguments
}

//Other methods to return specific data from each class
}

Does that help?

[Edited on 12.20.2012 2:14 PM PST]

  • 12.20.2012 2:09 PM PDT

Life can be dangerous
╔╗╔══╦╦╦╦╗
║║║╔╗║║║║║
║╚╣╠╣║║║║╚╗
╚═╩╝╚╩══╩═╝


Posted by: Razgriz Berkut
I recommend using a class called

class Shipping_Address

Since it looks like youre trying to that. 3 people, name of store, and the shipping location.

inside the class you make your private section

string Name
int num_Address
string st_Name, City, State, StoreName

then you use the functions you want in the public section

getName()
getAddress()
and any other function you need to get and output information

Then in your Main function you will do this

Shipping_Address information[3];

This way you make a class that holds all the information, and in the main you make 3 informations in an array

I know i didnt EXPLAIN classes, but I showed you on how to start :P


Right but this is only if I have one class, I have the mail class which uses the stuff I put in the address class and the person class.

  • 12.20.2012 2:13 PM PDT

Life can be dangerous
╔╗╔══╦╦╦╦╗
║║║╔╗║║║║║
║╚╣╠╣║║║║╚╗
╚═╩╝╚╩══╩═╝


Posted by: Hylebos
Okay, so here's what you need to do:

class Mail
{
person thePerson;
address theAddress;

public void initialize(Insert neccessary variables as arguments)
{
//Call Method to initialize thePerson and pass along neccessary arguments
//Call Method to initialize theAddress and pass alongneccessary arguments
}

//Other methods to return specific data from each class
}

Does that help?


But how do I take the properties I stored in other boxes and put into the bigger box?

  • 12.20.2012 2:14 PM PDT

Posted by: masterchief200
But how do I take the properties I stored in other boxes and put into the bigger box?
Well, just as person contains a string called name and an int called age (I forgot the exact specifications from your original post), mail has a person called thePerson and an address called theAddress, and therefore it should have access to all the data stored in those classes as well. Perhaps not direct access, it depends on how you declared your classes, but we can get around that.

In your person and address classes you should have methods that return the data values of the class like:

private int returnPersonAge()
{
return personAge; //Returns the integer we use to store the person's age.
}

So all you have to do in your mail class is have a method that calls upon returnPersonAge()

private int returnMailAge()
{
return thePerson.returnPersonAge();
}

Ba-BOMB!

[Edited on 12.20.2012 2:21 PM PST]

  • 12.20.2012 2:19 PM PDT