Thread: Help with Programming Assignment

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I don't know what you learned in class, but the basic rule when you are reading from a file is: the read statement should be your while conditional, e.g.
    Code:
    while(tunnel>>myVar)
    {
    
    }
    tunnel>>myVar calls a function that reads data into myVar and then returns the object tunnel, leaving you with:

    while(tunnel)

    The tunnel object will evaluate to false in the while conditional if any errors have occured that will prevent you from reading anymore data from the file. eof is considered an error, so the while loop will terminate correctly when you reach the end of the data without having to count the data.

    However, there are other possible errors that can occur while reading from a file. If one of those errors occurs, your current while loop will try to keep reading data because it hasn't encountered eof yet(and the counter hasn't reached 17)--but the error will prevent you from reading any data, and you won't know that you aren't reading in data. After the loop terminates due to the counter reaching its max, you'll think you successfully read in 17 lines of data. If you put the read statement in the while conditional instead, the loop will end immediately if there's any error, so you can check a counter to see if you read in 17 pieces of data and therefore you are good to go.

    By the way, the instructions say the data is in ascending order by flight angle, so while your maxval() and minval() functions would apply to data that isn't ordered, the minimum angle is actually just the first angle in the data file, and the max angle is the last angle in the data file. Your instructor apparently wanted to make the assignment easier and eliminated the need to write those functions. If I were you, I would read the data into a two dimensional array. Row 0 will have the angle in column 0 and the lift in column 1, row 1 will have the next angle in column 0, and the next lift in column 1, and so forth.

    Then prompt the user to enter an angle. After that, check that the angle is within the range: if it isn't display an error message, and prompt them again. If it is within the range, then start at row 0 in your array and check to see if the angle in column 0 is larger than the given angle. Check the rows until you find the first row whose angle is larger than the given angle. Record that row number. The angle that is lower than the given angle will be the recorded row number minus 1. That will give you the two rows whose angles surround the given angle. The lifts are in the second column of each of those rows. Then you do the math to find the lift and display it.

    Work on that for awhile.
    Last edited by 7stud; 11-06-2005 at 02:05 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM