0% found this document useful (0 votes)
54 views5 pages

Lab 02, DSA, V11

This document outlines 4 tasks to familiarize students with array data structures in C++. The tasks include: 1) declaring a 1D integer array, initializing with random values, and outputting even values; 2) initializing a character array with random values and counting vowels/consonants; 3) initializing a real number array, ignoring negatives/integers, and outputting decimals; 4) initializing a 2D integer array, summing rows, and outputting the row with the largest sum. Sample inputs and outputs are provided for each task.
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)
54 views5 pages

Lab 02, DSA, V11

This document outlines 4 tasks to familiarize students with array data structures in C++. The tasks include: 1) declaring a 1D integer array, initializing with random values, and outputting even values; 2) initializing a character array with random values and counting vowels/consonants; 3) initializing a real number array, ignoring negatives/integers, and outputting decimals; 4) initializing a 2D integer array, summing rows, and outputting the row with the largest sum. Sample inputs and outputs are provided for each task.
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/ 5

Lab 02: Array Data Structure, Initialization and Processing of Array, 2D Array,

Custom Operations
Objective:
The objective of this lab is to understand the working of array data structure using
C++. Students will be able to familiarize with the array operations including:
i. Array Declaration (1D, 2D)
ii. Array Initialization
iii. Array IO
iv. Custom Operations on Array Data
Scope:
Single Array and 2D array

Task 01:
Write a C++ program that declares an integer array of size 10, initializes it with ten
random values and outputs all the even values from array on separate lines.
Keywords:
Array, Random Values, Array IO
Sample IO:
Following are the sample inputs and their respective outputs when the program
was executed on three different occasions.
A = {5, 29, 16, 72, 43, 0, 34, 81, 58, 67} Even Values:
16
72
0
34
58
A = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19} Even Values:
A = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20} Even Values:
2
4
6
8
10
12
14
16
18
20

Source Code:
Students have to do it.

Task 02:
Write a C++ program that initializes an array of size 10 with random characters.
The program processes the array and outputs the number of vowels and non-
vowels on separate lines.
Keywords:
Character Array, Vowels, Array IO
Sample IO:
Following are the sample inputs and their respective outputs when the program
was executed on three different occasions.
A = {‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’} Number of Vowels: 3
Number of other characters: 7
A = {‘a’, ‘e’, ‘i’, ‘o’, ‘u’, ‘a’, ‘e’, ‘i’, ‘o’, ‘u’} Number of Vowels: 10
Number of other characters: 0
A = {‘b, ‘c’, ‘d’, ‘f’, ‘g’, ‘h’, ‘j’, ‘k’, ‘l’, ‘m’} Number of Vowels: 0
Number of other characters: 10

Source Code:
Students have to do it.

Task 03:
Write a C++ program that initializes an array of size 10 with random real numbers
(numbers with decimal point). The program performs the following steps on the
array data:
i. Ignores the negative values
ii. Ignores the part of every positive value before decimal point (positive
values) and Outputs the part of value after decimal point
Sample IO:
Following are the sample inputs and their respective outputs when the program
was executed on three different occasions.
A = {-2.9. 7.6, -1, 33, 3.1415, 0.0011, - Output:
44, 7.55, -8.812, 66.009} 6
0
1415
11
55
9
A = {-2.9. -7.6, -1, -33, -3.1415, - Output:
0.0011, -44, -7.55, -8.812, 66.009} 9
A = {2.9. 7.6, 1, 33, 3.1415, 0.0011, -44, Output:
7.55, 8.812, -66.009} 9
6
0
0
1415
11
55
812
Keywords:
Real Numbers, Negative and Positive Values, Processing Real Numbers
Source Code:
Students have to do it.

Task 04:
Write a C++ program that initializes a 2D integer array of size 5X5. The program
performs the following steps on the array data:
i. Initializes the array with the values of your choice
ii. Sums every row of the array separately
iii. Outputs the only row with the largest sum
Sample IO:
Following are the sample inputs and their respective outputs when the program
was executed on three different occasions.
A={ Output:
{1, 2, 3, 4, 4}, {-6, -6, -6, -6, 150}
{2, 3, 5, 5, 10},
{7, 0, -15, 23, 6},
{5, 5, 5, 5, 5},
{-6, -6, -6, -6, 150}
}
A={ Output:
{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}
{1, 1, 1, 1, 1},
{1, 1, 1, 1, 1},
{1, 1, 1, 1, 1},
{1, 1, 1, 1, 1}
}
A={ Output:
{1, 2, 3, 4, 5}, {5, 6, 7, 8, 9}
{2, 3, 4, 5, 6},
{3, 4, 5, 6, 7},
{4, 5, 6, 7, 8},
{5, 6, 7, 8, 9}
}

Keywords:
2D, Array Processing, Row with Largest Sum
Source Code:
Students have to do it.

You might also like