Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

LAB 10 – 1-DIMENSIONAL ARRAYS

Learning Objectives
In today’s lab, you will practice;
1. Declaring and initializing one-dimensional arrays.
2. Inserting values into and printing values out of one-dimensional arrays.

Practice Questions
You can practice the following problems in this lab.
Task 1.1 Declaring One-Dimensional Arrays
Write a C++ program, which declares;
• Integer type array of ‘10’ Indexes
• Float type array of ’15’ Indexes
• Double type array of ‘20’ Indexes
• Character type array of ‘25’ Indexes
Your program should calculate and print the size of each array. Your program should have the
following interface.

Size of integer array of 10 indexes is : 40 Bytes


Size of float array of 15 indexes is : 60 Bytes
Size of double array of 20 indexes is : 160 Bytes
Size of character array of 25 indexes is : 25 Bytes

Task 1.2 Initializing and Printing One-Dimensional Arrays


Write a C++ program, which declares;

• Integer type array of size ‘6’. Initialize each index of array with ‘12’ at the Time of
Declaration.
• Float type array of size ‘5’. Initialize each index of array with ‘0.5’ at the Time of
Declaration.
• Character type array of size ‘4’. Initialize each index of array with ‘a’ at the Time of
Declaration.
Your program should display the values stored in these arrays using the following format.

Integer array : 12 12 12 12 12 12
Float array : 0.5 0.5 0.5 0.5 0.5
Character array : a a a a
Task 1.3 Inserting Values into and Printing Values out of One-Dimensional Arrays
Write a C++ program which prompts the user to enter integer, float and character values into
the arrays defined in Task 9.2. Your program should have the following interface. Do this task
using ‘for’, ‘while’, and ‘do/while’ structures one by one.

Enter values into Integer Array:


Location [0] : 3
Location [1] : 4
Location [2] : 10
Location [3] : 102
Location [4] : 21
Location [5] : 968

Enter values into Float Array:


Location [0] : 3.5
Location [1] : 4.1
Location [2] : 1.8
Location [3] : 102.4
Location [4] : 21.3

Enter values into Character Array:


Location [0] : s
Location [1] : r
Location [2] : o
Location [3] : i

The Integer Array values are : 3, 4, 10, 102, 21, 968


The Float Array values are : 3.5, 4.1, 1.8, 102.4, 21.3
The Character Array values are : s, r, o, i

You might also like