CS 1073 Scientific Programming
Questions and Answers, Fall 2004

  1. Question (Fri Aug 27 22:19:31 CDT 2004): I'm in your 1073 class and i'm having a problem with the homework.  This is what i have done to try and calculate the angles but the angles come up as numbers less then 1

    Answer: Your formulas are correct, but the angles are coming out in radians, which you will see in calculus, if not elsewhere. For now you only need to know that there are 2*pi radians in a circle of 360 degrees, so that to convert radians to degrees you just need to multiply by 180/pi. [To convert degrees to radians, multiply by pi/180.]


  2. Question (Sun Sep 19 21:15:15 CDT 2004): I have a problem in finding the area. I input a correct formula for the area. But the answer output is negative 0. (-0.0) . And i don't know what is wrong with it. Would you please tell me my error? A computer science tutor also checked that error, and he don't know either. Thanks for reading my email.

    [Here are portions of this student's Java Program for Homework 1.]

    Answer: Two mistakes above:
    First: (1/2) will be 0, since this is integer division. You must write either 0.5, or, 1.0/2.0, or even 1.0/2 to get a double.

    Second: You should leave the angle A in radians, since Math.sin assumes radians. Thus instead of changing A from radians to degrees with A = A *180/Math.PI; you should just output A in degrees without changing it: System.out.println(A*180.0/Math.PI);

    Or, as you have it, you can change A back to radians in the formula for Area:
    Area= (0.5)*b * c * Math.sin(A * Math.PI / 180.0);


  3. Question (Sat Sep 25 22:22:41 CDT 2004): I am having the worst time putting all of this together. The attached is my attempt for the natural exponent (first part of Homework 2). My result is short by over one. I love mathematics, but I hate computers. Does that make any since?

    Answer: Computers are getting ever more essential for mathematicians. That's one reason you're required to take a programming course. When you know more about programming, you may not dislike it.

    Now, about your programming segment -- you can't have each individual term depend on n. The terms depend only on k, and in the end there are n of them.

    The idea it to realize that the kth term is just 1.0/k times the previous term (the (k-1)st term. This hint ought to be enough to help you along.


  4. Question (Sun Nov 7 16:06:35 CST 2004): I am having trouble with the Homework 4. I see that I need a method that will count down from 99. Then it should convert that to English and concatenate the verse strings. I just don't see how.

    Answer: Not a method to count down, but inside printSong: "Use a loop with a variable going from 99 down to 0." This is a for loop, and you can see a similiar backwards counting for loop at the end of:

    Inside this loop, for each value of i between 99 and 0, you mostly just print the same things, that is, some of the strings that have been defined for you, such as shortB, longB, or wall. You also have to print the actual number, the "Twenty-seven" when i is equal to 27. Here you should use the toEnglish function (method), which you should write. This function has an input parameter: an int between 99 and 0. Assume for right now it is 27. In this case i/10 will be 2 and i%10 will be 7, and ones[7] will be "seven", and tens[2] will be "Twenty". These strings can be concatenated together (along with "-") to yield a string that you should return from toEnglish. Numbers from 0 to 19 should be handled using the other array of strings.