Hey could someone please point me to a website which shows you how to remove duplicates of a list container of a class that have the same name, but change the int to be an average of both values in the class?

class product{
           string name;
           float rating;
}

so if the data read was "iPod 5 iPod 9" ipod being the name and the number after it the rating, how would i search for and remove the second iPod entry and make the first rating change to rating = 5+9/2

Sort by name order, do a total of the ratings.

Remove all occurences of the name and replace with name and rating - for all names.

cool thanx, could you please show me a link to some code? ive pretty new to containers and cant find any examples relating to lists of classes

cool thanx, could you please show me a link to some code? ive pretty new to containers and cant find any examples relating to lists of classes

[humor]
Yeah sure, why not. imthwee is quite good at it. ;)
[/humor]

cool thought i might give maps ago :P just one little problem

is it possible to have 3 types of data in a map container? having the name as the key, the rank as the second, and the number of times it has been ranked as the third?

pair<string, int> readin;
	pair<mapit, bool> ret;
	getline(ins, readin.first);
	ins >> readin.second;
	ret = product.insert(readin);
	ins.ignore();
	if (!ret.second)
	{
	//cerr<<"Duplicate entry."<<endl;
                // add readin.second to previous instance of name		
	}

is it possible if the name is a duplicate, the add the second to the previous instance of that name... then devide it by number of times its been added to find the average?

maps only take two values. For your purposes one value can be a structure that contains the two numbers you want.

map<vector<int>, std::string> theList;

Consider a map of pair std::map<keyType, std::pair<int,int> > theMap; The solution is more or less like post#8 but pair would be more efficient.

This article has been dead for over six months. Start a new discussion instead.