التخطي إلى المحتوى الرئيسي

شرح + اسئله عن موضوع Arrays في لغة c++

شرح + اسئله عن موضوع  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.

تعليقات

  1. يارب لك الحمد ع الاقل زبطوا الخط عشان نقدر نقرا ونفهم
    بعدين ياكثر المواقع الانجيزية ابغ اعرف ليه كاتبن بالانجليزي !!
    مواقع متخلف وصاحبة متخلف اكثر منه .

    ردحذف
  2. تبارك الله فيك بالنسخ و اللصق

    ردحذف

إرسال تعليق

المشاركات الشائعة من هذه المدونة

شرح + اسئله لموضوع Pointers في لغة c++

شرح + اسئله لموضوع Pointers في لغة c++ Lab 2: Using Pointers Lab Objectives: In this lab students will learn: ü Memory concept of variables, pointers and how to use variable identifiers and pointers to refer to the variable. ü Pointer variable declarations and initialization. ü Direct and indirect referencing a variable using the pointer operators. ü Using * and address (&) operators.   Background: When declaring a variable, it is located at a specific location in memory, the memory address. The task of locating variables is automatically performed by the operating system during runtime. In some cases we need to know the address where the variable is being stored during runtime. Variable which stores a reference to another variable is called a pointer. We can directly access the value stored in the variable using a pointer which points to it. Syntax: 1. Pointer Declaration: Syntax: Pointer_type *Pointer_name; Example: int *Ptr1; double *Ptr2; 2. Pointer initializati

شرح واسئله عن Friend function & friend class.

موضوع Friend function & friend class Task #6: Friend function & friend class.   Create and destroy objects dynamically. Static data members and member functions.     Objectives:   Using friend functions, and friend classes.   Using this pointer.    Creating and destroying objects dynamically with operators new and delete, respectively.    Creating dynamic array class.   Using static data members and member functions.   Student Learning Outcomes:   You will: Be able to write a friend function and friend class. Be able to allocate and de allocate objects dynamically.   Background:   You have learned the syntax of friend function, friend class, this pointer, and delete and new operators. You have also learned how to write a static data members and member functions.