tugas pemograman c++ pertemuan ke 3

Posted by Unknown On Saturday 13 October 2012 0 comments

Tugas Pertemuan 3
 
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. Perogram Menghitung Rumus :

gambar hasil pemograman C++
2. Scrip Menghitung rumus :

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

void main()
{
    float pilihan,s,r,t,VK,LL,VS;
    cout<<"\t\t\tPROGRAM UNTUK MENGHITUNG RUMUS"<<endl;
    cout<<"\t\tYAYAT RUHIYAT (TI111031)"<<endl;
    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 (s) kubus-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();
}

3. Looping angka :
 gambar hasil looping
4. Scrip Looping:

#include <iostream.h>
void main()
{
     int i,n;
     cout<<"Masukan nilai yang anda inginkan = ";
     cin>>n;
     for (i=0;i<=n;i++)
     {
         cout<<""<<i<<endl;
     }
}

Related Post:

0 comments:

Post a Comment