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
2 answers

How do I get shuffled arrays in a list to match up with each other in Java?

I am new to coding and I wanted to know how I can code this program so that the arrays are matched. (apples and the number 1 match, bananas and the number 2 match and mangos and the number 3 match) I've used assert fruits.size() == numbers.size();…
Kristie
  • 31
  • 6
0
votes
0 answers

Where are the parallel arrays in this c code?

#include #include int main() { int no_candiates; int no_regions; int details[100][100];//for the votes in each regions char names[100][100];//for candidate names int total[100];//total votes of each candidate int…
Niafo
  • 1
0
votes
1 answer

How can I fix two classes that won't show the output?

I am trying to get the Team Roster and Coach class to show the output, however, when I run the program it doesn't produce the output. It only produces the first-class but after that, no output is shown. public class Team { public static void…
Quoc Le
  • 1
  • 2
0
votes
1 answer

How do I create parallel arrays from a .txt file with two columns?

I am working on an assignment where I have to create a program that the user can personalize the options in buying a new car. I have a .txt file with two columns, one column has the price(double), the other column has the option(string). I want to…
0
votes
1 answer

MongoDB.Driver.MongoWriteException: 'A write operation resulted in an error. cannot index parallel arrays'

[BsonId] [BsonRepresentation(BsonType.ObjectId)] public string Id { get; set; } [BsonElement("Prop01")] public int Prop01{ get; set; } [BsonElement("Prop02")] public int Prop02{ get; set; } [BsonElement("Prop03")] public string[] Prop03{ get;…
Salman Elahi
  • 11
  • 1
  • 5
0
votes
1 answer

Why is my parallel array displaying random values?

I am supposed to use a parallel array to show how much a cup of coffee is based on what add-in is added. The original cup of coffee is 2 dollars. I am mostly confused with how to output the correct results. Currently, it will output saying "Order…
Gabby
  • 41
  • 5
0
votes
2 answers

Returning a string from a parallel array

I am sorry for the very newbie question, but this is driving me mad. I have a word. For each letter of the word, the characters position in one array is found and then returns the character at the same position found in a parallel array (basic…
user753420
  • 225
  • 1
  • 2
  • 5
0
votes
1 answer

How to accept user input into two parallel arrays

I need to accept a String input and a double input from a user and store them into two parallel arrays to create a shopping cart. I have initialized both arrays to a user determined size Amount and created a for loop to run for the inputs and store…
0
votes
1 answer

Im using JOptionPane and I'm not sure why its not working when I try to enter the Item Id for the first "?" it asks in my code

A company manufactures 10 items. write java program to store 10 items and their prices in arrays. if a customer ordered an item, your program checks whether it is valid, if it is valid print price import javax.swing.JOptionPane; public class…
Kale_Kyle
  • 1
  • 4
0
votes
1 answer

How can I use parallel arrays to make a list with quantities and words using c++

I'm stuck on trying to add quantities to this list when it returns the output. It is essentially a list entered by the user that starts with a quantity and is followed by a word. It is then supposed to output the same list but in alphabetical order.…
Hannah B.
  • 23
  • 3
0
votes
1 answer

How to write a constructor that accepts a single argument?

I am creating something like a kiosk program where you order food from using windows forms. I have to create a Toppings Class where it contains three fields that are arrays. ToppingList as an array of bool ToppingNames as an array of…
0
votes
0 answers

'fgets()' in a 'for' loop asks for input just once

I'm making a program which asks the user to type a list of 5 products and their price. Both the names and the prices are stored in two parallel arrays which will be later be used together to output the price of each product. The function used to ask…
user10071821
0
votes
1 answer

Write a program that stores the name as a String and number as int's of 11 players

How do I get the average points from each player of both games? Write a program that stores the name as a String and numbers as int's of 11 players on a team. Your program should display/output the average points scored of each player over the two…
Ian Adams
  • 21
  • 2
0
votes
1 answer

C# - Use parallel arrays to calculate cost of a phone call in GUI

all. Student programmer here, more than a noob but struggling with arrays. I have a homework assignment that I turned in for half the points a few weeks ago because I couldn't get the parallel arrays to work. We were asked to create a GUI to…
0
votes
1 answer

Having trouble outputting to a output file

In c++ can you output to a output file then reopen the output file again to output something else under the original output. for example, I open the output file then output the heading then close the output file. Then reopen the output file and…
Ken Casimiro
  • 85
  • 2
  • 9