Jumat, 01 Mei 2015

Contoh Latihan Bahasa C++ untuk Program Penjualan Produk

Pada postingan Struktur Kendali IF Jamak/Majemuk Pada Bahasa Pemrograman C/C++ dibahas pemakaian if jamak menggunakan bahasa C. Berikut ini merupakan contoh program dengan menggunakan bahasa C++.

Adapun program ini membahas pemakaian if() jamak

#include <iostream.h>
#include <conio.h>
#include <string.h>
void main()
{
    char    kd ;
    char    nama  [25] = ”” ;
    char    satuan [10] = ”” ;
    int       jumlah=0 ;
    float    harga=0, total=0  ;

    clrscr()  ;
    cout << “Input Data Barang CV. MESRAN IT ”  << endl ;
    cout << “———————————————————-” << endl  ;

    cout << “Input Kode Barang [A,B,C] :”  ;  cin >> kd  ;

    if (kd==’A’ || kd==’a’) {
        strcat( nama, “TV. Sony 21\”  ” ) ;
        strcat( satuan , “Unit”  ) ;
        harga  = 1500000  ;
    } else if (kd==’B’ || kd==’b’) {
        strcat( nama  , “DVD Sony” ) ;
        strcat( satuan ,  “Unit” )  ;
        harga  = 1000000  ;
    } else if (kd==’C’ || kd==’c’) {
        strcat( nama  , “Tape Compo Sony” );
        strcat( satuan , “Unit” )  ;
        harga  = 750000  ;
    } else {
        strcat( nama , “–” );
        strcat( satuan , “–” ) ;
        harga = 0 ;
    }

    cout << “Input Jumlah           :” ; cin >> jumlah  ;

    total = jumlah * harga ;

    cout << “Nama Barang   : “ <<   nama << endl ;
    cout << “Satuan              :  “ << satuan  << endl;
    cout << “Harga               :   “ << harga << endl ;
    cout << “Jumlah             :  “ << jumlah << endl;
    cout << “Total Harga     :  “ << total << endl ;
    cout << “————————————————————” << endl  ;
}

Tidak ada komentar:

Posting Komentar