CS 2073, Engineering Programming
Questions and Answers, Spring 2006

  1. Question (Sun Jan 22 16:48:40 CST 2006): I finished the trianle.c and the quadratic.c programs already. When submitting the programs you wanted the source code and the output statements. I used the Bloodshed program and also Borland C++ 5.0, both of which output to a command prompt/command shell in windows. How would I go about printing out the results when it comes out on the command shell?

    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.


  2. Question (Tue Jan 24 13:02:59 CST 2006): In program 1, I am trying to compute the area using the formulas you gave us, but I just keep getting the following error: "'s' cannot be used as a function". Here is where I calculate the area:

    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)


  3. Question (Sun Feb 5 16:06:29 CST 2006): On program 3 in the very last part of the program, where you are calculating the compound interest at various compounds; I am having problems understanding what exactly you want done.  So do you just want an output of the compounded interest rate (in the loop) or do you want the total or all of the compounded interest rates applied to the 1 dollar?

    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.


  4. Question (Thu Feb 9 20:04:52 CST 2006): I'm having trouble with the following to input numbers in program 3:

    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.


  5. Question (Fri Feb 10 22:01:18 2006): How do i keep the bloodshed command screen [the "black box"] to stay open, since it automatically closes after it finishes?

    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.


  6. Question (Tue Feb 14 13:27:04 CST 2006): In program 4 what is the purpose of asking the difference of the absolute values of x1 and x0.

    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"):

    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.


  7. Question (Tue Feb 14 13:53:35 CST 2006): In the second part of program 4, are we still using the function cos(x) - x and its derivative?

    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.)