Monday, 30 March 2015

Contoh kasus C++

Kasus 1
# include <iostream.h>
# include <conio.h>
# include <stdio.h>

main()
{

int i,pil;
char kata[20],*array,ulang;

clrscr();

do{
cout <<"\n********************************";
cout <<"\n* PROGRAM MEMPERMAINKAN KATA *";
cout <<"\n********************************";
cout <<"\n";
cout <<"\n1.Membalikkan Kata (inputan)";
cout <<"\n2.Kapitalis Kata";
cout <<"\n3.Exit";
cout <<"\n";
cout <<"\nMasukkan pilihan Anda ! : "; cin >>pil;
switch(pil){

case 1:
clrscr();
cout <<"\n================================";
cout <<"\n= Membalikkan Kata (inputan) =";
cout <<"\n================================";
cout <<"\n\n";
cout <<"Masukkan kata : "; cin >>kata;

for(kata[i]!='\0';i>=0;i--) // kata[i]!='\0' artinya, nilai awal array kata merupakan akhir dari index array yang diinputkan. '\0' = null, menandai akhir dari index array yang diinputkan.
{
cout <<kata[i];
}
cout <<"\n\n\n";
break;

case 2:
clrscr();
cout <<"\n====================";
cout <<"\n= Kapitalis Kata =";
cout <<"\n====================";
cout <<"\n\n";
cout <<"Masukkan kata ! : ";
gets(array); // fungsi pengambilan tipe data string pada Bahasa C
cout <<"\n--------------------------------";
cout <<"\n\nHASIL : ";

for(i=0;array[i]!='\0';i++)
{
if((array[i]>='A')&&(array[i]<='Z'))
{
printf("%c",array[i]+32); //penjumlahan bilangan desimal dari karakter huruf besar yang diinputkan untuk menghasilkan bilangan desimal karakter huruf kecil
}
else
{
printf("%c",array[i]-32); //pengurangan bilangan desimal dari karakter huruf kecil yang diinputkan untuk menghasilkan bilangan desimal karakter huruf besar
}
}
cout <<"\n\n\n";
break;

case 3 :
clrscr();
break;
}
cout <<"Apakah Anda ingin mengulang ? [Y/T] : ";
cin >>ulang;
}
while(ulang=='Y'||ulang=='y');

cout <<"\3\3\3 TERIMA KASIH \3\3\3";

getch();
}

Kasus 2

# include <iostream.h>
# include <conio.h>

main()
{

int i,j,BA,BK,I;

clrscr();
cout <<"\n*******************";
cout <<"\n* TABEL PERKALIAN *";
cout <<"\n*******************";
cout <<"\n\n\n";
cout <<"Masukkan Bilangan Awal! = "; cin>>BA;
cout <<"Masukkan Bilangan Akhir! = "; cin>>BK;
cout <<"Masukkan Interval! = "; cin>>I;
cout <<"\n";
for(i=BA;i<=BK;i=i+I)
{
for(j=BA;j<=BK;j=j+I)
{
cout <<i*j <<"\t";
}
cout <<"\n";
}

getch();
}


Kasus 3 :

# include <conio.h>
# include <iostream.h>
# include <math.h>

main()
{

int der,FN,LN,I;
float rad,s,c,t;

clrscr();
cout <<"\n******************************************";
cout <<"\n* TRIGONOMETRY ANGEL NUMBERING PROGRAM *";
cout <<"\n******************************************";
cout <<"\n\n";
cout <<"Enter first number ! = "; cin >>FN;
cout <<"Enter last number ! = "; cin >>LN;
cout <<"Enter interval ! = "; cin >>I;
cout <<"\n\n";
cout <<"\n=================================================";
cout <<"\n|DERAJAT| RADIAN | SINUS | COSINUS | TANGEN |";
cout <<"\n=================================================";

if(LN<FN)
{
cout <<"\n\t~~~~~~~~~~~~EEEEERRRROOOORRRRR~~~~~~~~~~~~";
cout <<"\nYour false entering first number or last number";
}
else
{
for(der=FN;der<=LN;der=der+I)
{
rad=1;

rad=M_PI/180*der;
s=sin(rad);
c=cos(rad);
t=tan(rad);
cout <<"\n| "<<der<<" | "<<rad<<" | " <<s<< " | " <<c<< " | " <<t<< " |";
cout <<"\n===================================================";
}
}
cout <<"\n\n\n";
cout <<"\t~~~~~~~~~~~~THANK YOU~~~~~~~~~~~~";

getch();
}

Kasus 4:

# include <conio.h>
# include <iostream.h>
# include <math.h> // Mengaktifkan fungsi-fungsi matematika pada script program

main ()
{
float r,L,K;

clrscr();
cout <<"\n*******************************";
cout <<"\n* LUAS & KELILING LINGKARAN *";
cout <<"\n*******************************";
cout <<"\n\n";
cout <<"\nMasukkan jari-jari ! = "; cin >>r;
cout <<"\nphi = " <<M_PI; //M_PI adalah fungsi matematika (phi)

L=M_PI*r*r;
K=2*M_PI*r;

cout <<"\n\n";
cout <<"\n=========";
cout <<"\n= HASIL =";
cout <<"\n=========";
cout <<"\n\n";
cout <<"\nLuas = " <<L;
cout <<"\nKeliling = " <<K;

getch();
}

Kasus 5:

# include <conio.h>
# include <iostream.h>

