![]() |
CS 2073, Engineering Programming
|
Answer: You are getting ahead of the class (which is fine). I will go over all this in class, but most of the answers are in the directions for running a program, which include directions running and for making up a file to email to me: Running directions.
If you are using Microsoft Visual Studio 6.0, first use the directions: Using Microsoft Visual C++ 6.0. After that use the directions: Making up a file for program submission.
If you are using the Bloodshed system, then you should also need the directions clear at the end: Under Bloodshed, keeping the black box from disappearing.
area = sqrt(s(s - a)(s - b)(s - c));
Answer: I talked about this a little in class. In the formulas for area, I used mathematics notation, rather than C. In mathematics, if you write s(s - a), it is assumed that these two items are multiplied together, but in C there must be an explicit * as a multiply operator : s*(s - a)
Answer: For each of the number of times to compound: 1 , 10 , 100 , 1000 , 10000 , ... I want a single number printed: the result of applying 100% interest to 1 dollar for 1 year, compounded the given number of times. A single number is what your program from Part 2 would print if you do it correctly. I gave the number that should be printed in case compound == 1 (2.0) , and the number that should be printed in case compound == 12 (2.613035290224) , although your final program would not be using 12 as the number of times to compound, but instead 1 , 10 , 100 , etc.
double amount;
double rate;
int years;
printf("Enter amount, rate, years:");
scanf("%if %if %if", &amount, &rate, &years);
Answer: scanf and his brother printf are tricky and error prone. Usually you don't get any error message, but it just doesn't work right. In this case you are using "%if" to scan a double, instead of "%lf". The code runs, but the numbers come out 0.0 or worse.
Answer:
This is a standard problem that is on the course webpage.
Click on "Running" on the main page, to go to:
Running
a program
and look at the bottom.
Answer: I suggested that you continue the loop as long as x1 and x0 are not within epsilon of one another, or that you break out of the loop when x1 and x0 are closer than epsilon apart. Since we don't know which of these is bigger than the other, we need to take the absolute value of their difference (not as you have: "the difference of the absolute values"):
if (fabs(x1 - x0) < epsilon) break;
You (the person asking the question) also had another standard mistake: you were checking how close the numbers were after doing the assignment: x0 = x1; But after this, the numbers will be equal, so that fabs(x1 - x0) will always be zero.
Answer: You are still using the same function cos(x) - x, but there is no need for the derivative. (The second part is a simpler approach that does not use calculus, although it may be harder for you to program.)