Sabtu, 21 April 2012

Enumeration

Enumeration

Enumeration is a data type that has elements of type constants in the order specified. The values
​​of these constants in the form of integer values ​​represented by the identifier written between curly brackets "{" and "}".This type is declared with the enum keyword.

Enumeration declaration:

Nama_enumerasi enum {value1, value2, ...}

Example program 3:


/ / program to access the structure elements
# include <iostream>
# include <conio.h>

j_kel enum {male, female};
int main () {

struct students
                {Int nis;
                char name [20];
                j_kel sex;
A};
                / / input data
                A.nis = 123;
                A.nama == "Windha";
                A.kelamin = female;
                / / output data
                cout << "\ nNis:" << endl << A.nis;
                cout << "Name:" << A.nama;
                cout << "\ nKelamin:" << A.kelamin;
                getch ();}

Structures that contain other structures

A structure can contain the elements of the other structures.
example:

# include <stdio.h>
# include <conio.h>
# include <iostream>
main ()
{
struct date {int day;
                                int month;
                                int year;};
struct address {char path [30];
                                char city [20];};
struct {char name [40];
                                struct date of entry;
                                struct residential address;
                                float salary;}
employees = {"Arief Kurniawan", 17,11,87, "Highway 5", "Yogyakarta", 750000.00};
/ * display the employee data * /
cout << "Employee Name:           " << karyawan.nama;
cout << "\ nTangggal Log:             " << karyawan.masuk.hari
                                                                <<karyawan.masuk.bulan
                                                                <<karyawan.masuk.tahun;
cout << "\ nThis address:              " << karyawan.tinggal.jalan;
cout << "\ n                                        " << karyawan.tinggal.kota;
cout << "\ Koran Employees Rp" << karyawan.gaji;
getch ();
}


0 komentar

Posting Komentar

Statistik