0% found this document useful (0 votes)
106 views6 pages

Lab 06: Arrays (One Dimensional) : Semester BS CS - 01 & BS IT - 02

1. The document discusses arrays, which allow storing and processing large amounts of data. Arrays can store multiple elements of the same data type. 2. A one-dimensional array stores elements in a single column with multiple rows. The document provides examples of using arrays to store and process integer values more efficiently than individual variables. 3. The lab objectives are to learn applying one-dimensional arrays in C++ and using arrays to store data. Exercises are provided to practice storing values in arrays, comparing arrays, and sorting an array.

Uploaded by

Eiman Wahab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views6 pages

Lab 06: Arrays (One Dimensional) : Semester BS CS - 01 & BS IT - 02

1. The document discusses arrays, which allow storing and processing large amounts of data. Arrays can store multiple elements of the same data type. 2. A one-dimensional array stores elements in a single column with multiple rows. The document provides examples of using arrays to store and process integer values more efficiently than individual variables. 3. The lab objectives are to learn applying one-dimensional arrays in C++ and using arrays to store data. Exercises are provided to practice storing values in arrays, comparing arrays, and sorting an array.

Uploaded by

Eiman Wahab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

CSL-113: Computer Programming Lab

Semester BS CS – 01 & BS IT - 02

Lab 06: Arrays (One Dimensional)

Objective(s) : Upon completion of this lab session, learners will be able to:

1. Apply Arrays in C++


2. Use of One Dimension Array

Arrays

So far we have been using only the standar data types: interger, character, floating point number, and
Boolean. These types are useful but they only hande limited amout of data. To handle more data in
programming language there are derived datatypes. Such datatype is Array structure.

Lets consider that we have a problem that requires us to read, process and print 10 interger values.
To solve this problem we need to create 10 variables, each with different name as shown in below
figure.

Having ten variables with different name is a problematic. How we can read 10 intergers from
keyboard and store them? To read 10 variables from keyboard we need to write 10 read statements.
Furthermore, once we have stored them in memory, we need to print them on screen, for that we
need to write 10 print statement as well.

Althrough this approach is adaptable for 10 variables, what if we need to store, process and print
1000 interger variables? To process large amout of data, we need a powerfull structure that is Array.

Department of Computer Sciences 1/6 Semester BSCS 01 & BS IT 02


CSL-113: Computer Programming Lab Lab 06: Array (1- Dimensional)
An Array is sequenced collection of elements of same data type. Following figure demonstrate the
array of scores, that can store 10 integer values.

To store, process and print the values, we can use loops. Below
figure demonstrates the flow of used to process 10 elements.

1. One Dimension Array

Department of Computer Sciences 2/6 Semester BSCS 01 & BS IT 02


CSL-113: Computer Programming Lab Lab 06: Array (1- Dimensional)
One dimension Array can have only single colum and N rows.

// Output
Elements Square
======== =======
0 0
1 1
2 4
3 9
4 16

Department of Computer Sciences 3/6 Semester BSCS 01 & BS IT 02


CSL-113: Computer Programming Lab Lab 06: Array (1- Dimensional)
EXERCISES

Exercise 1

Write a C++ program, that ask user to enter 10 integer values. Store those values in one dimension
array. Create an other one dimension array of same size, and store the values of first array in
reverse order. Print the results on screen.
Your Program should display output as follows:

#Sample Program Run#1


===================================
Matrix A – Original
===================================
12 23 25 4 6 8 2 7 9 11
===================================
Matrix A – Reverse
===================================
11 9 7 2 8 6 4 25 23 12

Exercise 2

Write a C++ Program that checks whether the two arrays are equal or not.
Declare two Interger Arrays with 7 elements, and fill up the array with keyboard input.
Test if every element in Array 1 is equal to corresponding element in Array 2. For example,
the program should check A[0] = B[0], A[1] = B[1], and so for.
Your Program should display output as follows:

Department of Computer Sciences 4/6 Semester BSCS 01 & BS IT 02


CSL-113: Computer Programming Lab Lab 06: Array (1- Dimensional)
Exercise 3

Write a C++ Program that will take an array of size 10 input from user and then sort that array in
ascending order.

Department of Computer Sciences 5/6 Semester BSCS 01 & BS IT 02


CSL-113: Computer Programming Lab Lab 06: Array (1- Dimensional)
Department of Computer Sciences 6/6 Semester BSCS 01 & BS IT 02
CSL-113: Computer Programming Lab Lab 06: Array (1- Dimensional)

You might also like