main()
{
int BA,BK,I,pil,bil,no;
float H;
char ulang;

clrscr();
cout <<"\n*************************************";
cout <<"\n* TUGAS AKHIR PRAKTIKUM C++ DASAR *";
cout <<"\n* PROGRAM KONVERSI JARAK *";
cout <<"\n*************************************";

do
{
clrscr();
cout <<"\n********************************";
cout <<"\n* KONVERSI VOLUME DARI METER^3 *";
cout <<"\n********************************";
cout <<"\n\n";
cout <<"1.Meter^3 - Kaki^3\n";
cout <<"2.Meter^3 - Yard^3\n";
cout <<"3.Exit";
cout <<"\n";
cout <<"\nMasukkan Pilihan Anda ! : "; cin >>pil;

switch(pil)
{
case 1:
clrscr();
do
{
cout <<"\n====================";
cout <<"\n= METER^3 - KAKI^3 =";
cout <<"\n====================";
cout <<"\n";
cout <<"\nMasukkan Bilangan Awal ! = "; cin >>BA;
cout <<"\nMasukkan Bilangan Akhir ! = "; cin >>BK;

if(BA>BK)
{
cout <<"\n\t\tANDA SALAH MEMASUKKAN BILANGAN";
cout <<"\n\t SEHARUSNYA BILANGAN AWAL < BILANGAN AKHIR";
cout <<"\n\n\nMENU UTAMA Tekan Sembarang Tombol !";
}
else
{
cout <<"\nMasukkan Interval ! = "; cin >>I;
cout <<"\n=========================";
cout <<"\n|No.| METER^3 | KAKI^3 |";
cout <<"\n=========================";

no=1;
for(bil=BA;bil<=BK;bil=bil+I)
{
H=bil/0.02832;
no=no+1;
cout <<"\n| "<<no<< " | "<<bil<<" | "<<H<<" |";
}
cout <<"\n---------------------------------";
cout <<"\n\nApakah Anda Ingin Mengulang Konversi ? [Y/T] : ";
cout <<"\n\nMENU UTAMA Tekan Sembarang Tombol !";
}
ulang=getche();
}
while(ulang=='Y'||ulang=='y');
break;

case 2:
clrscr();
do
{
cout <<"\n====================";
cout <<"\n= METER^3 - YARD^3 =";
cout <<"\n====================";
cout <<"\n";
cout <<"\nMasukkan Bilangan Awal ! = "; cin >>BA;
cout <<"\nMasukkan Bilangan Akhir ! = "; cin >>BK;

if(BA>BK)
{
cout <<"\n\t\tANDA SALAH MEMASUKKAN BILANGAN";
cout <<"\n\t SEHARUSNYA BILANGAN AWAL < BILANGAN AKHIR";
cout <<"\n\n\nMENU UTAMA Tekan Sembarang Tombol !";
}
else
{
cout <<"\nMasukkan Interval ! = "; cin >>I;
cout <<"\n=========================";
cout <<"\n|No.| METER^3 | YARD^3 |";
cout <<"\n=========================";

no=1;
for(bil=BA;bil<=BK;bil=bil+I)
{
H=bil/0.7645;
no=no+1;
cout <<"\n| "<<no<< " | "<<bil<<" | "<<H<<" |";
}
cout <<"\n---------------------------------";
cout <<"\n\nApakah Anda Ingin Mengulang Konversi ? [Y/T] : ";
cout <<"\n\nMENU UTAMA Tekan Sembarang Tombol !";
}
ulang=getche();
}
while(ulang=='Y'||ulang=='y');
break;

case 3:
default:
cout <<"\n\n\t\tTERIMA KASIH Telah Menggunakan Program Ini";
break;

}
}
while(pil!=3);
getch();

}

Kasus 6:

# include <conio.h>
# include <iostream.h>
# include <stdio.h>
main()
{
int pil,s,p,l,a,t,LP,LPP;
float LS;
char ulang;

clrscr();

do{
cout <<"\n******************************";
cout <<"\n* PROGRAM PERHITUNGAN LUAS *";
cout <<"\n******************************";
cout <<"\n";
cout <<"\n1.Luas Persegi";
cout <<"\n2.Luas Persegi Panjang";
cout <<"\n3.Luas Segitiga";
cout <<"\n4.Exit";
cout <<"\n";
cout <<"\nMasukkan pilihan Anda ! : "; cin >>pil;

switch(pil){

case 1:
clrscr();
cout <<"\n==============================";
cout <<"\n= Perhitungan Luas Persegi =";
cout <<"\n==============================";
cout <<"\n";
cout <<"\nMasukkan sisi ! = "; cin >>s;

LP=s*s;

cout <<"\nLuas Persegi = " <<LP;
cout <<"\n\n\n";
break; /*break, berfungsi untuk keluar dari struktur switch*/

case 2:
clrscr();
cout <<"\n======================================";
cout <<"\n= Perhitungan Luas Persegi Panjang =";
cout <<"\n======================================";
cout <<"\n";
cout <<"\nMasukkan panjang ! = "; cin >>p;
cout <<"\nMasukkan lebar ! = "; cin >>l;

LPP=p*l;

cout <<"\nLuas Persegi Panjang = " <<LPP;
cout <<"\n\n\n";
break;

case 3:
clrscr();
cout <<"\n===============================";
cout <<"\n= Perhitungan Luas Segitiga =";
cout <<"\n===============================";
cout <<"\n";
cout <<"\nMasukkan alas ! = "; cin >>a;
cout <<"Masukkan tinggi ! = "; cin >>t;

LS=0.5*a*t;

cout <<"\nLuas Segitiga = " <<LS;
cout <<"\n\n\n";
break;

case 4:
clrscr();
break;

}
cout <<"Apakah Anda ingin mengulang ? [Y/T] : ";
cin >>ulang;
}
while(ulang=='Y'||ulang=='y');

cout <<"\2\2\2 TERIMA KASIH \2\2\2";
getch();

}

No comments:

Post a Comment