Attack bonuses against units do not apply when attacking cities. The strength a unit adds varies mainly depending on it's own strength and current hp, and whether you have Oligarchy or not.
As for the strength formula, I looked at the code and this seems relevant:
Looks like city strength depends on the following:
- Number of techs
- Defensive buildings
- Garrison unit
Specifically, the part concerning units:
// Garrisoned Unit
CvUnit* pGarrisonedUnit = GetGarrisonedUnit();
int iStrengthFromUnits = 0;
int iMaxHits = GC.getMAX_HIT_POINTS();
iStrengthFromUnits = pGarrisonedUnit->GetBaseCombatStrength() * 100 * (iMaxHits - pGarrisonedUnit->getDamage()) / iMaxHits;
iStrengthValue += ((iStrengthFromUnits * 100) / /*300*/ GC.getCITY_STRENGTH_UNIT_DIVISOR());
So the formula for the strength a unit adds seems to be (Unit Combat Strength * 100) * Current Unit HP / Maximum Unit HP. This value is then apparently multiplied by 100 and divided by CITY_STRENGTH_UNIT_DIVISOR (which is 500 according to GlobalDefines.xml). Then in
iValue *= /*40*/ GC.getCITY_RANGED_ATTACK_STRENGTH_MULTIPLIER();
iValue /= 100;
it is multiplied by CITY_RANGED_ATTACK_STRENGTH_MULTIPLIER (which is 75 according to GlobalDefines.xml) and divided by 100.
iValue *= (100 + GET_PLAYER(m_eOwner).GetGarrisonedCityRangeStrikeModifier());
iValue /= 100;
it is multiplied by 100 + GetGarrisonedCityRangeStrikeModifier (which seems to be 0 normally and 100 with Oligarchy according to CIV5Policies.xml) and divided by 100 again.