RSS

kumpulan source code pemrograman C++

27 Nov

Belajar mengenai C++

……..///
Mencari luas segitiga///

#include
#include
#include
#include

main()
{
clrscr();
//Program Luas Segitiga
//char nama[15];
//int r;
//float l,phi=3.14;

//cout<>r;

//l=phi*(r*r);
//cout<<" Luas Lingkaran : "<>a;
cout<<"Nilai Tinggi : "; scanf("%d",&t);

l = ((a*t)/2);

printf("Luas Segitiga = %4.2f cm",l);

getche();
}

……///menghitung usia///

#include
#include
#include
#include

main()
{
clrscr();
//Program Menghitung Usia
char nama[15];
int tl=0,ts=0,us=0;

printf(” B I O D A T A “);
printf(“\n ——————————-“);

printf(“\n Nama : “); scanf(“%s”,&nama);
printf(“\n Tahun Sekarang : “); scanf(“%d”,&ts);
printf(“\n Tahun Lahir : “); scanf(“%d”,&tl);

us = ts – tl;

clrscr();

printf(“\n Tahun Sekarang = %d “,ts);
printf(“\n Selamat %s, Usiamu sekarang = %d Tahun”,nama,us);
getche();
}

…//pembayaran Taxi//

#include
#include
main()
{
char nama[20];
int jarak,ongkos;
clrscr();
printf(“TAXI BLUE BRID”);
printf(“\n\tMasukan Nama Penumpang : “);scanf(“%s”,&nama);
printf(“\n\tMasukan Jarak Tempuh : “);scanf(“%d”,&jarak);
ongkos=(jarak-1)*2500+3000;
printf(“\n\tJadi ongkos taxi= %d”,ongkos);
getch();
}

…//program Penjualan berbagai merk motor//

#include “stdio.h”
#include “conio.h”
#include “iostream.h”
#include “iomanip.h”

garis()
{ cout<<" \n—————————————————–\n"; }

char *merk(char kd)
{
if((kd=='H')||(kd=='h')) {return "Honda";}
else if((kd=='S')||(kd=='s')) {return "Suzuki";}
else if((kd=='K')||(kd=='k')) {return "Kawasaki";}
else {return "Yamaha";}
}

float harga(char kd)
{
if((kd=='H')||(kd=='h')) {return 14000000;}
else if((kd=='S')||(kd=='s')) {return 12500000;}
else if((kd=='K')||(kd=='k')) {return 21000000;}
else {return 13500000;}
}

main()
{
int i,jml; float t,d,hb,ppn,pt,ub,uk; char lagi;

struct
{
char nm[15],brg[10],kd;
int it;
float hrg,ttl;
}beli[20];

clrscr();

garis();
cout<<" DEALER DUAMOTOR "<<endl;
cout<<" Penjualan berbagai merk motor "<<endl;
garis();
cout<<endl<>jml;
garis();
cout<<endl;

for(i=1;i<=jml;i++)
{
cout<<" Data Ke – "<<i<<endl;
cout<>beli[i].nm;
cout<>beli[i].kd;
garis();
cout<<setiosflags(ios::fixed);
cout<<" Merk Motor : "<<merk(beli[i].kd)<<endl;
cout<<" Harga Motor : "<<"Rp. "<<setprecision(2)<<harga(beli[i].kd)<<endl;
garis();
t = t + harga(beli[i].kd);
}

output:
clrscr();

garis();
cout<<" DEALER DUAMOTOR "<<endl;
cout<<" Penjualan berbagai merk motor "<<endl;
garis();
cout<<" No. Nama Pembeli Merk Harga "<<endl;
garis();
cout<<endl;

for(i=1;i<=jml;i++)
{
cout<<setiosflags(ios::fixed);
cout<<setw(3)<<i;
cout<<setw(12)<<beli[i].nm;
cout<<setw(18)<<merk(beli[i].kd);
cout<<setw(10)<<"Rp. "<<setprecision(2)<<harga(beli[i].kd);
cout<<endl;
}

garis();
cout<<" Total keseluruhan : Rp."<<setprecision(2)<<t<<endl;
pt = 0.025 * t ;
cout<<" Potongan 2,5 % : Rp."<<setprecision(2)<<pt<<endl;
ppn = 0.1 * t ;
cout<<" PPN 10% : Rp."<<setprecision(2)<<ppn<<endl;
garis();
hb = (t + ppn) – pt;
cout<<" Harga Bersih : Rp."<<setprecision(2)<<hb<<endl;
cout<>ub;
uk = ub – t ;
garis();
cout<<" Uang Kembalian : Rp."<<setprecision(2)<<uk<<endl;
garis();
getch();
}

…//program penjualan tiket kereta api//

#include
#include
#include
main()
{
char nama[20],pilih;
int jt,ub,th,uk;
clrscr();
printf(” DAFTAR NAMA KERETA API \n”);
printf(“\n*************************************”);
printf(“\n1.ARGO LAWU “);
printf(“\n2.ARGO BROMO “);
printf(“\n3.PARAHYANGAN”);
printf(“\n4.TAKSANA “);
printf(“\n*************************************”);
printf(“\nNama Penumpang = “);gets(nama);
clrscr();
printf(“\nMasukan Kereta Pilihan Anda[1..4]: “);
scanf(“%s”,&pilih);
switch(pilih)
{
case ‘1’:
printf(“\nNama Kereta :ARGO LAWU”);
printf(“\nJumlah Tiket =”);scanf(“%d”,&jt);
th=200000*jt;
printf(“\nTotal Bayar = %d”,th);
printf(“\nUang Bayar =”);scanf(“%d”,&ub);
uk=ub-th;
printf(“\nUang Kembali=%d”,uk);
break;
case ‘2’:
printf(“\nJumlah Tiket =”);scanf(“%d”,&jt);
th=180000*jt;
printf(“\nTotal Bayar = %d”,th);
printf(“\nUang Bayar =”);scanf(“%d”,&ub);
uk=ub-th;
printf(“\nUang Kembali=%d”,uk);
break;
case ‘3’:
printf(“\nJumlah Tiket =”);scanf(“%d”,&jt);
th=80000*jt;
printf(“\nTotal Bayar = %d”,th);
printf(“\nUang Bayar =”);scanf(“%d”,&ub);
uk=ub-th;
printf(“\nUang Kembali=%d”,uk);
break;
case ‘4’:
printf(“\nJumlah Tiket =”);scanf(“%d”,&jt);
th=160000*jt;
printf(“\nTotal Bayar = %d”,th);
printf(“\nUang Bayar =”);scanf(“%d”,&ub);
uk=ub-th;
printf(“\nUang Kembali=%d”,uk);
break;
default:
printf(“Anda Salah Memasukan Kode..!!!!”);
break;
}
getch();
}
//*catatan*//
//jt=jumlah tiket
//ub=uang bayar
//th=total harga
//uk=uang kembalian

 
Tinggalkan komentar

Ditulis oleh pada November 27, 2012 in Contoh program C++

 

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s