Hey,
There are somethings i dont understand in classes, for example let us examine this :

we created a class Employee , with private data members firstName, lastName and monthlySalary; we have some functions that performs operations like a constructor, set and get functions on this data members. Now! we create an object of the class. I will like to some things:

1==> is the constructor like a form we fill to enter employee details as soon as a new employee is employed? for example we have a new employee in the company, we want to create an object for him/her from the class employee, are we going to use the constructor for the details ? or are we going to use the set functions? If the class does not have a constructor for the details, what happens with the new employee?


2==> when we have created the employee object, what happens next? is it just that we are going to store it as a record on the computer or database? or are there other things we can use the employee object for?
or does that mean that if we are not going to store or retrieve information from the computer, we dont need classes?

3==> I still have few more questions but i dont want to create a long boring page... May be when i get a reply for this i will paste the rest of my question:confused:

>is the constructor like a form we fill to enter employee details as soon as a new employee is employed?
Pretty much, yes. The first and foremost goal of the constructor however, is to allocate memory for the object. Additionally, most constructors provide a way of initializing the data like you described, however that is the choice of the programmer.

>are we going to use the constructor for the details ?
Usually you would make the constructor do this to make the code shorter, but again, it's the choice of the programmer.

>If the class does not have a constructor for the details, what happens with the new employee?
If no constructor (or destructor) is defined, the compiler inserts a default one which takes care of the static-memory allocation.

>when we have created the employee object, what happens next?
Whatever you want. Basically you do whatever the instructor tells you to do.

>is it just that we are going to store it as a record on the computer or database?
Well, if your project requirements say to do that, then you would.

>or are there other things we can use the employee object for?
Sure, you could send it over the internet, print it out onto paper, or just display it on screen. Anything you want.

>or does that mean that if we are not going to store or retrieve >information from the computer, we dont need classes?
You never need classes, they're just an effective way of storing information and keeping your code organized. If you weren't writing the data to the hard disk, it would still be useful to use classes, because they're extremely good at storing data like that.

Comments
Hey do I always need a reason...;) BTW congratulations on one million blog views of Daniweb :D - Sanjay

thnx alot for the rescue,


like i said i still have more questions to ask about this same classes:

concerning the previous question, hwo can another class interact with class employee e.g class doctor?

There is this question that my mind cant just stop thinking about; How is it possible to improve an object of a class?
does this mean that the object will have some features that is more advanced than the class?
like additional data members.
For example, in the class automobiles, will a convertible have a data member that others dont have? or a convertible belongs to a new class that imitates the class automobiles but with more data members? like member openRoof;

> how can another class interact with class employee e.g class doctor?
One class interacts with another classes by means of object instances. You can always pass on object instance of one class to the member function of another class. In fact we do this all the time without even realizing it:

// here str is a object instance of class string
string SomeClass::modifyString (string str)
{
   // process
   return str;
}

> How is it possible to improve an object of a class?

What do you exactly mean by this ? Maybe the generalization and specialization relationship. Consider for example an Account class.

An Account class is the generalization of Savings, Fixed and Current account types (a fixed account is a type of Account). On the other hand a FixedAccount class is a specialization of the generic class Accounts.

Thus the Savings class will have data members which the Fixed account might not have but they all will definately contain the members of their super class Account depending on the access specifiers specified and so on. (public, private, protected)

This question has already been answered. Start a new discussion instead.