How to use textures and arrays in CUDA?

C ++ how to use parallel arrays in programming?

  • The data file contains student scores for 3 exams. How do you create a function to read these values from a data file and record the highest value in each exam?. I realize you'd have to set the first value to the highest and keep comparing subsequent values to the last and assign the highest value to the highest number encountered so far till all the numbers have been examined. Usually , the command (given the names test1, test2 test3) inFile>>test1>>test2>>test3; would read the values from the 3 tests. But what if we want it to read each column seperately? My question is how to instruct the program(using a function) to go through the first column first(find the highest), go to the second column(find the highest) and then to to third to find the highest. Here's an example of my data file: Smith 89 91 87 Jones 87 65 98 Bean 50 87 68 Doe 85 68 74...etc Detailed help would be great!! Please use parallel arrays if you can.....Thanks guys..

  • Answer:

    If by 'parallel arrays' you mean 'multidimensional arrays', then something like this might work. Disclaimer -- I wrote this without any testing or debugging. //=======Begin Code Snippet========= int testScores [4] [3]; int highestScore[3]; string ignoreName; // this is a dummy value for (int i = 0; i < 4; i++) { infile >> ignoreName >> testScores [ i ] [0] >> testScores [ i ] [1] >> testScores [ i ] [2] ; //this reads in the name, then the first test score, then the 2nd, then the 3rd (remember that C++ starts counting from zero) for (int j = 0; j < 3; j++) { if ( testScores [ i ] [ j ] > highestScore [ j ] ) { highestScore [ j ] = testScores [ i ] [ j ]; } } // end for loop //=======End Code Snippet======= Keep me posted.

Joe B at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.