Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <array>
- #include <iomanip>
- using namespace std;
- // variable global bosku
- // untuk laptop :
- string laptop[] = {"Acepp ", "Leknovo ", "Msg "};
- int hargaLaptop[] = {700, 850, 980};
- // untuk kipas:
- string kipas[] = {"Politeron", "Cosmas ", "Mayuko "};
- int hargaKipas[] = {500, 800, 890};
- //untuk televisi
- string televisi[] = {"Philis ", "Shorp ", "Sany "};
- int hargaTelevisi[] = {900, 850, 600};
- //untuk fungsi
- string cartBarang[100];
- int cartHarga[100];
- int kode,jumlah;
- int indeks = -1, indek = -1 , indek2 = -1;
- int jumlahBeli;
- //pembayaran
- int bayar, total,hasil,hasil2;
- // data pembeli
- string namaPembeli;
- string nomerTelfon;
- string alamatPembeli;
- int kodePos;
- string kota;
- // struk
- int maks[100],totalBarang;
- // Function bray!
- time_t ambilWaktu;
- void ateam();
- void daftarLaptop(string laptop[], int hargaLaptop[]);
- void cartLaptop();
- void daftarKipas(string kipas[], int hargaKipas[]);
- void cartKipas();
- void daftarTelevisi(string televisi[], int hargaTelevisi[]);
- void cartTelevisi();
- void keranjang(int maks, string cartBarang[], int cartHarga[]);
- void pembayaran();
- void hapusDuplikat(string arr[]);
- void hapusDuplikat3(int arr[]);
- void hapusDuplikat2(int arr[]);
- void sixe(int *p);
- void struk();
- int main(){
- system("clear");
- awal:
- cout << "Program Penjualan Barang Elektronik" << endl
- << endl;
- cout << "Silakan Pilih barang yg ingin anda beli" << endl;
- cout << "======================"<< endl;
- cout << "| No | Jenis Barang |" << endl;
- cout << "======================" << endl;
- cout << "| 1. | Laptop |" << endl;
- cout << "| 2. | Kipas Angin |" << endl;
- cout << "| 3. | Televisi |" << endl;
- cout << "======================" << endl;
- char lanjut;
- int pilih;
- cout << "Input kode barang yg ingin anda beli: ";
- cin >> pilih;
- switch (pilih){
- case 1:
- cartLaptop();
- break;
- case 2:
- cartKipas();
- break;
- case 3:
- cartTelevisi();
- break;
- default:
- cout << "Maaf kode yg anda masukkan salah" << endl;
- goto awal;
- }
- ljnt:
- cout << endl;
- cout << "Apakah anda ingin membeli barang lagi?: " << endl;
- cout << "[Y] untuk membeli barang lagi" << endl;
- cout << "[N] untuk melanjutkan ke pembayaran" << endl;
- cout << "Silahkan ketik [y/n] ";
- cin >> lanjut;
- system("clear");
- lanjut:
- if (lanjut == 'Y' or lanjut == 'y'){
- goto awal;
- }
- else if (lanjut == 'N' or lanjut == 'n'){
- keranjang(indeks, cartBarang, cartHarga);
- pembayaran();
- struk();
- }
- else{
- cout << "Kode salah, Silahkan ulangi kembali" << endl;
- goto ljnt;
- }
- ateam();
- return 0;
- }
- void ateam(){
- cout << "Dibuat dengan "
- << "\342\230\272"
- << " oleh kelompok 8" << endl;
- cout << "Terima Kasih Telah Membeli Barang Di Toko Kami " << endl;
- cin.get();
- }
- void daftarLaptop(string laptop[], int hargaLaptop[]){
- cout << endl;
- cout << "============================================================" << endl;
- cout << "Kode\t\tMerk Laptop\t\tHarga" << endl;
- cout << "============================================================" << endl;
- for (int i = 0; i < 3; i++){
- cout << " " << i << "\t\t" << laptop[i] << "\t\t"
- << "Rp. " << hargaLaptop[i] << ".000\t" << endl;
- }
- cout << "============================================================" << endl;
- cout << endl;
- }
- void cartLaptop(){
- char lagi;
- do{
- daftarLaptop(laptop,hargaLaptop);
- int kode;
- input:
- cout << "Masukkan jumlah barang yg ingin anda beli: ";
- cin >> jumlahBeli;
- cout << "Input kode barang yg ingin anda beli : ";
- cin >> kode;
- for (int i = 1; i <= jumlahBeli; i++){
- if (kode >= 3){
- cout << "Kode yg anda masukkan salah" << endl;
- goto input;
- }
- else{
- cout << "\nBarang ke - " << i << endl;
- cout << "===========================================================================" << endl;
- cout << "Nama Barang : " << laptop[kode] << endl;
- cout << "Harga Barang : Rp. " << hargaLaptop[kode] << ".000" << endl;
- indeks = indeks + 1;
- indek = indeks;
- indek2 = indeks;
- maks[indek2] = jumlahBeli;
- cartBarang[indek] = laptop[kode];
- cartHarga[indeks] = hargaLaptop[kode];
- jumlah = jumlah + hargaLaptop[kode];
- cout << "Total harga : "
- << "Rp. " << jumlah << ".000" << endl;
- cout << "===========================================================================" << endl;
- }
- cout << endl;
- }
- }while(lagi == 'Y' || lagi == 'y');
- }
- void daftarKipas(string kipas[], int hargaKipas[]){
- cout << endl;
- cout << "====================================================================================" << endl;
- cout << "Kode\t\tMerk Kipas Angin\t\tHarga " << endl;
- cout << "====================================================================================" << endl;
- for (int i = 0; i < 3; i++)
- {
- cout << " " << i << "\t\t" << kipas[i] << "\t\t\t"
- << "Rp. " << hargaKipas[i] << ".000" << endl;
- }
- cout << "====================================================================================" << endl;
- cout << endl;
- }
- void cartKipas(){
- char lagi;
- do{
- daftarKipas(kipas, hargaKipas);
- int kode;
- input1 :
- cout << "Masukkan jumlah barang yg ingin anda beli: ";
- cin >> jumlahBeli;
- cout << "Input kode barang yg ingin anda beli : ";
- cin >> kode;
- for (int i = 1; i <= jumlahBeli; i++)
- {
- if (kode >= 3)
- {
- cout << "Kode yg anda masukkan salah" << endl;
- goto input1;
- }
- else
- {
- cout << "\nBarang ke - " << i << endl;
- cout << "===========================================================================" << endl;
- cout << "Nama Barang : " << kipas[kode] << endl;
- cout << "Harga Barang :Rp. " << hargaKipas[kode] << ".000" << endl;
- indeks = indeks + 1;
- indek = indeks;
- indek2 = indeks;
- maks[indek2] =jumlahBeli;
- cartBarang[indek] = kipas[kode];
- cartHarga[indeks] = hargaKipas[kode];
- jumlah = jumlah + hargaKipas[kode];
- cout << "Total harga : "
- << "Rp. " << jumlah << ".000" << endl;
- cout << "===========================================================================" << endl;
- }
- cout << endl;
- }
- }while(lagi == 'Y' || lagi == 'y');
- }
- void daftarTelevisi(string televisi[], int hargaTelevisi[]){
- cout << endl;
- cout << "===========================================================================" << endl;
- cout << "Kode\t\tMerk Televisi\t\tHarga " << endl;
- cout << "===========================================================================" << endl;
- for (int i = 0; i < 3; i++)
- {
- cout << " " << i << "\t\t" << televisi[i] << "\t\t\t"
- << "Rp. " << hargaTelevisi[i] << ".000\t" << endl;
- }
- cout << "===========================================================================" << endl;
- cout << endl;
- }
- void cartTelevisi(){
- char lagi;
- do{
- daftarTelevisi(televisi, hargaTelevisi);
- int kode;
- input3:
- cout << "Masukkan jumlah barang yg ingin anda beli: ";
- cin >> jumlahBeli;
- cout << "Input kode barang yg ingin anda beli : ";
- cin >> kode;
- for (int i = 1; i <= jumlahBeli;i++){
- if (kode >= 3){
- cout << "Kode yg anda masukkan salah" << endl;
- goto input3;
- }
- else{
- cout << "Barang ke - " << i << endl;
- cout << "===========================================================================" << endl;
- cout << "Nama Barang : " << televisi[kode] << endl;
- cout << "Harga Barang : " << hargaTelevisi[kode] << ".000" << endl;
- indeks = indeks + 1;
- indek = indeks;
- indek2 = indeks;
- maks[indek2] = jumlahBeli;
- cartBarang[indek] = televisi[kode];
- cartHarga[indeks] = hargaTelevisi[kode];
- jumlah = jumlah + hargaTelevisi[kode];
- cout << "Total harga : "
- << "Rp. " << jumlah << ".000" << endl;
- cout << "===========================================================================" << endl;
- }
- cout << endl;
- }
- }while(lagi == 'Y' || lagi == 'y');
- }
- void sixe(int *p)
- {
- std::cout << "Length of array = " << (sizeof(p)/sizeof(*p)) << std::endl;
- }
- void hapusDuplikat2(int arr[]){
- for(int i=0;i<=indeks;i++)
- {
- for(int j=i+1;j<=indeks;)
- {
- if(arr[i]==arr[j])
- {
- for(int k=j;k<=indeks;k++)
- {
- arr[k]=arr[k+1];
- }
- indeks--;
- }
- else
- j++;
- }
- }
- }
- void hapusDuplikat3(int arr[]){
- for(int i=0;i<=indek2;i++)
- {
- for(int j=i+1;j<=indek2;)
- {
- if(arr[i]==arr[j])
- {
- for(int k=j;k<=indek2;k++)
- {
- arr[k]=arr[k+1];
- }
- indek2--;
- }
- else
- j++;
- }
- }
- }
- void hapusDuplikat(string arr[]){
- for(int i=0;i<=indek;i++)
- {
- for(int j=i+1;j<=indek;)
- {
- if(arr[i]==arr[j])
- {
- for(int k=j;k<=indek;k++)
- {
- arr[k]=arr[k+1];
- }
- indek--;
- }
- else
- j++;
- }
- }
- }
- void keranjang(int maks, string cartBarang[], int cartHarga[]){
- time(&ambilWaktu);
- cout << endl;
- cout << "===========================================================================" << endl;
- cout << "Daftar Barang yg anda beli: " << endl;
- for (int i = 0; i <= maks; i++){
- cout << "\t\t" << i + 1 << ". " << cartBarang[i] << "\t\t\tRp. " << cartHarga[i] << ".000" << endl;
- }
- cout << "===========================================================================" << endl;
- cout << "\t\tTransaksi di lakukan pada: " << ctime(&ambilWaktu) << endl;
- cout << "\t\tTotal harga barang yg anda beli adalah: "
- << "Rp. " << jumlah << ".000" << endl;
- }
- void pembayaran(){
- cout << endl << endl;
- cout << "\tSilakan mengisi form data terlebih dahulu" << endl;
- cout << "===========================================================================" << endl;
- cout << "Nama lengkap \t\t: ";
- cin.ignore(1);
- getline(cin, namaPembeli);
- cout << "\nNomer telfon \t\t: ";
- cin >> nomerTelfon;
- cout << "\nAlamat \t\t: ";
- cin.ignore(1);
- getline(cin, alamatPembeli);
- cout << "\nKota \t: ";
- getline(cin, kota);
- cout << "\nKode Pos \t: ";
- cin >> kodePos;
- cout << "===========================================================================" << endl;
- cout << endl;
- cout << "Silakan melakukan pembayaran atas barang yg anda beli" << endl;
- cout << "===========================================================================" << endl;
- cout << "Masukkan nominal uang yang ingin anda bayarkan: Rp. ";
- cin >> bayar;
- total = bayar - jumlah;
- }
- void struk(){
- system("clear");
- hapusDuplikat(cartBarang);
- hapusDuplikat3(maks);
- hapusDuplikat2(cartHarga);
- cout << endl;
- cout << "\t\t\tStruk Pembelian Barang" << endl;
- cout << endl;
- cout << "\t\t\tPt Enginio Client" << endl;
- cout << "\t\t\tJl Soekarno-Hatta 54 Jakarta" << endl;
- cout << "\t\t\t(021) 90903234" << endl;
- cout << "\t\t\t---------------------------------------------------" << endl;
- cout << "\t\t\t| No | Nama Barang | Harga Barang | Jumlah Barang|" << endl;
- cout << "\t\t\t---------------------------------------------------" << endl;
- for(int i = 0; i <= 2; i++)
- cout << "\t\t\t|" << setw(2) << i+1 << setw(4) << " | " << cartBarang[i] << " |" << setw(5) << "Rp. " << cartHarga[i] << ".000 |" << setw(3) << maks[i] << " |" << endl;
- cout << "\t\t\t---------------------------------------------------" << endl;
- cout << "\t\t\tNama Pembeli : " << namaPembeli << endl;
- cout << "\t\t\tNomer Telfon : " << nomerTelfon << endl;
- cout << "\t\t\tAlamat : " << alamatPembeli << endl;
- cout << "\t\t\tKota : " << kota << endl;
- cout << "\t\t\tKode Pos : " << kodePos << endl;
- for (int i = 0; i <= 2; ++i)
- {
- totalBarang += maks[i];
- }
- cout << "\t\t\tTotal Barang : " << totalBarang << endl;
- cout << "\t\t\tTotal Harga : Rp. " << jumlah << ".000" << endl;
- cout << "\t\t\tKembalian : Rp. " << total << ".000" << endl;
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement