Welcome to Dream.In.Code
Getting Help is Easy!

Join 117,607 Programmers for FREE! Ask your question and get quick answers from experts. There are 2,456 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Parallel Arrays

2 Pages V  1 2 >  
Reply to this topicStart new topic

Parallel Arrays

cavvysri
post 16 Jun, 2008 - 08:32 AM
Post #1


New D.I.C Head

*
Joined: 12 Jun, 2008
Posts: 29


My Contributions


can anyone give any pointers on Parallel Arrays?
User is offlineProfile CardPM

Go to the top of the page


jayman9
post 16 Jun, 2008 - 08:48 AM
Post #2


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,445



Thanked 27 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


What specifically do you not understand about parallel arrays?
User is offlineProfile CardPM

Go to the top of the page

cavvysri
post 16 Jun, 2008 - 08:57 AM
Post #3


New D.I.C Head

*
Joined: 12 Jun, 2008
Posts: 29


My Contributions


QUOTE(cavvysri @ 16 Jun, 2008 - 08:32 AM) *

can anyone give any pointers on Parallel Arrays?

i need to process 2 arrays, and where data is found, it writes out reserved, or on shelf

var borrowedArray = ['-', '-', '-', 'rs-14', '-', '-'];
var reservedArray = ['-', 'ly-44', '-', '-', '-', '-'];

for (var count1 = 0; count1 < indexArray.length; count1 ++)
document.write(count1 + ' ----- ' + bookArray[count1] + ' ----- ' + authorArray[count1] + ' ----- ' + reservedArray[count1] + ' ----- ' + borrowedArray[count1]+ '<BR>')

i know this code is wrong as it just prints out the reservedArray and borrowedArray

User is offlineProfile CardPM

Go to the top of the page

jayman9
post 16 Jun, 2008 - 09:37 AM
Post #4


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,445



Thanked 27 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


Use an If statement to check the value of the array and depending on what it finds, output the word "reserved" or "on shelf" to the document, in place of the array output that you are currently getting.
User is offlineProfile CardPM

Go to the top of the page

cavvysri
post 16 Jun, 2008 - 11:02 AM
Post #5


New D.I.C Head

*
Joined: 12 Jun, 2008
Posts: 29


My Contributions


QUOTE(jayman9 @ 16 Jun, 2008 - 08:48 AM) *

What specifically do you not understand about parallel arrays?

is there something i need to write in it when checking if there is any value in the array? as you can see there are only 2 index's in the arrays currently reserved or borrowed..later on the other indexes will be filled by a user reserving or borrowing a book
User is offlineProfile CardPM

Go to the top of the page

kelbly
post 17 Jun, 2008 - 05:18 AM
Post #6


New D.I.C Head

*
Joined: 15 Jun, 2008
Posts: 8

Hey, im still trying to tackle this one, just wondering if anyone can offer advice as to what i have so far?


