473,804 Members | 3,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parallel array

8 New Member
Hello!

Im learning arrays and am having trouble with parallel arrays. I dont understand exactly what they are. Can anyone give me an explanation of what they are or maybe how they can be declared or a small example...anyth ing to help me understand parallel arrays?

Thank you.
Mar 25 '07 #1
2 2292
Killer42
8,435 Recognized Expert Expert
Im learning arrays and am having trouble with parallel arrays. I dont understand exactly what they are. Can anyone give me an explanation of what they are or maybe how they can be declared or a small example...anyth ing to help me understand parallel arrays?
I think I've heard the expression "parallel arrays" once or twice. My guess would be that this refers to the common practice of defining multiple arrays with the same number of occurrences, to hold related information. For instance, you might have one array to hold names, another to hold ages, and so on.

I could be wrong, of course. Try some searches on TheScripts and on the web in general (you can do both from the Search box at the top-right of this page).
Mar 25 '07 #2
SammyB
807 Recognized Expert Contributor
Hello!

Im learning arrays and am having trouble with parallel arrays. I dont understand exactly what they are. Can anyone give me an explanation of what they are or maybe how they can be declared or a small example...anyth ing to help me understand parallel arrays?

Thank you.
Killer's exactly right. For example, you might have an array of people's names and a parallel array of their ages. So, if you search thru the name array and find Sam at index 2, then you you can use the same index into the age array to find Sam's age:
Expand|Select|Wrap|Line Numbers
  1.         Dim Names() As String = {"Killer", "Sam", "Deja", "Sue"}
  2.         Dim Ages() As Integer = {23, 61, 17, 12}
  3.         Dim i As Integer = 0
  4.         Do While Names(i) <> "Sam"
  5.             i = i + 1
  6.         Loop
  7.         MsgBox("Sam is " & Ages(i))
However, since parallel arrays indicate that something belongs together, now we usually create an object to hold all of the parallel data. Doing the example object-oriented, we would not use parallel arrays but instead create a Person object with two properties, name and age, and create List of Persons. Our Person class would look like:
Expand|Select|Wrap|Line Numbers
  1. Public Class Person
  2.     Public Name As String
  3.     Public Age As Integer
  4.     Public Sub New(ByVal sName As String, ByVal iAge As Integer)
  5.         Name = sName
  6.         Age = iAge
  7.     End Sub
  8. End Class
And our object-oriented code would look like
Expand|Select|Wrap|Line Numbers
  1.         Dim Persons As List(Of Person)
  2.         Persons = New List(Of Person)
  3.         Persons.Add(New Person("Killer", 23))
  4.         Persons.Add(New Person("Sam", 61))
  5.         Persons.Add(New Person("Deja", 17))
  6.         Persons.Add(New Person("Sue", 12))
  7.         Dim p As Person
  8.         For Each p In Persons
  9.             If p.Name = "Sam" Then _
  10.                 MsgBox("Sam is " & p.Age)
  11.         Next
The object-oriented way is probably beyond you now, but by the end of the class you'll be there. Keep smiling, it could be worse: trying to learn all this at 61. :D Sam
Mar 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1749
by: Markus Franz | last post by:
Hi. I have a difficult problem: An array contains several different URLs. I want to load these websites in parallel by using a HTTP-Request. How can I do this in PHP? Up to now I did this with an external Python script because Python offers process control functions. But in PHP only exist restricted possibilities for using threads / processes.
6
3534
by: Xiaozhu | last post by:
say, if you had parallel arrays containing the sales person id, the month, and the sales figures (for that person in that month), sorting on sales figure and preserve the order of figures within the data about the same person: Original Data: id month sales +-----+ +-----+ +-----+ | 432 | | 8 | | 89 | +-----+ +-----+ +-----+ | 123 | | 8 | | 116 |
10
4985
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement, knowledge of fast and practical algorithms is not commonplace." Hume and Sunday, "Fast String Searching", Software - Practice and Experience, Vol. 21 # 11, pp 1221-48
11
5289
by: Timothy Smith | last post by:
hello people. i've been trying to send an 8 byte string to my parallel port under freebsd. the purpose is it to control a relay board. the board simply responds to the output byte coming from the port. eg. 00000001 will set pin 1 high and flick the relay open. todate i've attempted this with merely open() on /dev/ppi0 and numpy for the byte array, but i just can't seem to get it working. i know the parallel port works and i know the...
1
1808
by: kmuz08 | last post by:
Hello to everyone, I have to do a project in my discovering programming class based on creating parallel arrays for an order form. I am still not completely sure was a parallel array is! But basically any help, tips, pr tricks would help. My program is to allow the user to enter the name of a product, the product number or serial number, the quantity, and the cost per item and have them all displayed in different parrallel...
9
1853
by: IamIan | last post by:
I'm using an array to store map features (name, lat, lon, caption, etc), from which the user can then select an individual feature. The problem is that when thousands of features are stored in the array, looping over the entire array looking for a match is SLOW. So I'm running a hash in parallel, where every time a feature is pushed onto the array it's name is also added to the hash as an identical key value pair. I then check if the key...
2
15495
by: simo | last post by:
Hello to all... I am trying to write an algorithm parallel in order to realize the quicksort. They are to the first crews with C and MPI. The algorithm that I am trying to realize is PARALLEL QUICKSORT with REGULAR SAMPLING. The idea on the planning is right. the code that I have written syntactically does not only have problems that it does not want any to know to work... Are two days that I analyze it but I do not succeed to find the...
3
2347
by: darklunar | last post by:
Hello I've been given this assignment where I am to read from a text file of a number of students with a list of their names and GPA. Here is the text: James 3.9 Margaret 3.5 Charles 1.2 Jennifer 4.0
1
1992
by: joor | last post by:
Hi I am a beginner and currently trying to create a small program. I seem to be stuck on the multiplication of their elements. Eg. I have an Array with 4 different prices for 4 different products and have created 2 other Arrays to which I have assigned values through window.prompt(parseFloat) , what I am trying to do is multiplicate the values on the parallel arrays by their corresponding indexes and keep a running total so I can have an...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5516
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.