RSS

Arsip Kategori: Contoh program C++

kumpulan source code pemrograman C++

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

Iklan
 
Tinggalkan komentar

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

 

Pemrogaman Perhitungan Nilai rata-rata menggunakan C++

#include
#include
#include

main()
{
char nim[10],nama[30];
int a,b;
int c;
float d;
clrscr();
printf(“\tPROGRAM HITUNG NILAI RATA-RATA\n”);

printf(“\nNim Siswa = “);scanf(“%s”,&nim);
printf(“Nama siswa = “);scanf(“%s”,&nama);
printf(“Nilai Tugas 1 = “);scanf(“%i”,&a);
printf(“Nilai tugas 2 = “);scanf(“%i”,&b);
printf(“Nilai Tugas 3 = “);scanf(“%i”,&c);
d=(a+b+c) / 3;
printf(“\nNim %s “,nim) ;
printf(“Siswa yang bernama %s “,nama) ;
printf(“Memperoleh nilai rata-rata %2.2f “,d) ;
printf(“dari hasil tugas yang diikutinya\n “);
getch();
}

 
Tinggalkan komentar

Ditulis oleh pada Oktober 9, 2012 in Contoh program C++

 

Pemrogaman Hitung nilai akhir menggunakan C++

#include
#include
#include

main()
{
char nama[30];
int k,t;
int u;
float a,b,c,d;
clrscr();
printf(“\tPROGRAM HITUNG NILAI AKHIR\n”);
printf(“\nNama Siswa : “);scanf(“%s”,&nama);
printf(“Nilai Keaktifan : “);scanf(“%i”,&k);
printf(“Nilai Tugas : “);scanf(“%i”,&t);
printf(“Nilai Ujian : “);scanf(“%i”,&u);
a=k*0.2;
b=t*0.3;
c=u*0.5;
d=a+b+c;
printf(“\nSiswa yang bernama %s “,nama) ;
printf(“\nDengan nilai presentasi yang dihasilkan.\n”);
printf(“\nNilai Keaktifan * 20% :”);printf(” %2.2f”,a);
printf(“\nNilai Tugas * 30% : “);printf(” %2.2f”,b);
printf(“\nNilai Ujian * 50% : “);printf(“%2.2f\n”,c);
printf(“\nJadi siswa yang bernama %s “,nama);
printf(“Mendapat nilai akhir sebesar %f”,d);
getch();
}

 
Tinggalkan komentar

Ditulis oleh pada Oktober 9, 2012 in Contoh program C++

 

Pemrograman pembayaran Warnet

#include
#include
#include
main()
{
char nm[20],plg,*ket,lagi;
int hrg,lama,pot,total,ubay,ukem;
atas:
cout<<"masukan Nama anda : ";gets(nm);
cout<>plg;
if(plg=’p’)
{ket=”pelanggan”;
hrg=4000;}
else
{ket=”umum”;
hrg=5000;}
cout<>lama;
if(lama>=5)
{pot=0.5*hrg;}
else if(lama>=3)
{pot=0.3*hrg;}
else
{pot=0;}
clrscr();

/*layar keluaran*/
cout<<"\t WARNET GAULL "<<endl;
cout<<"==========================="<<endl<<endl;
cout<<"Nama Penggujung :"<<nm<<endl;
cout<<"keterangan :"<<ket<<endl;
cout<<"Potongan Harga :"<<pot<<endl;
total=(hrg*lama)-pot;
cout<<"Total Pembayaran:"<<total<<endl<<endl;
cout<<"==========================="<<endl<<endl;
cout<>ubay;
ukem=ubay-total;
cout<<"Uang Kembai :"<<ukem<<endl;
cout<<"=========================="<<endl<<endl;
cout<<"TERIMA KASIH ATAS KUNJUNGAN ANDA"<<endl<<endl;
cout<>lagi;
if(lagi==’Y’ || lagi==’y’)
{goto atas;}
else
{goto akhir;}
akhir:
getch();
}

 
Tinggalkan komentar

Ditulis oleh pada Oktober 9, 2012 in Contoh program C++

 

Pemrograman pemesanan kereta api

#include
#include
#include
main()
{
char nm[10],kode,ka[15],lagi;
int jml;
long hrg,total,ubyr,ukem;
atas:
clrscr();
cout<<"SELAMAT DATANG DI TERMINAL TIKEL KA"<<endl<<endl;
cout<<"____________________________________"<<endl;
cout<<"1. Taksaka (Excusive) Rp. 350.000"<<endl;
cout<<"2. Senja Utama (Bisnis) Rp. 150.000"<<endl;
cout<<"3. Gajahwong (Ekonomi) Rp. 120.000"<<endl;
cout<<"____________________________________"<<endl;
cout<>kode;
if (kode==’1′)
{
strcpy(ka,”Taksaka”);
hrg=350000;
}else

if (kode==’2′)
{
strcpy(ka,”Senja Utama”);
hrg=150000;
}else
{strcpy(ka,”Gajahwong”);
hrg=120000;
}
cout<<"Anda memilih kereta:"<<ka<<endl;
cout<<"Dengan Harga Satuan Rp. "<<hrg<<endl;
cout<>jml;
total=hrg*jml;
cout<<"Harga total Bayar Rp. "<<total<<endl;
cout<>ubyr;
ukem=ubyr-total;
cout<<"kembali Rp. "<<ukem<<endl;
cout<<"__________________________________"<<endl;
cout<<"TERIMA KASIH KUNJUNGAN ANDA"<<endl<<endl;
cout<>lagi;
if(lagi==’Y’ || lagi ==’y’)
{goto atas;}
akhir:
getche();
}

 
Tinggalkan komentar

Ditulis oleh pada Oktober 9, 2012 in Contoh program C++