1 / 11

Introduction Algorithm & Structure Data

Introduction Algorithm & Structure Data. Part III By Suzila Yusof. Structure Data & Array. Array and structure are two kinds of data structures storage in C + +. Array is a collection data consisting from same data type.

unity
Download Presentation

Introduction Algorithm & Structure Data

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction Algorithm & Structure Data Part III By Suzila Yusof

  2. Structure Data & Array • Array and structure are two kinds of data structures storage in C + +. • Array is a collection data consisting from same data type. • The structure is a collection data consisting from different data types. • Defined as an array data structure is static, in which the user must define the size of an array when it is defined.

  3. Array • A data collection consisting of a list of elements under a single name, in which elements of the same type of data. • Each element is referred using an index or subscript. • The number of elements in the array is finite and fixed. • Array can be divided into two - one-dimensional - multidimensional

  4. Type of Array Structure • Defining two variables, such as pAli and pSani records for the structure of the student may be referred to a variable because it uses the same type of structure. • This can be solved using a variable array of type structures.

  5. Example: Struct pelajar pelajarJTMK[10]; • Gambaran tatasusunan setelah pengisytiharan di atas dilakukan. Ahli data dalam struct pelajar pelajarJTMK pelajarJTMK[0] pelajarJTMK[1] pelajarJTMK[2] : pelajarJTMK[10]

  6. Type of Array Structure • Size of array can be ignored if the initial value is given during the declaration. • Structured data elements in the array is also referred to by using subscripts. • Example : - looping for is used to change the subscript numbers to enable them one by one put in array data.

  7. Example of coding cout<<"Masukkan rekod 10 pelajar seksyen 1/n"; for (i=0; i<=10; i++) { cout<<"NO METRIK:"; cin >>pelajarJTMK[i].nometrik; cout<<"NAMA:"; cin >>pelajarJTMK[i].nama; cout<<"TAJUK PROJEK:"; cin >>pelajarJTMK[i].projek; }

  8. Example declaration struct KoleksiCD { char Tajuk[15]; char Artis[35]; int JumLagu; float Harga; char TarikhBeli[15]; }myCD[5];

  9. Operations input to the first element cin>> myCD[0].Tajuk; cin>> myCD[0].Artis; cin>> myCD[0].JumLagu; cin>> myCD[0].Harga; cin>> myCD[0].TarikhBeli;

  10. Operations output to the first element cout<<“Tajuk CD :” myCD[0].Tajuk<<endl; cout<<“Artis :” myCD[0].Artis<<endl; cout<<“Jumlah lagu :” myCD[0].JumLagu<<endl; cout<<“Harga :” myCD[0].Harga<<endl; cout<<“Tarikh Beli :” myCD[0].TarikhBeli<<endl;

  11. Use Loop Control Structures For (i=0; i<10; i++) { cout<<“Tajuk CD :” myCD[0].Tajuk<<endl; cout<<“Artis :” myCD[0].Artis<<endl; cout<<“Jumlah lagu :” myCD[0].JumLagu<<endl; cout<<“Harga :” myCD[0].Harga<<endl; cout<<“Tarikh Beli :” myCD[0].TarikhBeli<<endl; }

More Related