The program below makes two classes that when calling their generate functions in a .cpp file generates a list of soldiers and then a separate list of skills, I want to combine these 2 lists,that way you can say Soldier 1 has skill 1,4,7 while Soldier 2 has 3,4,5,6,7,8. How would I go about putting these two lists together? In the end I want the user to be able to type in a group of skills he is looking for and then the program make a team consisting of 5 soldiers where each skill the user specified is held by at least two members

class skill
        skill(int i){x=i;}
        bool operator == (skill s){return (x==s.getx());}
        void operator = (skill s){x=s.getx();}
        void display(){cout<<"a"<<x<<" ";}
        void generate1(list<skill>*S);
        int x;


class soldier
        soldier(int i){x=i;}

        bool operator == (soldier s){return (x==s.getx());}
        void operator = (soldier s){x=s.getx();}
        void display(){cout<<"S"<<x<<" ";}
        void generate2(list<soldier>*S);
        int x;


Don't think about it as a list within a list.
Rather, a Soldier has a list of skills.
When you want to know a Soldier's skills, you look at its list.

okay Ive attached a soldier with his list of skills, now Im pretty much stuck on how I would go through the list after the user inputs which skills he is looking for 1-10 and best pick out 5 soldiers to go on a team that meets the requirement of every skill needs to be held by at least two members on the team.

There will be a list<Soldier> inside Skill class. So every instance of the skill class will have the list of soldiers who are having that particular skill. Now for particular skill, Soldiers can be selected.

You would need a function that checks the list for the given criteria.
...and create a NEW list of soldiers with that criteria


for(int i=0; i < numSoldiers; i++)
   Soldier soldier = lstSoldiers[i];


How would I go about writing a display for this class? Because its imputing a file as a parameter,can't for the life of me find how I would get the numbers inside the list to display.

*Edit* Never mind answered my own question on that one

Edited 4 Years Ago by Hiiero: n/a

Though when I have a list that contains a list in it,how do I pull a single object out of the 2nd list to compare it with something else?


class team
        team(int i,list<skill>*Slist){x=i;s = *Slist;}

how would I go about getting a specific value out of team Slist??To get i, I just wrote a getx function that returned the value of x in integer form....

Im trying

        int gets(){
                 a =  sk->getx();
                 return a;


but I am only getting the first item in the list to print out,not the rest of the items.

With that code, you have a return statement inside a while loop.
As soon as it gets to the first element, it will return.
Also, I thought you were interested in returning a LIST of skills, not just an integer.

How would I erase the current team object out of the list at this point and time, I tried doing T.erase(titr) but it crashes in the middle of the program. Im trying to do checks and if they are met I am trying to move the current team to a new list and delete the current team from the old list

for(int i = 0;i < v;i++)
                           skptr = new skill(d[i]);
                           tptr2 = new team(titr->getx(),&S1);

To answer your other question about the display:
Just remove the display functions from inside the class.
Return to the user the "data" that needs to be displayed OR return a pointer to the element that is going to be displayed.

That way, you can use this in a CGI or game or other without needing to change the "direction" of the output.

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