Hey.. Names Jay..

I'm new around here.. Doin C++ and i'm a beginner programmer.. I have been going OK but i am stuck!!

For this assessment i have to create a payroll system for a company..

The company must contain staffmembers.. There is a class for staffmembers.. Inheriting frmo this staffmember class, are 3 other classes, (Manager, Casual, Salesperson).

In the company class, these 3 types of staffmembers must be stored in an array..

Using the interface we must create, we must be able to insert a users ID, and from their, be able to edit the specific staffmembers details..

My Dillemma:

How to add the members into their correct array after construction:

(The following is my constructor for a manager)

int managercount = 0;
manager::manager():staffmember()
{
 salary = 0;
 managercount++;
}

Now i FIGURE i could somehow insert the manager into the themanagers[] array from my company class.. But i am not sure how..

MY IDEA: considering the interface will be used to create these members of staff.. I could create each object using a number system, such as there staff id.. **I am aware i would need to convert that from into to string.. or maybe char? I'm not sure** Therefore: it would be something SIMILAR to below.. However i don't know the correct syntax:

string object_temp;
object_temp = staffID  //.. staffID is a static int counting how many staff members have been created and then giving the next number to the next staffmember as their staff ID.. 
 
manager object_temp();

If i'm correct, with the correct syntax.. This would make it possible to create an insert function which looked something SIMILAR too (again my syntax is lame because of my lack of knowledge regarding the language so far):

manager::insert(staffID)
{
    int ID_temp;
    ID_temp = staffID - 1;
 
    themanagers[ID_temp] = staffID // being that the staffID is also the identifier of the object
 
}

If anyone has an EASIER idea.. Please contact me!! Or if you can help with any of the syntax here i'd be thankful.. Or even a resource already available which may help me?

I apologise for the long post and i also apologise if i have caused anybody discomfort for having to try and understand my jibberish!! ;)
THANK YOU!!!

Do you mean add new members to an array that's already been declared? That's not possible. You'll either have to use vectors or a linked list. Linked lists look like this:

class LinkedList {
   public:
   int mydata;
   // etc..

   LinkedList *next;
};

Where next points to the next node in the structure.

Vectors are similar in the fact that they too can dynamically add data, but they're really classes that are templates. For example:

std::vector<classtype> classvector_instance;

And then you can add or remove nodes by using the vector's member functions push and pop , respectively.

Then all you'll need to worry about is the class constructor, and not bother with an insert member function.

More information on linked lists and vectors:
http://www.fortunecity.com/skyscraper/false/780/linklist.html
http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4027/

Hope this helps

Awesome.. Thank you!!I'm working on the idea of using vectors.. I THINK i have the concept behind it, however, i'm not sure where to put each part of the vectors.. For example, would it go in my header file as follows:

//company.hclass company{    public:              //..functions go here    protected:              vector themanagers(20);           // making vectors with room for 20, 50 and 50 in order              vector thecasuals(50);              vector thesalesstaff(50); };

And then to use these in there respective class, i am sorta lost after that.. Do i need an iterator (if so how/what does this do).. And then where do i put the syntax to put the managers into the vector? I have a feeling i've turned something simple into something confusing.. Please help me fix that.. lol..Thanks..
***Please excuse the code bein all messed up.. I can't seem to get it to go normal :(***

No, the syntax of vectors is different, and you don't need to declare how many nodes are going to be in it (although you can, but in this case it's kind of pointless), you just add them as you ned them:

class company {

   // ...



   protected:

   std::vector<managers> themanagers;

   std::vector<casuals> thecasuals;

   std::vector<salesstaff> thesalesstaff;

};



// eg.

themanagers.push_back(/*initalization data for constructor*/);

And then you can access any node in a vector exactly the same as you would a regular array.

themanagers[index_var].member_data = whatever;

Hey mate.. Thanks for the help and patience!!I have added the correct syntax into my header file.. as you said

protected:
       std::vector themanagers;
       std::vector thecasuals;
       std::vector thesalesstaff;

Now in my interface, i want to make it so that, a staffmember can be created, and then it will be added to the vector.. Below is how i ATTEMPTED to do this..

string temptype;
 string object_name
 cout << "Please enter a UNIQUE name for this staff member object: ";
 cin >> object_name;
 cout << "Please enter the type of staff member you would like to create." << endl;
 cout << "Either 'casual', 'manager' or 'salesperson'. : ";
 cin >> temptype;
 cout << endl;
if (temptype == 'casual')
{
   casual object_name();
   thecasuals.pushback(object_name);
}
//... Repeat else if for the manager and salesperson types..

PS: My code messed that up in the previous post.. Sorry.. :)

Sorry about the late(ish) reply! I had this post written, and then my computer messed up, so I wasn't able to post it.

string object_name

Missing semicolon.

if (temptype == 'casual')

Use double quotes for a string, not singles.

Vector syntax looks good, though!

Sorry for MY delay on my OWN forum post.. I have been at a job interview all day... Ok i believe i've made progress.. With one compiler error.. I'm not sure why the compiler error is happening.. therefore imma post it here in hopes it is understood..

//.. client.cpp
 
 string temptype;
 string object_name
 cout << "Please enter a UNIQUE name for this staff member object: ";
 cin >> object_name;
 cout << "Please enter the type of staff member you would like to create." << endl;
cout << "Either 'casual', 'manager' or 'salesperson'. : ";
 cin >> temptype;
cout << endl;
if    (temptype == 'casual')
   casual object_name();
   thecasuals.add_casual(object_name);
}
//.. rest of the else ifs

Now that is calling an add_casual function which contains the following

void company::add_casual(casual casname)
{
   thecasuals.pushback(casname);
}

All SEEMS GREAT except 1 error in compiling.. Which says

error C2664: 'add_asual' : annot onvert parameter 1 from 'class casual (void)' to 'class casual'
No constructoer could take the source type, or constructor overload resolution was ambiguous

I don't know why.... :( I just really need to get this done.. Due friday before 5pm.. It is currently 8:27pm wednesday.. And i've been working on it for weeks :( lol.. So difficult..

Thanks for any help again..

if    (temptype == 'casual')
{ // I think you missed this brace here.
   casual object_name; // Removed the brackets. 
                       // causal object_name() is a function called object_name that returns a causal object. 
                       // You want a instance of class causal.
   thecasuals.add_casual(object_name);
}
//.. rest of the else ifs

And you should read mr. joe's post again:

if (temptype == 'casual') => if (temptype == "casual")
string object_name => string object_name;

Ahh yes!! Thank you!! lol!! All that for some brackets..

Well i got it compiled.. Now i need to work out how to access all the 'casuals' in this vector.. to print all their details, eg, staff_id and functions.. And the rest of it.. Thank you both for your help!! If i get stuck i will post a new forum post tonight/tomorow some time.. I will be working on it for the next 48 hours straight!!

Oh and thanks niek.. But i had already fixed them but all my code is on my laptop and i simply copy and pasted snippets from my previous posts.. So no need to seem attitudey :P

Marking as solved :D

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