Lab Ex Ch4 Array

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 4

Lab Ex Ch4 – Array (1D)

1. Write array declarations, including initializers, for the following:


a) A list of 10 integer voltages: 89, 75, 82, 93, 78, 95, 81, 88, 77, and 82.
b) A list of 100 double-precision distances; the first six distances are 6.29,
6.95, 7.25, 7.35, 7.40, and 7.42.
c) A list of 64 double-precision temperatures; the first 10 temperatures are
78.2, 69.6, 68.5, 83.9, 55.4, 67.0, 49.8, 58.3, 62.5, and 71.6.
d) A list of 15 character codes; the first seven codes are f, j, m, q, t, w, and z.
2) Write a program to declare a 4-by-5 array of integers and initialize with
the data 16, 22, 99, 4, 18, -258, 4, 101, 5, 98, 105, 6, 15, 2, 45, 33, 88,
72, 16, and 3.
3) Write a program to input eight integer numbers into an array named
temp. As each number is input, add the number into a total. After all
numbers are input, display the number and their average.
4) Write a C++ program that read and adds equivalent elements of the
two-dimensional arrays named first and second. The program should
print the resulting data elements in table form.
Chapter 4 1
Lab Ex Ch4 – Array (1D)
5. Write a program to input the following values in an array named volts: 11.95,
16.32, 12.15, 8.22, 15.98, 26.22, 13.54, 6.45, and 17.59. After the data has
been entered, have your program display it three column in table form:
6. Design a program that read total mark of a students’ and print the score level
with the mark in tabular format. Score status level for score >=80 Excellent,
>=60 Very Good, >= 50 Fair, >=40 poor and <40 Fail.
7. Write a program that store a list of number and print the even numbers in the
array in reverse order they are entered.
8. Write a program that read the quantity and unit price of an item and print the
total price in tabular form. Use one dimensional array.
9. Write a program that stores the following resistance values in an array named
resistance: 16, 27, 39, 56, and 81. Your program should also create two arrays
named current and power, each capable of storing five double-precision
numbers. Have your program to accept five user-input numbers in the current
array when the program is run. Your program should store the product of the
values of the squares of the current array and the resistance array in the power
array.
Chapter 4 2
Lab Ex Ch4 – Array (2D)
1. Write a program that checks whether two one dimensional arrays
of the same size are identical (have the same elements) or not.
2. Write a C++ program to that accepts a two-dimensional array and
displays the multiplication of row elements and the sum of column
elements.
3. Write a program to store exam scores (test, assignment, quiz,
project and final). The program should determine and print the
score level alongside with the total mark in tabular format. Score
status level for score >=80 Excellent, >=60 Very Good, >= 50 Fair,
>=40 poor and <40 Fail.
4. Write C++ program, to read 3*4 2D-array, find and print the sum of
even array elements. The program should also print even array
elements and ‘*’ instead of odd numbers in tabular form

Chapter 4 3
Lab Ex Ch4 – Array (2D)
5. Write a C++ program that read and adds equivalent elements of
the two-dimensional arrays named first and second. The program
should print the resulting data elements in table form.
6. Suppose indices represent people and that the value at row i, column j of
a 2D array is true just in case i and j are friends and false otherwise.
Initialize the 2D array to represent the following configuration. Then the
program counts how many pairs of friends are represented in the array.
Note that each friendship pair appears twice in the array, so in the
example above below there are 6 pairs of friends.

Chapter 4 4

You might also like