#TUGAS PERTEMUAN KE-3
Soal
1. Buatlah program untuk menampilkan unsur dan melakukan proses sbb menu ;
A. menghitung volume kubus V= sxsxs
B. menghitung luas lingkaran L= 22/7 x r x r
C. menghitung volume silinder V = 22/7 x r x r x t
pilihan user (1~3) ;
2. buat program yang menerima input sebuah angka positif,
kemudian menampilkan angka genap 0 sd angka tsb.
Jawab
1. PROGRAM PENGHITUNGAN RUMUS
gambar 1 contoh programnya
SCRIPTNYA :
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
void rumus()
{ }
main()
{
int a;
cout<<"Nama : Ilcham Nugroho"<<endl;
cout<<"NIM : TI-111035"<<endl;
cout<<"Mata Kuliah : Pemograman C++"<<endl;
cout<<"jurusan : Teknik Informatika D4 Reguler"<<endl;
cout<<"Semester : III (tiga)"<<endl;
cout<<"Tugas : membuat program Menghitung Rumus"<<endl<<endl;
menu:
cout<<"1. Menghitung Volume Kubus "<<endl;
cout<<"2. Menghitung Luas Lingkaran "<<endl;
cout<<"3. Menghitung Volume Silinder "<<endl;
cout<<"4. Exit Program "<<endl;
cout<<"\n";
cout<<"Silahkan Pilih Rumus (1-4): ";
cin>>a;
if (a==1)
goto kubus;
else if(a==2)
goto lingkaran;
else if(a==3)
goto selinder;
else if(a==4)
goto exit;
else
cout<<"Pilihan anda tidak tersedia\n"<<"Silahkan enter ,kemudian pilih rumus yang tersedia";
getch();
goto menu;
kubus:
{
int VK,s;
cout<<"[VOLUME KUBUS]"<<endl;
cout<<"masukkan panjang sisi kubusnya? ";
cin>>s;
VK=s*s*s;
cout<<"---------------------------"<<endl;
cout<<"Rumus Volume Kubus = s*s*s "<<endl;
cout<<"---------------------------"<<endl;
cout<<"diketahui : "<<endl;
cout<<"sisi kubus (s) = "<<s<<endl;
cout<<"---------------------------"<<endl;
cout<<"JAWAB : "<<endl;
cout<<"V="<<s;
cout<<"*"<<s;
cout<<"*"<<s;
cout<<"="<<VK<<endl;
cout<<"---------------------------"<<endl;
cout<<"maka volume kubusnya adalah "<<VK<<endl;
}{
cout<<"\n";
}{ int jawab;
cout<<"\n";
cout<<"kembali ke home? \n";
cout<<"1. YES \n";
cout<<"2. NO / EXIT \n";
cout<<"3. Try Again \n"<<endl<<endl;
cin>>jawab;
if (jawab==1)
goto menu;
else if(jawab==2)
goto exit;
else if(jawab==3)
goto kubus;
else
cout<<"Kesalahan input"<<"\n"<<"Program Otomatis Berhenti";
getch();
goto exit;
}
lingkaran:
{
float r,LL;
cout<<"[LUAS LINGKARAN]"<<endl;
cout<<"masukkan panjang jari-jari lingkarannya? ";
cin>>r;
cout<<"---------------------------"<<endl;
cout<<"Rumus Luas Lingkaran = 3.14*r*r"<<endl;
cout<<"---------------------------"<<endl;
cout<<"diketahui : "<<endl;
cout<<"phi = 3.14 "<<endl;
cout<<"jari-jari (r) = "<<r<<endl;
cout<<"---------------------------"<<endl;
cout<<"JAWAB : "<<endl;
cout<<"Luas = 3.14";
cout<<"*"<<r;
cout<<"*"<<r;
cout<<"="<<LL<<endl;
cout<<"---------------------------"<<endl;
cout<<"Luas=3.14"<<r<<r<<LL<<endl;
cout<<"\n maka luas lingkaran-nya adalah "<<LL<<endl;
}{
cout<<"\n";
}{ int jawab;
cout<<"\n";
cout<<"kembali ke menu? \n";
cout<<"1. YES \n";
cout<<"2. NO / EXIT \n";
cout<<"3. TRY AGAIN \n";
cin>>jawab;
if (jawab==1)
goto menu;
else if(jawab==2)
goto exit;
else if(jawab==3)
goto kubus;
else
cout<<cout<<"Kesalahan input"<<"\n"<<"Program Otomatis Berhenti";
getch();
goto exit;
}
selinder:
{
float r,t,VS,LL;
cout<<"[VOLUME SILINDER]"<<endl;
cout<<"masukkan panjang jari-jari silinder-nya? ";
cin>>r;
cout<<"masukkanb panjang tinggi silinder-nya? ";
cin>>t;
cout<<"---------------------------"<<endl;
cout<<"Rumus Volume Silinder = 3.14*r*r*t"<<endl;
cout<<"---------------------------"<<endl;
cout<<"diketahui : "<<endl;
cout<<"phi = 3.14 "<<endl;
cout<<"jari-jari (r) = "<<r<<endl;
cout<<"tinggi (t) = "<<t<<endl;
cout<<"---------------------------"<<endl;
cout<<"JAWAB : "<<endl;
cout<<"V = 3.14";
cout<<"*"<<r;
cout<<"*"<<r;
cout<<"*"<<t;
cout<<"="<<VS<<endl;
cout<<"=---------------------------"<<endl;
cout<<"Luas=3.14"<<r<<r<<LL<<endl;
cout<<"Volume=3.14"<<r<<r<<t<<VS<<endl;
cout<<"\n maka volume silinder-nya adalah "<<VS<<endl;
}{
cout<<"\n";
}{int jawab;
cout<<"\n";
cout<<"kembali ke menu? \n";
cout<<"1. YES \n";
cout<<"2. NO / EXIT \n";
cout<<"3. TRY AGAIN \n";
cin>>jawab;
if (jawab==1)
goto menu;
else if(jawab==2)
goto exit;
else if(jawab==3)
goto kubus;
else
cout<<"Kesalahan input"<<"\n"<<"Program Otomatis Berhenti";
getch();
goto exit;
}
exit:
{
cout<<"Thanks for visiting"<<endl<<endl<<endl;
{return 0;
}
}
}
gambar 2 contoh program looping angka
SCRIPT :
#include <iostream.h>
void main()
{
cout<<"Nama : Ilcham Nugroho"<<endl;
cout<<"NIM : TI-111035"<<endl;
cout<<"Mata Kuliah : Pemograman C++"<<endl;
cout<<"jurusan : Teknik Informatika D4 Reguler"<<endl;
cout<<"Semester : III (tiga)"<<endl;
cout<<"Tugas : membuat program looping"<<endl<<endl;
int i,a;
cout<<"masukan angka yang akan dilooping : ";
cin>>a;
for (i=0;i<=a;i+=2)
{
cout<<""<<i<<endl;
}
}


No comments:
Post a Comment