![]() |
CSC 215 |
|
Midterm solutions |
Listed below are solutions to the midterm.
double getFactor() { double answer; do { cout << "Please enter the factor: "; cin >> answer; } while (answer <= 0.5 || answer >= 1); return answer; }
char getShirtSize() { char answer; do { cout << "Please enter a shirt size: "; cin >> answer; answer = toupper(answer); } while (answer != 'S' && answer != 'M' && answer != 'L'); return answer; }
double hypotenuse(double a, double b) { if (a < 0 || b < 0) { return 0; } else { return sqrt(a*a + b*b); } }
double donutVolume(double r_donut, double r_hole) { const double pi = 3.14159; return 2* pi*pi * r_donut*r_donut * (r_hole + r_donut); }
long sumseries(int m, int n) { int index; long answer = 0; for (index = m; index <= n; index++) { answer += index*index + 3*index; } return answer; }
16 8 4 2 4, 1
1, 1 2, 5 3, 14 4, 30