There are a number of problems with this:
1) Naming - this method does NOT change the AI attituide, it just gets what the chnage due to buildings is, so yoyu definately shouldn't name it that way (sopmething like getBuildingAttitudeChange() would be more appropriate)
2) As written it calculates the same value in every city, whcuih is the value of all possible buildings since it doesn't check whetehr the city HAS each building before including its contribution. You need an 'if (getNumActiveBuilding(eLoopBuilding) > 0)' test in there inside the loop.
3) I know its only pseudocode so you'd pick this up when you tried to actually compile it, but don't loop over building classes, just loop over buildings directly (i.e. - eLoopBuilding should be you for loop variable)
4) To use it you'll proabbly need to add a loop over cities that calls it and adds up the contribution from each city, to CvPlayerAI::AI_getCivicAttitudeChange(PlayerTypes ePlayer) which currently works out the attitude change due to civics
BTW - it turns out that attitude handling is actually very unusual - almost all building effects are handled in processBuilding() (and almost all civic effects in doCivic()), but attitude calculations are doen totally differently, which is why the pattern for this one is a bit unusual.
So much for it being easy and self-contained.
