Thread: comparing inputted text to text in a file

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    2

    comparing inputted text to text in a file

    Hey

    I am having a little trouble with this one. I have stored specific data in a .res file. In the format:

    Field Point no. of ray time of arrival

    For a specific field point I have on average 3 rays with three corresponding time of arrival so a list is looking like this.

    Field Point no. of ray time of arrival
    (x,y,z) 0 89
    (x,y,z) 1 66
    (x,y,z) 2 54

    I now want the user to be able to input the time of arrival and give me back the field point which corresponds to the 3 specific time of arrivals.

    The problem is for another field point you may have the first two time of arrivals same but not the third one.

    Any help wud be great,
    Cheers
    Ailis

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    how about a class/struct called timePt which has an array of three ints (one each for x, y, and z) and an array of three time structs, one for each arrival time. Each time struct could have two ints, one for the hour and one for min. You read the material from the file into a container and then ask for user the time inputs. Then you search the container for the given time inputs and print out the x, y, and z values of the timePt that corresponds to the arrival times.
    You're only born perfect.

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    2

    only problem

    I have all that done.
    Sorry my question mainly was how do i search the file.

    Thanks
    Ailis

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Depends what you have so far. If you have the timePts from the file in an array or a vector then you can use a loop to run the array. If you have the timePts in a map then you can use the [] operator to look for a given timePt (not my first choice of containers, but you might be able to get it to work). If you have a tree or a list, then you can use a loop or recursion. Let's say you like to use vectors.

    Then you could:
    Code:
    declare timePt class to include: 
    a data member which is a vector of ints called pt
    a data member which is a vector of arrivalTimes
    an overloaded << operator which displays the pt vector
     
    declare an arrivalTime class to include:
    an int for hour
    an int for minute
    an overloaded == operator
     
    declare a vector of timePts called v to hold the timePt data from file
     
    use an ifstream to read each timePt from file into v
     
    The goal is to look for a timePt in v with three unique arrivalTimes supplied by user so:
     
    declare a vector, desiredATs, to hold the desired arrivalTimes supplied by the user and obtain user input for each arrivalTime
     
    declare iterators to run the vector of timePts:
    std::vector<timePt>::iterator start = v.begin();
    std::vector<timePt>::iterator stop = v.end();
     
    use a loop to do the running from start to stop
       within the loop check start->arrivalTimes vs 
       desiredATs for equality
    	  if equality found then display value in start using the 
    		 << operator
    	  and break out of the loop
    if you aren't familiar with vectors but you know about arrays and you can write your own list then you could:
    Code:
    declare timePt class to include: 
    a data member which is an array of ints called pt
    a data member which is an array of arrivalTimes
    an overloaded << operator which displays pt
     
    declare an arrivalTime class to include:
    an int for hour
    an int for minute
    an overloaded == operator
     
    declare a node struct to include:
    a timePt called data
    a pointer to another node called next
     
    declare a list of nodes called v to hold the timePt data from file
     
    use an ifstream to read each timePt from file into a new node and add the new node to v
     
    The goal is to look for a timePt in v with three unique arrivalTimes supplied by user so:
     
    declare an array called desiredATs to hold the desired arrivalTimes supplied by the user and obtain user input for each arrivalTime
     
    declare a node pointer called currentNode to run the list
     
    use a loop to do the running from currentNode equals head until currentNode equals NULL
       within the loop check currentNode->data.arrivalTimes vs 
       desiredATs for equality using a second loop to see 
       if each arrivalTime in desiredATs is in currentNode->data.arrivalTimes
    	  if the two arrays match display currentNode->data 
    	  using the << operator
    	  and break out of the loops
    At least I think that approach will work. I haven't actually written code to confirm it.
    You're only born perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM