Please help, the tasks on last paragraph. Laboratory work No. 5 "Fundamentals of the C ++ programming language: Arrays" One-dimensional arrays It often becomes necessary to store not one variable, but a set of variables of the same type. For example, a list of students in a class is a string-type dataset, the coordinates of a polygon's vertices, or the coefficients of a polynomial is a numeric dataset. Data structures are used to store datasets. The main data structure is an array. An array is a structure of the same type of data that occupies a contiguous area of memory. An array has size — the number of elements in it. Each element of an array has its own number (also called an index); an array element is accessed by specifying its index. In C ++, elements are numbered starting at 0, so the last element in an array is numbered 1 less than the size of the array. An array in C ++ is defined as follows: item_type id [size]; where_element_type is an arbitrary data type of the C ++ language that the elements of the array will have, for example, int, double, etc .; identifier is the name of the array, size is the number of elements in it. An array element can be accessed as an identifier [index]. For example, if an announcement was made doubleA [5]; then in this way 5 elements of a double array are created: A [0], A [1], A [2], A [3], A [4]. An example program that creates an array of type int [] of a user-specified size, reads its elements from the keyboard, then adds number 1 to each element of the array, and then displays the result on the screen: #include usingnamespacestd; intmain () { intn; // Array size inti; // counter in cycles cout << "Enter the number of numbers:"; cin >> n; // Read the size of the array intarr [n]; // Array declaration // Read the array cout << "Enter" << n << "integers:"; for (i = 0; i > arr [i]; // Add 1 to each element for (i = 0; i
Please help, the tasks on last paragraph.
Laboratory work No. 5 "Fundamentals of the C ++ programming language: Arrays"
One-dimensional arrays
It often becomes necessary to store not one variable, but a set of variables of the same type. For example, a list of students in a class is a string-type dataset, the coordinates of a polygon's vertices, or the coefficients of a polynomial is a numeric dataset. Data structures are used to store datasets. The main data structure is an array.
An array is a structure of the same type of data that occupies a contiguous area of memory. An array has size — the number of elements in it. Each element of an array has its own number (also called an index); an array element is accessed by specifying its index. In C ++, elements are numbered starting at 0, so the last element in an array is numbered 1 less than the size of the array.
An array in C ++ is defined as follows:
item_type id [size];
where_element_type is an arbitrary data type of the C ++ language that the elements of the array will have, for example, int, double, etc .; identifier is the name of the array, size is the number of elements in it.
An array element can be accessed as an identifier [index]. For example, if an announcement was made
doubleA [5];
then in this way 5 elements of a double array are created: A [0], A [1], A [2], A [3], A [4].
An example program that creates an array of type int [] of a user-specified size, reads its elements from the keyboard, then adds number 1 to each element of the array, and then displays the result on the screen:
#include <iostream>
usingnamespacestd;
intmain ()
{
intn; // Array size
inti; // counter in cycles
cout << "Enter the number of numbers:";
cin >> n; // Read the size of the array
intarr [n]; // Array declaration
// Read the array
cout << "Enter" << n << "integers:";
for (i = 0; i <n; ++ i)
cin >> arr [i];
// Add 1 to each element
for (i = 0; i <n; ++ i)
arr [i] + = 1;
// Display the array on the screen
for (i = 0; i <n; ++ i)
cout << arr [i] << "";
// Translate the cursororn to a new string
cout << endl;
return0;
}
Tasks
Print all the even-indexed elements of the array (that is, A [0], A [2], A [4], ...).
Print all the even elements of the array (that is, those elements that are even numbers).
Step by step
Solved in 2 steps with 1 images