Friday, April 1, 2011

struct in c++

| Friday, April 1, 2011 | 0 comments

           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;
  .
  .} ;
struct name_struct name_object;



/ / 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;



/ / example struct with different data types:
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 ();}










0 comments:

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Post a Comment

 

analytics

Powered By Blogger
© Copyright 2010. http://hackhaha.blogspot.com . All rights reserved | http://hackhaha.blogspot.com is proudly powered by Blogger.com | Template by o-om.com - zoomtemplate.com