CONTOH PROGRAM dengan
typedef struct DALAM DEV C++
PROGRAMNYA:
#include <cstdlib>
#include <iostream>
#include <iomanip>
#define maks 5
using
namespace std;
//yogi.king.pratama@blogspot.com
typedef struct
{
int harga,tgl,kodebrg,jumlahdibel;
double harjum,total;
char namapembeli [31];
char namabrg [31];
char alamat[51];
}nota_belanja;
nota_belanja belanja[maks];
int main (int argc,char*argv[])
{
int y,g;
cout<<"berapa data belanja?";cin>>g;
cout<<endl;
for(y=0;y<g;y++)
{
cout<<"nota pembelian ke="<<y+1<<endl;
cout<<"=================="<<endl;
cout<<"tanggal
pembelian:";cin>>belanja[y].tgl;
cout<<"nama
pembeli:";fflush(stdin);cin.get(belanja[y].namapembeli,30);
cout<<"alamat
pembeli:";fflush(stdin);cin.get(belanja[y].alamat,50);
cout<<"nama barang:";fflush(stdin);cin.get(belanja[y].namabrg,30);
cout<<"kode barang:";cin>>belanja[y].kodebrg;
cout<<"harga satuan:";cin>>belanja[y].harga;
cout<<"jumlah yang
dibeli:";cin>>belanja[y].jumlahdibel;
cout<<endl<<endl;
}
cout<<" TABLE NOTA
BELANJA
"<<endl;
cout<<" TOKO ABADI
TERUS
"<<endl;
cout<<" JL.H.M.JONI.NO.99,MEDAN "<<endl;
cout<<"***************************************************************************"<<endl<<endl;
cout<<"==========================================================================="<<endl;
cout<<"| no | kode barang | nama barang | harga satuan |
jumlah | harga * jumlah |"<<endl;
cout<<"==========================================================================="<<endl;
for(y=0;y<g;y++)
{
belanja[y].harjum=belanja[y].harga*belanja[y].jumlahdibel;
cout<<"|"<<setw(2)<<y+1<<setw(2)<<"|";
cout<<setw(8)<<belanja[y].kodebrg;
cout<<setw(6)<<"|"<<setw(8)<<belanja[y].namabrg;
cout<<setw(7)<<"|"<<setw(8)<<belanja[y].harga;
cout<<setw(7)<<"|"<<setw(4)<<belanja[y].jumlahdibel;
cout<<setw(5)<<"|"<<setw(10)<<belanja[y].harjum<<setw(7)<<"|"<<endl;
belanja[maks].total=belanja[0].harjum+belanja[1].harjum+belanja[2].harjum+belanja[3].harjum+belanja[4].harjum;
}
cout<<"==========================================================================="<<endl;
cout<<"total belanja
(Rp)"<<setw(40)<<"|"<<setw(10)<<belanja[maks].total<<setw(7)<<"|"<<endl;
cout<<"==========================================================================="<<endl;
system ("PAUSE");
return 0;
}
HASIL
COMPILE:
Tidak ada komentar:
Posting Komentar