# Latihan UTS

Total = Harga * Jumlah Beli
Total Bayar = Jumlah Keseluruhan Dari Pembelian
Logika if atau case
Kode Produk
Nama Produk
Ukuran
Harga
1
2500
SP
SPRITE
2
3000
3
3500
1
3000
FN
FANTA
2
3500
3
4000
1
4000
CC
COCA-COLA
2
4500
3
5000

Rancangan Input

Rancangan Ouput

Borland C++

Created By F@Y

Jawaban
#include <stdio>
#include <conio>
#include <iostream>
#include <iomanip>
main()
{
char nmpet[25],nmpem[20][20],kd[3][20],*nm[20],ukuran[20],lagi;
float hrg[20],jb[20],tot[20],totbyr=0;
int i,j;
awal:
cout<<"
cout<<" Jl.Pancoran barat no 60 Telp 021 7568451"<<endl;
cout<<"==========================================="<<endl;
cout<<" Masukan Nama Petugas = ";cin>>nmpet;
cout<<" Masukan Jumlah Data = ";cin>>j;
cout<<endl;
for(i=1;i<=j;i++)
{
cout<<" Data Ke - "<<i<<endl;
cout<<" Masukan Nama Pembeli
= ";cin>>nmpem[i];
cout<<" Masukan Kode [SP/FN/CC]
= ";cin>>kd[i];
cout<<" Masukan Ukuran [1/2/3]
= ";cin>>ukuran[i];
if(strcmp(kd[i],"SP")==0||strcmp(kd[i],"sp")==0)
{
nm[i]="SPRITE";
if(ukuran[i]=='1')
{
hrg[i]=2500;
}
else if(ukuran[i]=='2')
{
hrg[i]=3000;
}
else if(ukuran[i]=='3')
{
hrg[i]=3500;
}
}
else if(strcmp(kd[i],"FN")==0||strcmp(kd[i],"fn")==0)
{
nm[i]="FANTA";
if(ukuran[i]=='1')
{
hrg[i]=3000;
}
else if(ukuran[i]=='2')
{
hrg[i]=3500;
}
else if(ukuran[i]=='3')
{
hrg[i]=4000;
}
}
else
{
nm[i]="COCA-COLA";

Borland C++

Created By F@Y

if(ukuran[i]=='1')
{
hrg[i]=4000;
}
else if(ukuran[i]=='2')
{
hrg[i]=45000;
}
else if(ukuran[i]=='3')
{
hrg[i]=50000;
}
}
cout<<" Nama Produk
cout<<" Harga
cout<<" Masukan Jumlah Beli
cout<<endl;
tot[i]=hrg[i]*jb[i];
totbyr=totbyr+tot[i];

= "<<nm[i]<<endl;
= "<<hrg[i]<<endl;
= ";cin>>jb[i];

}
clrscr();
cout<<"
cout<<" Jl.Pancoran barat no 60 Telp 021 7568451"<<endl;
cout<<"Nama Petugas = "<<nmpet<<endl;
cout<<"=================================================="<<endl;
cout<<"No Nama
Kode
Ukuran
Nama
Harga
Jumlah
Total"<<endl;
cout<<"
Pembeli Produk
Produk
Beli"<<endl;
cout<<"=================================================="<<endl;
for(i=1;i<=j;i++)
{
cout<<setiosflags(ios::left)<<setw(4)<<i;
cout<<setiosflags(ios::left)<<setw(9)<<nmpem[i];
cout<<setiosflags(ios::left)<<setw(9)<<kd[i];
cout<<setiosflags(ios::left)<<setw(9)<<ukuran[i];
cout<<setiosflags(ios::left)<<setw(10)<<nm[i];
cout<<setiosflags(ios::left)<<setw(10)<<hrg[i];
cout<<setiosflags(ios::left)<<setw(7)<<jb[i];
cout<<setiosflags(ios::left)<<setw(8)<<tot[i]<<endl;
}
cout<<"=================================================="<<endl;
cout<<"Total Bayar = "<<totbyr<<endl;
cout<<"Mau Input Data Lagi[Y/T] = ";cin>>lagi;
if(lagi=='Y'||lagi=='y')
goto awal;
else
goto akhir;
akhir:
getch();
}

Borland C++

Created By F@Y