CBSE Coding Class 8 Solution Student Handbook Chapter 4 Programming with Array
CBSE Coding Class 8 Solution Student Handbook Chapter 4 Programming with Array
Reason: you can make an Array of Integers as well as another Array of Strings. However, you cannot make an Array having Integer and
Strings in same Collection.
Answer: There are chances of wastage of memory space if elements inserted in an array are lesser than the allocated size
Reason: Index value of an array can’t be negative neither we have to sequentially access elements in arrays.
Standard Questions
Answer: Arrays are collection of similar data type variables. Array can store multiples values which can be referenced by single name.
Arrays are always stores in specific memory location. Arrays do not support different data types in same collection. Arrays improve
readability of code by using a single variable for a large set of data.
For Example: you can make an Array of Integers as well as another Array of Strings. You cannot make an Array having Integer and
Strings in same Collection.
Answer: The variables in an Array are always ordered sequentially with index starting with 0.
10 20 30 40 50 60
0 1 2 3 4 5
https://www.netexplanations.com/cbse-coding-class-8-solution-student-handbook-chapter-4-programming-with-arrays/ 1/3
CBSE Coding Class 8 Solution Student Handbook Chapter 4 Programming with Arrays
Here, Length of Array = 6
First Index = 0
Last Index = 5
(3) Explain how you can sort an array {67, 23, 98, 19} using Python?
Answer: Python has inbuilt sort function to order an array. The sort() method sorts the list ascending by default.
Numbers.Sort()
Print (Numbers)
Answer: Python uses index method to search for an element in an array. For Example –
X = [34,45,3,23,22,78,65]
Print(X.index(23))
If you run the above code, you would get 3 as output. As 23 is located on index 3.
(1) Make an array of animals (10 animals in the array) and use for loop which runs as many times as the length of the array
todrop horses from the sky.
Answer:
(2) Make an array of animals (10 animals in the array) and use for loop which runs as many times as the length of the array
todrop animal present on the 4th position (Tip: The 4th position will be indexed as 3) from the sky Answer:
Applied Project
(1) Problem Statement: There is a robot which can read the numbers written on the cards only when kept close to its eyes. It can pick
only one card containing numbers in its left hand and another in its right hand. Can you help it to arrange the cards in ascending order
using bubble sort? Let’s try it on the numbers 1, 5, 4, 3, 2.
Step 2) Create a function to sort the array and pass the list as argument. And declare and initialize variable Flag to 0 to check if the
statement becomes false.
Step 3) Calculate the number of list and run the outer loop till length of list minus one.
Step 4) Perform inner passes n-1 times for outer pass. Get the first element value and compare it with the second value. If the second
value is less than the first value, then swap the positions.
https://www.netexplanations.com/cbse-coding-class-8-solution-student-handbook-chapter-4-programming-with-arrays/ 2/3
CBSE Coding Class 8 Solution Student Handbook Chapter 4 Programming with Arrays
Step 5) Repeat step 3 passes until you reach the outer pass (n – 1). Get the next element in the list then repeat the process that was
performed in step 3 until all the values have been placed in their correct ascending order. And change the value of flag to 1.
Step 6) Check the value of Flag if changed, if so then break the loop .
Step 7) Return the result when all passes have been done. Return the results of the sorted list.
defbubbleSort(array):
n = len(array) for i in
range( n – 1 ) :
== 0:
break return
array
bubbleSort(Number) print
(result)
https://www.netexplanations.com/cbse-coding-class-8-solution-student-handbook-chapter-4-programming-with-arrays/ 3/3