The structure is a collection of data elements are combined into a single unit of data.Each data element is called a field or element structure. Fields can have different data types or, even if the field is in one but still could siakses individually.
Declaration of structure
structname_struktur
{
type1 element1;
type2 element2; member / element of structure
type3 element3;
} nane_object; // identifier that is used to calling structure
------------atau---------------
structname_struktur
{
type1 element1;
type2 element2;
type3 element3;
.
.} ;
/ / example struct with the same data type:
struct date
{
int date;
int month;
int year;
} th;
--- --- or can be written
struct date
{
int date, month, year;
} th;
struct date
{
int date;
int month;
int year;
} th;
--- --- or can be written
struct date
{
int date, month, year;
} th;
/ / example struct with different data types:
struct student
{
NIM char [10];
char name [25];
char department [2];
float GPA;
}MHS;
struct student
{
NIM char [10];
char name [25];
char department [2];
float GPA;
}MHS;
example program
/ / program inventory data
# include <iostream>
# include <conio.h>
struct stock {
char name [50];
int Amount;
stoks};
main ()
{
court <<"Enter item name ="; cin>> stoks.name;
court <<"Enter the number of items ="; cin>> stoks.jml;
court <<"";
court <<"------------------------- \ n ";
court <<"";
court <<"Output" <<stoks.name <<"=";
court <<stoks.jml;
getch ();}
# include <iostream>
# include <conio.h>
struct stock {
char name [50];
int Amount;
stoks};
main ()
{
court <<"Enter item name ="; cin>> stoks.name;
court <<"Enter the number of items ="; cin>> stoks.jml;
court <<"";
court <<"------------------------- \ n ";
court <<"";
court <<"Output" <<stoks.name <<"=";
court <<stoks.jml;
getch ();}
0 comments:
Post a Comment
thank you for visiting my blog and comment here. I hope the commentary contains a comment which intend to build and repair. criticism and suggestions I gladly accept.