CODE
if (readerPassword == readerPasswordArray[count])
            {
                document.write('<BR>'+'<BR>'+'Welcome to the catalog'+'<br>'+'================='+' <BR>' )
                
                
                for (var index = 0; index < bookArray.length; index++)
                var shelfArray = new Array
                (if (borrowedArray[index] == ('-'))
                {
                shelfArray[index] = ('onshelf')
                }
                else
                {
                if (borrowedArray[index] != ('-'))
                {
                shelfArray[index] = ('borrowed')
                }
                })

                
                document.write ( index + ' --- ' +bookArray[index] + '---------' + authorArray[index] +' ----------'  + shelfArray[index] +'<br>'  );
                '<br>'
                document.write ('What would you like to do?'+ '<br>' + '<br>')
                document.write('1. Reserve a Book'+ '<br>')
                document.write('2. Borrow a Book'+ '<br>')


var borrowedArray = ['-', '-', '-', 'rs-14', '-', '-'];

// Array Of Book Reservation Information

var reservedArray = ['-', 'ly-44', '-', '-', '-', '-'];

what I want to happen is where the borrowed array or reserved array have a '-' i want the document to write on shelf, and where there is a reader name eg. 'ly-44' the words resered or borrow to be written. I have tried if statements galore, but to no avail.

Im only a newbie so if its really obvious at how its done please dont shout at me lol!!

I hope I have made some sense?

kelbly

User is offlineProfile CardPM

Go to the top of the page

cavvysri
post 17 Jun, 2008 - 07:47 AM
Post #7


New D.I.C Head

*
Joined: 12 Jun, 2008
Posts: 29


My Contributions


QUOTE(kelbly @ 17 Jun, 2008 - 05:18 AM) *

Hey, im still trying to tackle this one, just wondering if anyone can offer advice as to what i have so far?


CODE
if (readerPassword == readerPasswordArray[count])
            {
                document.write('<BR>'+'<BR>'+'Welcome to the catalog'+'<br>'+'================='+' <BR>' )
                
                
                for (var index = 0; index < bookArray.length; index++)
                var shelfArray = new Array
                (if (borrowedArray[index] == ('-'))
                {
                shelfArray[index] = ('onshelf')
                }
                else
                {
                if (borrowedArray[index] != ('-'))
                {
                shelfArray[index] = ('borrowed')
                }
                })

                
                document.write ( index + ' --- ' +bookArray[index] + '---------' + authorArray[index] +' ----------'  + shelfArray[index] +'<br>'  );
                '<br>'
                document.write ('What would you like to do?'+ '<br>' + '<br>')
                document.write('1. Reserve a Book'+ '<br>')
                document.write('2. Borrow a Book'+ '<br>')


var borrowedArray = ['-', '-', '-', 'rs-14', '-', '-'];

// Array Of Book Reservation Information

var reservedArray = ['-', 'ly-44', '-', '-', '-', '-'];

what I want to happen is where the borrowed array or reserved array have a '-' i want the document to write on shelf, and where there is a reader name eg. 'ly-44' the words resered or borrow to be written. I have tried if statements galore, but to no avail.

Im only a newbie so if its really obvious at how its done please dont shout at me lol!!

I hope I have made some sense?

kelbly


my tutor said the same about the guide on page 25, but i still havent got a clue lol!
User is offlineProfile CardPM

Go to the top of the page

kelbly
post 17 Jun, 2008 - 08:01 AM
Post #8


New D.I.C Head

*
Joined: 15 Jun, 2008
Posts: 8

Nope me neither!!

I can do it by creating an array to write it out, but I have manualy written the array, and i thought by way the question has been asked means we have to create a code to work out the status of the book.

But then you look at the clue, and they have manually written in the month names, so I am totally lost!! I feel stupid if i ask the tutor again!!
User is offlineProfile CardPM

Go to the top of the page

cavvysri
post 17 Jun, 2008 - 08:19 AM
Post #9


New D.I.C Head

*
Joined: 12 Jun, 2008
Posts: 29


My Contributions


QUOTE(kelbly @ 17 Jun, 2008 - 08:01 AM) *

Nope me neither!!

I can do it by creating an array to write it out, but I have manualy written the array, and i thought by way the question has been asked means we have to create a code to work out the status of the book.

But then you look at the clue, and they have manually written in the month names, so I am totally lost!! I feel stupid if i ask the tutor again!!


ive wasted enough time, i just created a new array saying the status of the book, i know we need to go back to these arrays in the next question, so if its wrong ill try sort it then..probably is wrong knowing me
User is offlineProfile CardPM

Go to the top of the page

cavvysri
post 17 Jun, 2008 - 08:47 AM
Post #10


New D.I.C Head

*
Joined: 12 Jun, 2008
Posts: 29


My Contributions


QUOTE(kelbly @ 17 Jun, 2008 - 08:01 AM) *

Nope me neither!!

I can do it by creating an array to write it out, but I have manualy written the array, and i thought by way the question has been asked means we have to create a code to work out the status of the book.

But then you look at the clue, and they have manually written in the month names, so I am totally lost!! I feel stupid if i ask the tutor again!!

cant drag myself away from this question, its doing my head in..

there must be some way of using an if statement to search through the array until it finds the username and display reserved or borrowed, depending on where the reader name is in the index..

anybody doing the same course got any pointers? i dont want to be given the answer as i want it to be my own work..just a gentle nudge in the right direction would be appreciated lol
User is offlineProfile CardPM

Go to the top of the page

nebuna
post 17 Jun, 2008 - 02:49 PM
Post #11


New D.I.C Head

*
Joined: 17 Jun, 2008
Posts: 4

QUOTE(cavvysri @ 17 Jun, 2008 - 08:47 AM) *

QUOTE(kelbly @ 17 Jun, 2008 - 08:01 AM) *

Nope me neither!!

I can do it by creating an array to write it out, but I have manualy written the array, and i thought by way the question has been asked means we have to create a code to work out the status of the book.

But then you look at the clue, and they have manually written in the month names, so I am totally lost!! I feel stupid if i ask the tutor again!!

cant drag myself away from this question, its doing my head in..

there must be some way of using an if statement to search through the array until it finds the username and display reserved or borrowed, depending on where the reader name is in the index..

anybody doing the same course got any pointers? i dont want to be given the answer as i want it to be my own work..just a gentle nudge in the right direction would be appreciated lol


Hi, I see quite a few of us stuck with this. I'm stuck as well at the same point and I found the examples from units very unhelpful, I've studied them all last night and really can't associate them with this question. Hope we'll get it done by next week... And I just don't want to move to the next question before sorting this out, because we'll need this script to be done for next part.. Tried setting up new arrays but still can't get correct output nowhere near..
User is offlineProfile CardPM

Go to the top of the page

truetoon
post 18 Jun, 2008 - 06:09 AM
Post #12


New D.I.C Head

*
Joined: 22 May, 2008
Posts: 24

Hi the best way to tackle this is to Write a a function that checks both arrays and returns the correct value. You won't then need to create another array. That's how i completed it anyway.

The first part of function could go something like this
CODE

function bookStatus()

if (reservedArray[count] == '-' && borrowedArray[count] == '-')

return 'on shelf'



then just create more if else statements to work the possible variations.

then add the bookStatus() to the write out.

Hope this helps a little
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 10/7/08 11:30PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month