Questions tagged [parallel-arrays]

Use for questions about using in separate array per field (I.e. `name[10], subject[10], grade[10]`.) to store structured records instead of array of objects with fields/properties.

This tag is for questions that concern usage of multiple (parallel) arrays to store records in array-per-field manner (vs. using classes to store fields of an entity together and than have a single array of such entities). See Wikipedia for more information.

Example of parallel arrays (JavaScript-like language):

   var names = ["Bob", "Alice"];
   var subject = ["Crypto", "Compression"];
   var grades = [9002, 9001];

Same data as objects:

   var students = [
     {name:"Bob", subject: "Crypto", grade: 9002},
     {name:"Alice", subject: "Compression", grade: 9001}
   ];

Cases when you would use parallel arrays:

  • arrays is the only data structure you know or "should" know depending on how far you in the programming course. If that is the case make sure to clearly spell out in the question, especially if assignment in question calls for using arrays.
  • your specific case shows significant benefits of using parallel array to store the data. Add reasoning and, ideally, performance measurements to the question. Expect alternative suggestions to represent the data as valid answers.
71 questions
0
votes
0 answers

Tracking scores with parallel arrays or single multidemensional array

I have to write a program that keeps the statistics for a basketball team of 10 players. The statistics are shots attempted, made percentage; free throws attempted, made percentage; offensive and defensive rebounds; assists; turnovers and total…
VinceCat
  • 25
  • 3
  • 14
0
votes
4 answers

how do i match the index of two parallel arrays?

i have a list in a text file that alternates between name and age. there are 9 names and 9 ages. i need my program to display Person (insert name here) has the highest age: (insert age here). here is my code so far: public class Names …
user1556084
  • 29
  • 1
  • 3
  • 12
-1
votes
1 answer

reading from file and storing into array C++

I need to write a function that reads from a file and store the values into parallel arrays. In the text file I have a name and on the next line I have a set of 4 scores. Any tips on how to achieve this. here is an example of the text file joe 30…
BrokenCodez
  • 53
  • 1
  • 8
-1
votes
1 answer

Trouble with filling parallel arrays from file while checking for existing elements

The program's purpose is to fill two arrays from data in a file, the first column is department number, and the second is boxes sold. There should be a max of 15 departments, variables departmentNumber and boxesSold should receive data from file…
mattvondu
  • 1
  • 3
-1
votes
2 answers

How to calculate comparation percentage of 2 arrays?

How can I get a percentage of right answers if I have 2 arrays in PHP or javascript, preferably in PHP? So, I have these two arrays and I want to compare a quiz result with the correct answers and get a percentage score: $quiz_results = array( 'q1'…
Ionut Necula
  • 11,107
  • 4
  • 45
  • 69
-1
votes
1 answer

c++ declaring arrays as functions

i'm facing some problems with the array, as I have my .h and .cpp files so do i declare them as per norm of how we usually declare a function? pointtwod.h class PointTwoD { private: int xcord,ycord; float civIndex; …
user2900611
  • 67
  • 2
  • 10
-2
votes
1 answer

How do i get names outputted when i read a file

i am having trouble with reading names from a file the file contains a name and their score #include #include #include using namespace std; int main(){ // ifstream reader; const int arraySize=100; //storing names and…
victoria
  • 1
  • 1
-2
votes
3 answers

read from file as parallel arrays in java

This is my code to read from file and display in console try { BufferedReader readFile = new BufferedReader(new FileReader("sales.txt")); String line = ""; while((line = readFile.readLine()) != null) { …
Konstantin F
  • 180
  • 1
  • 15
-2
votes
3 answers

double array won't print

I did some more work on this program, but now I am stuck because the string array prints, but i cant for the life of me get the double array to print. Any help would be appreciated! import java.util.ArrayList; import java.util.Arrays; import…
-3
votes
1 answer

Sorting and searching parallel arrays?

The following problem is a homework assignment (I'll list the problem first then my coding)... Looking forward to hear from you. Problem: Design a program that has two parallel arrays: a string array named people that is initialized with the names…
-5
votes
1 answer

Parallel Arrays for toys made by elves c++

I would really like help with this program, as I can't figure out what to do. I've tried searching online for answers or something that would point me in the right direction, but this is sort of difficult for me since I'm just learning how to code.…
1 2 3 4
5