Worksheet On Arrays Parallel Arrays 2018
Worksheet On Arrays Parallel Arrays 2018
QUESTION 1
QUESTION 1.1
Identify and correct the FIVE errors in this code, to ensure it works as shown.
The program below has two parallel arrays. It prompts for the temperatures for each day
and stores these into the temperatures array.
temperatures = int.Parse(Console.ReadLine());
}
Identify and correct the SEVEN errors in this code, to ensure it works as shown.
It then prints all the temperatures above the average and all the temperatures below the
average in a message box, as shown.
Console.ReadLine();
}
Identify and correct the SEVEN errors in this code, to ensure it works as shown.
The program has five parallel arrays, namely, skaterName, score1, score2, score3 and
score4. It determines the highest per skater and prints this value out as shown.
int[] score1 = { 6, 8, 7, 8 };
int[] score2 = { 6, 9, 7, 8 };
int[] score3 = { 4, 10, 8, 5 };
int[] score4 = { 7, 8, 7, 7 };
Console.ReadLine();
}
This question deals with the petName and petType parallel arrays.
QUESTION 3.1
View the code below and indicate what will be printed to the console window.
string[] petName = new string[4];
string [] petType = new string[4]; // example would be dog, cat, bird, etc.
QUESTION 3.2
View the code of Question 3.1. Show the contents of the petName and petType parallel arrays.
petName
(0) (1)
petType
(0) (1)
QUESTION 3.3
View the code of Question 3.1 and answer the following questions.
3.1 Indicate the final value for the variable i
3.2 Indicate the value for petType.Length
QUESTION 3.5
View the code below.
Assume user will enter “Zorro” for a dog, then “Lassie” for a bird, then “Speckles” for a cat, then
Spotty for a fish, if the code segment loops and asks for 4 pets.
The following program deals with names and their ages. Name and age are parallel arrays. View
code below.
int numberOfNames;
int yearsLeft;
QUESTION 4.1
Prompt for the number of names and then declare the two arrays, called name and age, by
using this input value.
QUESTION 4.2
Once question 4.1 is complete, prompt for the name and age and store these into the parallel arrays,
called name and age.
Also to be printed out is the names of everyone above the average age, as well as the total ages
below the average age.
QUESTION 4.4
Using the age array, determine the youngest age. Variable youngest has been declared.
You need to print out as shown below.
QUESTION 4.5
All names and ages must be printed out, including a specific message via the
retirementMessage variable declared.
If the age is above 55, then “Close to retirement” must be printed out
If the age is above 50, then “Nearly there” must be printed out.
The age gap must also be determined using the ageGap variable. The calculation is 60
minus age.
QUESTION 4.7
Declare and use a message1 and message2 variable.
Message1 must show all names and ages less than 40 years of age, while message 2 must
display all names and ages over 40 years of age. Display via messagebox.
message1
message2