This midterm is due at noon on Wednesday, May 5, at the start of class. Late exams will be 10% for every 24 hours after the due date.
This exam is to be worked on ALONE. You are not allowed to work on the exam with anyone else, to consult with anyone else on the exam, to consult on-line references or web sites or chat rooms or whatever. The only resources you are allowed to use for this exam are the textbook, Visual Studio, the previous programs you yourself have written, and the knowledge in your head.
Along with turning in the exam, everyone is required to sign the honor agreement and bring it to class on Wednesday, May 5. I will not grade your exam or give you credit for having done it until I get your signed honor agreement.
To turn the exam in, you should e-mail me four files - a text file containing your analyses of the loops and programs in problems 1-4 and the functional decomposition in problem 5, and the source files for the programs you write in probelms 6 and 7.
Problems 1-4 should be done BY HAND, not by compiling the code and then running it. I'm trusting you here. Don't let me down.
Good luck. If you have any questions, you know where to find me, but it should be pretty straightforward. Don't forget, you get one "Get Out Of Jail Free" card for specialized assistance during the weekend.
1.
a = 256; for(x=0;x<a;x++) { if(x%2 == 1) { x = x*x; } else { a = a/2; } }
int x=1; int a=10000; while(a > 0) { a = a/x; x++; }
3.
#include <iostream> using namespace std; int main() { int num, x, y, total; cout << "Please enter a number: "; cin >> num; cout << endl; for(x=1; x<=num;x++) { total=0; for(y=x;y>0;y--) { total = total + (y*y); } cout << x << " -----> " << total << endl; } }
#include <iostream> using namespace std; #define MAX 10 void crunch(int a[MAX], int b[MAX]); int main() { int x[MAX], y[MAX]; int i; cout << "Please enter " << MAX << " numbers." << endl; for(i=0;i<MAX;i++) { cin >> x[i]; } cout << endl << endl; crunch(x, y); for(i=0;i<MAX;i++) { cout << x[i] << " -----> " << y[i] << endl; } } void crunch(int a[MAX], int b[MAX]) { int i, j; for(i=0; i<MAX; i++) { b[i] = 1; for(j=1;j<=a[i];j++) { b[i] = j * b[i]; } } }
(15 pts)
The factors of 12 are 2, 3, 4, and 6.
I should continue to be asked to enter numbers until I enter a negative number.
(25 pts)
The formula for calculating how far away my shot will land is:
distance = ( (velocity^2) * sin(2 * angle)) / 32.2
I want to enter the angle in degrees, since I know degrees. However, the formula requires that the angle be in radians. The conversion from degrees to radians is:
radians = (degrees * pi) / 180
I get five shots to destroy the castle before the castle guards can get to me and kill me. Your program should let me repeatedly shoot until I either destroy the castle or get killed.
Along with simply judging it based on whether it works or not, your program will also be graded on whether you make intelligent choices about which functions should be part of the class and which ones should be generic functions.
(25 pts)