# Strukture

Structure

mempunyai tipe

data yang

berbeda.

Variable-variabel

membentuk sebuah struktur dinamakan elemen struktur.
BU:

Struct
{
Elemen_struktur;
...............;
...............;
} nama_tipe_struktur;

Contoh Program:
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
struct
{
char kd[3],*nama;
float hrg,jmlbyr;
int jml;
}barang;

main()
{
char np[30],lagi;
awal:
clrscr();
cout<<endl;
cout<<"

DAFTAR BARANG "<<endl;

cout<<"========================="<<endl;
cout<<"

Kode

Nama Barang"<<endl;

cout<<"

[AR]

1. Ardiles "<<endl;

cout<<"

[NK]

2. Nike

"<<endl;

cout<<"

[CR]

3. Carvil

"<<endl;

Created By F@Y

yang

Structure digunakan untuk mengelompokkan sejumlah data yang

Strukture
cout<<"

[ZN]

4. Zando

"<<endl;

cout<<"========================="<<endl;

cout<<" Nama Pembeli

= ";cin>>np;

cout<<"----------------------------"<<endl;
cout<<" Input Kode

= ";cin>>barang.kd;

if (strcmp(barang.kd,"AR")==0||strcmp(barang.kd,"ar")==0 )
{
barang.nama="ARDILES";
barang.hrg=45000;
}
else if (strcmp(barang.kd,"NK")==0||strcmp(barang.kd,"nk")==0)
{
barang.nama="NIKE";
barang.hrg=60000;
}
else if (strcmp(barang.kd,"CR")==0||strcmp(barang.kd,"cr")==0)
{
barang.nama="CARVIL";
barang.hrg=55000;
}
else if (strcmp(barang.kd,"ZN")==0||strcmp(barang.kd,"zn")==0)
{
barang.nama="ZANDO";
barang.hrg=35000;
}
else
{
cout<<"salah kode!!masukan [AR/NK/CR/ZN]!"<<endl;
cout<<"Mau Input data lagi[Y/T]:";cin>>lagi;
if (lagi=='Y'||lagi=='y')
goto awal;
else
goto akhir;
}

Created By F@Y

cout<<endl;

Strukture
cout<<" Jumlah Barang

= ";cin>>barang.jml;

barang.jmlbyr=barang.hrg*barang.jml;

cout<<"

cout<<endl;
cout<<"\t

Struk Pembayaran"<<endl;

cout<<"********************************"<<endl;
cout<<"

Nama Pembeli

= "<<np<<endl;

cout<<"

Kode Barang

= "<<barang.kd<<endl;

cout<<"

Nama Barang

= "<<barang.nama<<endl;

cout<<"

Harga

= "<<barang.hrg<<endl;

cout<<"

Jumlah

= "<<barang.jml<<endl;

cout<<"********************************"<<endl;
cout<<"

Jumlah Bayar

= "<<barang.jmlbyr<<endl;

cout<<endl;
cout<<" Mau Input data lagi[Y/T]: ";cin>>lagi;
if (lagi=='Y'||lagi=='y')
goto awal;
else
goto akhir;
akhir:
getch();
}

Created By F@Y