Structure Dinamic
Assalamualaikum Wr.Wb
Salam Sejahtera semuanya.
Hallo Teman teman dibawah ini dalah sebagian kecil contoh contoh stuktur dinamic dalam c++
#include "iostream"
using namespace std;
struct Data //Structure Dinamic
{
char NamaBarang[20];
int jumlah;
double harga;
double bayar;
double Discount;
};
int main()
{
Data *getData=new Data; //pointer *GetData
cout<<"\n\t Dinamic Struct \n";
cout<<"\t-----------------------------";
cout<<"\n\tNama Barang = ";cin.get(getData->NamaBarang,20);
cout<<"\tHarga = Rp. ";cin>>(*getData).harga;
cout<<"\tjumlah = ";cin>>(*getData).jumlah;
cout<<"\tDiscount (%) = ";cin>>(*getData).Discount;
double Disc=((*getData).harga*((*getData).Discount/100)*(*getData).jumlah);
double total=((*getData).harga)*((*getData).jumlah)-Disc;
cout<<"\n\t-----------------------------";
cout<<"\n\tDiscount = Rp. "<<Disc;
cout<<"\n\tTotal = Rp. "<<total;
cout<<"\n\tJumlah Bayar = Rp. ";cin>>(*getData).bayar;
double kembali=((*getData).bayar)-(total);
cout<<"\n\tKembali = Rp. "<<kembali;
cout<<"\n\t-----------------------------\n\n\n\n";
delete getData;
system("pause");
return EXIT_SUCCESS;
}
using namespace std;
struct Data //Structure Dinamic
{
char NamaBarang[20];
int jumlah;
double harga;
double bayar;
double Discount;
};
int main()
{
Data *getData=new Data; //pointer *GetData
cout<<"\n\t Dinamic Struct \n";
cout<<"\t-----------------------------";
cout<<"\n\tNama Barang = ";cin.get(getData->NamaBarang,20);
cout<<"\tHarga = Rp. ";cin>>(*getData).harga;
cout<<"\tjumlah = ";cin>>(*getData).jumlah;
cout<<"\tDiscount (%) = ";cin>>(*getData).Discount;
double Disc=((*getData).harga*((*getData).Discount/100)*(*getData).jumlah);
double total=((*getData).harga)*((*getData).jumlah)-Disc;
cout<<"\n\t-----------------------------";
cout<<"\n\tDiscount = Rp. "<<Disc;
cout<<"\n\tTotal = Rp. "<<total;
cout<<"\n\tJumlah Bayar = Rp. ";cin>>(*getData).bayar;
double kembali=((*getData).bayar)-(total);
cout<<"\n\tKembali = Rp. "<<kembali;
cout<<"\n\t-----------------------------\n\n\n\n";
delete getData;
system("pause");
return EXIT_SUCCESS;
}
Comments
Post a Comment