شرح + اسئله عن موضوع Arrays في لغة c++
1: Arrays
Lab Objectives:
ü Learn how to use the array data structure to represent a set of related data items.
ü Learn how to declare arrays, initialize arrays and refer to the individual elements of arrays.
ü Learn how to pass arrays to functions.
ü Learn how to declare and manipulate Two-dimensional arrays.
ü
Background:
Definition
Array: A collection of individual values, all of the same data type, stored in adjacent memory locations.
One Dimensional Array: An array with a single variable index.
Using the array name together with an integral valued index in square brackets refers to the individual values.
The first array element always has the subscript 0. The second array element has the subscript 1, etc.
The base address of an array is its beginning address in memory.
Declaring an Array:
Use the following syntax below.
DataType ArrayName [Const Int Expression];
The example below shows the declaration of an integer array of size 10 with element 0 - 9.
const int MAXSIZE = 10;
int array[MAXSIZE];
Arrays can be initialized during declaration by equating the array to a listing of the array's members in brackets. For example
int array[MAXSIZE] = {2 , 4, 6, 8, 10, 12, 14,16, 18, 20};
Passing Arrays as Function Parameters
In C++, arrays are always passed by reference by default. Whenever an array is passed as a parameter, its base address is sent to the called function. Generally, functions that work with arrays require 2 items of information as actual parameters: the beginning address of the array (in memory), and the number of elements to process in the array.
For example (Function PrintArray):
void PrintArray(int Array[ ], int ArraySize)
{
for (int i = 0; i <= ArraySize - 1; i++)
cout << "array[" << i << "] = "<<
Array[i] << endl;
}
Declare and manipulate Two-dimensional arrays
Two-dimensional arrays store a tabular arrangement of values accessed by two indexes, for example matrix[i][j], where i is the row index and j is the column index.
To declare and initialize a two-dimensional arrays, Use the following syntax below.
DataType ArrayName [row][column];
The example below shows the declaring two-dimensional array b
int b[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } };
Lab Problems:
Lab Problem-1: Storing quiz scores
Write a program that allows a user to enter 6 quiz scores to calculate and print the average for these quizzes.
Lab Problem -2: store values in 2D arrays
Write a program that reads in random values from 1-100 for 2D array and simply display, as output, the value of each cell.
Lab Problem-3: using array to CountDigit
Write a function CountDigit which receives two arguments: a char array and the size of the array (of type int). This function counts the number of digit letters in the char array, and returns the count (of type int).
Lab Problem -4: search array for a key value
Write a function that searches an array for a "key value" and returns the array's index for that element. If the element is not found, then the function should return -1. Write a driver program that correctly tests this function. The driver should print the array and show the value of the search result.
Lab Problem -5: Minimum array entry
With a function that take as parameters a 2D array and the capacity of the array. Your function has to find the minimum entry in a 2D array .write a driver program that reads array values and finds the minimum entry using your function.
يارب لك الحمد ع الاقل زبطوا الخط عشان نقدر نقرا ونفهم
ردحذفبعدين ياكثر المواقع الانجيزية ابغ اعرف ليه كاتبن بالانجليزي !!
مواقع متخلف وصاحبة متخلف اكثر منه .
تبارك الله فيك بالنسخ و اللصق
ردحذف