The struggling college student's GPA Calculator
Jelly, 15 21 bytes (12 with no rounding)
+6 bytes for the strict formatting (almost certainly possible in less but it's bed time)
Oạ69.Ḟ×S×ȷ2÷⁹S¤RLDż”.
A full program taking the grades and the respective credit hours which prints the calculated GPA (Note: the rounding method is to floor, as allowed in the OP).
Try it online!
With no rounding for 12 bytes:
Oạ69.Ḟ×S÷⁹S¤
How?
Oạ69.Ḟ×S×ȷ2÷⁹S¤RLDż”. - Link: list of characters, grades; list of number, creditHours
- e.g. "AFBDC", [5, 2, 4, 1, 2]
O - cast to ordinals (vectorises) [65,70,66,68,67]
69. - literal 69.5
ạ - absolute difference (vectorises) [4.5,0.5,3.5,1.5,2.5]
Ḟ - floor (vectorises) [4,0,3,1,2]
× - multiply by creditHours (vectorises) [20,0,12,1,4]
S - sum 37
ȷ2 - literal 100
× - multiply 3700
¤ - nilad followed by link(s) as a nilad:
⁹ - chain's right argument, creditHours [5, 2, 4, 1, 2]
S - sum 14
÷ - division 264.2857142857143
R - range [1,2,3,...,264]
L - length 264
D - digits [2,6,4]
”. - literal '.'
ż - zip together [[2,'.'],6,4]
- implicit print (smashing) 2.64
Python 3, 66 bytes
-5 bytes thanks to Rod.
lambda g,c:'%.2f'%sum('FDCBA'.find(i)*j/sum(c)for i,j in zip(g,c))
Try it online!
Perl 5, 57 53 + 2 (-an
) = 59 55 bytes
$c+=$F[1];$\+=$F[1]*=!/F/&&69-ord}{printf'%.2f',$\/$c
Try it online!
Edit: swapped the input around to save 4 bytes
Input format: line separated, credits followed by grade:
grade credits
Example:
A 3
B 4
A 1
A 1