tugas FUNGSI borland C++
LATIHAN GABUNGAN BORLAND C++ (STRUKTUR,ARRAY,FUNGSI,FOR)
Tampilan kondisi bunganya sebagai berikut :
Selamat Mengerjakan yap....!!!
neh jawabannya :
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<iomanip.h>
judul() /*>>>>>>>>>fungsi judul<<<<<<<<*/
{
puts("\t\t\t Toko Bunga Segar");
puts("\t\t\t ''FLO FLOWERS''");
puts("\t\t\t==================");
}
garis()/*>>>>>>>>>>>>fungsi garis<<<<<<<<<*/
{
puts("=====================================================================");
}
long totalsub(long hrg,long jbl)/*>>>>>>>>>>>>fungsi subtotal<<<<<<<<<<<<*/
{
return(hrg*jbl);
}
long bayartotal(long ttlbyr,long sbttl)/*>>>>>>>>>>>>>fungsi total bayar<<<<<<<<<*/
{
return(ttlbyr+sbttl);
}
long kembali(long ubyr,long tbyr)/*>>>>>>>>>>>>>>fungsi uang kembali<<<<<<<<<<<<*/
{
return(ubyr-tbyr);
}
main()/*>>>>>>>>>>>program utama<<<<<<<<<<*/
{
char nasir[30],napem[30],more;
int j,a;
long tobay,ubay,ukem;
struct/*>>>>>>>>>>>>>>struktur<<<<<<<<<<<*/
{
char kobung[5],kopak,nabung[25],jepak[20];
int jumbel,harga;
long subtotal;
}toko[10];
awal:
clrscr();
#include<conio.h>
#include<iostream.h>
#include<iomanip.h>
judul() /*>>>>>>>>>fungsi judul<<<<<<<<*/
{
puts("\t\t\t Toko Bunga Segar");
puts("\t\t\t ''FLO FLOWERS''");
puts("\t\t\t==================");
}
garis()/*>>>>>>>>>>>>fungsi garis<<<<<<<<<*/
{
puts("=====================================================================");
}
long totalsub(long hrg,long jbl)/*>>>>>>>>>>>>fungsi subtotal<<<<<<<<<<<<*/
{
return(hrg*jbl);
}
long bayartotal(long ttlbyr,long sbttl)/*>>>>>>>>>>>>>fungsi total bayar<<<<<<<<<*/
{
return(ttlbyr+sbttl);
}
long kembali(long ubyr,long tbyr)/*>>>>>>>>>>>>>>fungsi uang kembali<<<<<<<<<<<<*/
{
return(ubyr-tbyr);
}
main()/*>>>>>>>>>>>program utama<<<<<<<<<<*/
{
char nasir[30],napem[30],more;
int j,a;
long tobay,ubay,ukem;
struct/*>>>>>>>>>>>>>>struktur<<<<<<<<<<<*/
{
char kobung[5],kopak,nabung[25],jepak[20];
int jumbel,harga;
long subtotal;
}toko[10];
awal:
clrscr();
tobay=0;
judul();
cout<<"Nama Kasir : ";gets(nasir);
cout<<"Nama Pembeli : ";gets(napem);
cout<<"jumlah jenis Bunga : ";cin>>j;
cout<<endl;
for(a=1;a<=j;a++)/*>>>>>>>>>>>perulangan untuk kondisi<<<<<<<<<*/
{
cout<<"Bunga ke - "<<a<<endl;
cout<<"Kode bunga [TL/LY] : ";cin>>toko[a].kobung;
cout<<"Kode Paket [S/B] : ";cin>>toko[a].kopak;
cout<<"Jumlah Beli : ";cin>>toko[a].jumbel;
if (!strcmp(toko[a].kobung,"TL")||!strcmp(toko[a].kobung,"tl"))/*>>>>>>>>>>>kondisi nested if<<<<<<<<<*/
{
strcpy(toko[a].nabung,"TULIP");
if(toko[a].kopak=='S'||toko[a].kopak=='s')
{
strcpy(toko[a].jepak,"SINGLE");
toko[a].harga=10000;
}
else if(toko[a].kopak=='B'||toko[a].kopak=='b')
{
strcpy(toko[a].jepak,"BUKET");
toko[a].harga=35000;
}
else
{
strcpy(toko[a].jepak,"SALAH KODE");
toko[a].harga=0;
}
}
else if (!strcmp(toko[a].kobung,"LY")||!strcmp(toko[a].kobung,"ly"))
{
strcpy(toko[a].nabung,"LILY");
if(toko[a].kopak=='S'||toko[a].kopak=='s')
{
strcpy(toko[a].jepak,"SINGLE");
toko[a].harga=20000;
}
else if(toko[a].kopak=='B'||toko[a].kopak=='b')
{
strcpy(toko[a].jepak,"BUKET");
toko[a].harga=50000;
}
else
{
strcpy(toko[a].jepak,"SALAH KODE");
toko[a].harga=0;
}
}
else
{
strcpy(toko[a].nabung,"SALAH KODE");
}
cout<<endl;
}
cout<<endl<<endl;
clrscr();
judul();
cout<<"Nama Kasir : "<<nasir<<endl;
cout<<"Nama Pembeli : "<<napem<<endl;
cout<<endl;
garis();
puts("No Nama Bunga Jenis Paket Harga Jumlah Beli Subtotal");
garis();
for(a=1;a<=j;a++)/*>>>>>>>>perulangan untuk mencetak output<<<<<<<<<*/
{
cout<<setiosflags(ios::left)<<setw(5)<<a;
cout<<setiosflags(ios::left)<<setw(12)<<toko[a].nabung;
cout<<setiosflags(ios::left)<<setw(13)<<toko[a].jepak;
cout<<setiosflags(ios::left)<<setw(12)<<toko[a].harga;
cout<<setiosflags(ios::left)<<setw(8)<<toko[a].jumbel;
toko[a].subtotal=totalsub(toko[a].harga,toko[a].jumbel);
cout<<setiosflags(ios::left)<<setw(5)<<toko[a].subtotal<<endl;
tobay=bayartotal(tobay,toko[a].subtotal);
}
garis();
cout<<"\t\t\t\t\tTotal Bayar : "<<tobay<<endl;
cout<<"\t\t\t\t\tUang Bayar : ";cin>>ubay;
ukem=kembali(ubay,tobay);
cout<<"\t\t\t\t\tUang Kembali : "<<ukem<<endl;
cout<<endl<<endl;
cout<<"\t\t\tInput Data Lagi [Y/T]: ";cin>>more;/*>>>>>>>penggunaan label<<<<<<<*/
if(more=='Y'||more=='y')
goto awal;
else
goto akhir;
getch();
akhir:
}
judul();
cout<<"Nama Kasir : ";gets(nasir);
cout<<"Nama Pembeli : ";gets(napem);
cout<<"jumlah jenis Bunga : ";cin>>j;
cout<<endl;
for(a=1;a<=j;a++)/*>>>>>>>>>>>perulangan untuk kondisi<<<<<<<<<*/
{
cout<<"Bunga ke - "<<a<<endl;
cout<<"Kode bunga [TL/LY] : ";cin>>toko[a].kobung;
cout<<"Kode Paket [S/B] : ";cin>>toko[a].kopak;
cout<<"Jumlah Beli : ";cin>>toko[a].jumbel;
if (!strcmp(toko[a].kobung,"TL")||!strcmp(toko[a].kobung,"tl"))/*>>>>>>>>>>>kondisi nested if<<<<<<<<<*/
{
strcpy(toko[a].nabung,"TULIP");
if(toko[a].kopak=='S'||toko[a].kopak=='s')
{
strcpy(toko[a].jepak,"SINGLE");
toko[a].harga=10000;
}
else if(toko[a].kopak=='B'||toko[a].kopak=='b')
{
strcpy(toko[a].jepak,"BUKET");
toko[a].harga=35000;
}
else
{
strcpy(toko[a].jepak,"SALAH KODE");
toko[a].harga=0;
}
}
else if (!strcmp(toko[a].kobung,"LY")||!strcmp(toko[a].kobung,"ly"))
{
strcpy(toko[a].nabung,"LILY");
if(toko[a].kopak=='S'||toko[a].kopak=='s')
{
strcpy(toko[a].jepak,"SINGLE");
toko[a].harga=20000;
}
else if(toko[a].kopak=='B'||toko[a].kopak=='b')
{
strcpy(toko[a].jepak,"BUKET");
toko[a].harga=50000;
}
else
{
strcpy(toko[a].jepak,"SALAH KODE");
toko[a].harga=0;
}
}
else
{
strcpy(toko[a].nabung,"SALAH KODE");
}
cout<<endl;
}
cout<<endl<<endl;
clrscr();
judul();
cout<<"Nama Kasir : "<<nasir<<endl;
cout<<"Nama Pembeli : "<<napem<<endl;
cout<<endl;
garis();
puts("No Nama Bunga Jenis Paket Harga Jumlah Beli Subtotal");
garis();
for(a=1;a<=j;a++)/*>>>>>>>>perulangan untuk mencetak output<<<<<<<<<*/
{
cout<<setiosflags(ios::left)<<setw(5)<<a;
cout<<setiosflags(ios::left)<<setw(12)<<toko[a].nabung;
cout<<setiosflags(ios::left)<<setw(13)<<toko[a].jepak;
cout<<setiosflags(ios::left)<<setw(12)<<toko[a].harga;
cout<<setiosflags(ios::left)<<setw(8)<<toko[a].jumbel;
toko[a].subtotal=totalsub(toko[a].harga,toko[a].jumbel);
cout<<setiosflags(ios::left)<<setw(5)<<toko[a].subtotal<<endl;
tobay=bayartotal(tobay,toko[a].subtotal);
}
garis();
cout<<"\t\t\t\t\tTotal Bayar : "<<tobay<<endl;
cout<<"\t\t\t\t\tUang Bayar : ";cin>>ubay;
ukem=kembali(ubay,tobay);
cout<<"\t\t\t\t\tUang Kembali : "<<ukem<<endl;
cout<<endl<<endl;
cout<<"\t\t\tInput Data Lagi [Y/T]: ";cin>>more;/*>>>>>>>penggunaan label<<<<<<<*/
if(more=='Y'||more=='y')
goto awal;
else
goto akhir;
getch();
akhir:
}