Let total number of students in class be x.
Let cost of food for each student be y.
∴ Total cost of food for x students:−
⇒x×y=960 .... (1)
So, now according to given condition when 8 students fails to go on picnic and cost of food increases by 6 for each student
∴(x−8)(y+6)=960.... (2)
Solving (1) and (2), we get
6x−8y=48
⇒x=8y+486
Substituting in (1), we get
8y+486×y=960
⇒8y2+48y=960×6
⇒y2+6y=720
Solving this quadratic equation, we get
y=24, ignoring negative value since y can't be negative
∴x=40
∴ Total number of students in class =40 → (Answer for (ii))
Total number of students who attended picnic=32 → (Answer for (i))