Pages

Tuesday, October 16, 2012

Tugas 3 Pemrograman C++

Soal

  1. Buatlah program untuk menampilkan  unsur dan melakukan proses sbb;
    menu ;
    1. menghitung volume kubus V= sxsxs
    2. menghitung luas lingkaran L= 22/7 x r x r  
    3. 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 Menghitung Rumus-rumus

Contoh Program Menghitung Rumus

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

void main()
{
    float pilihan,s,r,t,VK,LL,VS;

    cout<<"1. Menghitung Volume Kubus "<<endl;
    cout<<"2. Menghitung Luas Lingkaran "<<endl;
    cout<<"3. Menghitung Volume Silinder "<<endl;
    cout<<"\n";
    cout<<"Pilih rumus ke- berapa yang ingin anda pilih? ";
    cin>>pilihan;

    cout<<"\n";
    if(pilihan==1)
    {
        cout<<"VOLUME KUBUS"<<endl;
        cout<<"berapa sisi-nya? ";
        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<<"volume kubus-nya adalah "<<VK<<endl;
    }
    if(pilihan==2)
    {
        cout<<"[LUAS LINGKARAN]"<<endl;
        cout<<"berapa jari-jari (r) lingkaran-nya? ";
        cin>>r;
        LL=3.14*r*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<<"\nluas lingkaran-nya adalah "<<LL<<endl;
    }
    if(pilihan==3)
    {
        cout<<"[VOLUME SILINDER]"<<endl;
        cout<<"berapa jari-jari (r) silinder-nya? ";
        cin>>r;
        cout<<"berapa tinggi (t) silinder-nya? ";
        cin>>t;
        VS=3.14*r*r*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<<"\nvolume silinder-nya adalah  "<<VS<<endl;
    }
    else
{
cout<<"maaf rumus tidak tersedia";
}
    getch();
}



2. Looping angka

Contoh Program Looping  Angka
Script

#include <iostream.h>
void main()
{
     int i,n;
     cout<<"masukan nilai : ";
     cin>>n;
     for (i=0;i<=n;i+=2)
     {
         cout<<""<<i<<endl;
     }
}


By :
Muhammad Akbar Tias Dwi Santoso 
TI111011