Senin, November 24, 2014

Latihan C++ #3

Bagi kawan yang ingin mempelajari dan memperdalam pemrograman C++, cara paling efektif dalam menguasai pemrograman C++ adalah dengan latihan dan praktek langsung. Berikut ini adalah contoh soal beserta jawaban pemrograman C++ yang bisa dijadikan latihan untuk menghadapi Ujian Algoritma dan Pemrograman.

Buatlah program untuk perhitungan penjualan di Swalayan dengan tampilan sebagai berikut:

Tampilan awal:
SWALAYAN
“[nama kelompok anda]”
===========================
KODE BARANG : <IN>
NAMA BARANG : <OUT>
HARGA SATUAN : <OUT>
JUMLAH BELI : <OUT>


Tampilan baru selanjutnya:
SWALAYAN
“[nama kelompok anda]”
===========================
KODE BARANG : <OUT>
NAMA BARANG : <OUT>
HARGA SATUAN : <OUT>
JUMLAH BELI : <OUT>
===========================
HARGA TOTAL : Rp. <OUT>
DISKON : Rp. <OUT>
===========================
SUB TOTAL : Rp. <OUT>
PPN 10% : Rp. <OUT>
===========================
GRAND TOTAL : RP. <OUT>
BAYAR : Rp. <IN>
KEMBALIAN : Rp. <OUT>
TERIMA KASIH
ATAS KUNJUNGAN ANDA


Keterangan:
Kode Barang Nama Barang Harga Satuan Diskon
D012 Tepung Terigu 1Kg 12000 5%
D013 Margarin 1Kg 5600 0%
D014 Gula 1Kg 9600 7%
D015 Minyak Sayur 1 Kg 6500 2.5%
Soal oleh: Agung Sasongko, S.Kom

Jawaban
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>

class Cswalayan
{
public:
char kode[4];
long jml_beli,bayar;

char *nama_brg()
{
char *n;
if ((kode[0]=='D'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='2')||(kode[0]=='d'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='2'))
{n = "Tepung terigu 1Kg";}
else if ((kode[0]=='D'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='3')||(kode[0]=='d'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='3'))
{n = "Margarin 1Kg";}
else if ((kode[0]=='D'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='4')||(kode[0]=='d'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='4'))
{n = "Gula 1Kg";}
else if ((kode[0]=='D'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='5')||(kode[0]=='d'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='5'))
{n = "Minyak 1Kg";}
else {n = "Kode tidak ditemukan";}
return n;
}

long harga_brg()
{
long h;
if ((kode[0]=='D'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='2')||(kode[0]=='d'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='2'))
{h = 12000;}
else if ((kode[0]=='D'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='3')||(kode[0]=='d'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='3'))
{h = 5600;}
else if ((kode[0]=='D'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='4')||(kode[0]=='d'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='4'))
{h = 9600;}
else if ((kode[0]=='D'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='5')||(kode[0]=='d'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='5'))
{h = 6500;}
else {h = 0;}
return h;
}

long diskon()
{
long d;
if ((kode[0]=='D'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='2')||(kode[0]=='d'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='2'))
{d = 5;}
else if ((kode[0]=='D'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='3')||(kode[0]=='d'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='3'))
{d = 0;}
else if ((kode[0]=='D'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='4')||(kode[0]=='d'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='4'))
{d = 7;}
else if ((kode[0]=='D'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='5')||(kode[0]=='d'&&kode[1]=='0'&&kode[2]=='1'&&kode[3]=='5'))
{d = 25;}
else {d = 0;}
return d;
}

long harga_total()
{
long o;
o = harga_brg() * jml_beli;
return o;
}

long harga_diskon()
{
return (harga_total()/100)*diskon();
}

long sub_total()
{
return harga_total() - harga_diskon();
}

long ppn()
{
return sub_total() * 0.1;
}

long grand_total()
{
return sub_total() + ppn();
}

long kembalian()
{
return bayar - grand_total();
}

};

main()
{
Cswalayan belanja;
cout<<" SWALAYAN\n";
cout<<" [Nama Kelompok]\n";
cout<<"====================================\n";
cout<<"Kode Barang : "; cin>>belanja.kode;
cout<<"Nama Barang : "; cout<<belanja.nama_brg()<<"\n";
cout<<"Harga Satuan : "; cout<<belanja.harga_brg()<<"\n";
cout<<"Jumlah Beli : "; cin>>belanja.jml_beli;
cout<<"====================================\n";
cout<<"Harga Total : "; cout<<belanja.harga_total()<<"\n";
cout<<"Diskon : ";
cout<<belanja.harga_diskon()<<"\n";
cout<<"====================================\n";
cout<<"Sub Total : "; cout<<belanja.sub_total()<<"\n";
cout<<"PPN 10% : "; cout<<belanja.ppn()<<"\n";
cout<<"====================================\n";
cout<<"Grand Total : "; cout<<belanja.grand_total()<<"\n";
cout<<"Bayar : "; cin>>belanja.bayar;
cout<<"Kembalian : "; cout<<belanja.kembalian()<<"\n";

getch();
}

Share:

0 comments:

Posting Komentar