Jumat, 08 April 2016

BAB 6

SOAL :
Latihan
Buatlah procedure untuk:
1. Menghitung ganjil dan genap
2. Menghitung luas persegi panjang
3. Menghitung keliling persegi panjang
4. Menghitung volum lingkaran
5. Menhitung keliling lingkaran
6. Menghitung luas segitiga
7. Menghitung keliling segitiga
8. Menghitung tinggi segitiga
9. Menghitung kombinasi
10. Menghitung permutasi

C++ DAN RAPTOR :
1.#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int g;
cout<<"-----------------------------------"<<endl;
cout<<"Menentukan Nilai Ganjil dan Genap"<<endl;
cout<<"-----------------------------------"<<endl;
cout<<"Masukan nilai g : ";
cin>>g;
if (g % 2==0)
cout<<"Bilangan Genap"<<endl;
else
cout<<"Bilangan Ganjil"<<endl;
cout<<"------------------------------------"<<endl;
return 0;
}





2.#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
class persegi {
public :
persegi ();
void input();
void proses();

private :
int p;
int l;
int hasil;
};
persegi::persegi(){
cout<<"=================================\n";
cout<<"Menghitung Luas Persegi Panjang\n";
cout<<"=================================\n";
}

void persegi::input (){
cout<<"Masukkan Panjang : ";
cin>>p;
cout<<"Masukkan Lebar : ";
cin>>l;

}

void persegi::proses(){
hasil = p*l;
cout<<"Luas : "<<hasil;
}


int main(int argc, char** argv) {

persegi Prsg;
Prsg.input();
Prsg.proses();
return 0;
}


3.#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
class persegi {
public :
persegi ();
void input();
void proses();

private :
int p;
int l;
int hasil;
};
persegi::persegi(){
cout<<"=================================\n";
cout<<"Menghitung Keliling Persegi Panjang\n";
cout<<"=================================\n";
}

void persegi::input (){
cout<<"Masukkan Panjang : ";
cin>>p;
cout<<"Masukkan Lebar : ";
cin>>l;

}

void persegi::proses(){
hasil = 2*(p+l);
cout<<"Keiling : "<<hasil;
}

int main(int argc, char** argv) {
persegi Prsg;
Prsg.input();
Prsg.proses();
return 0;
}


4. #include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
class lingkaran {
public :
lingkaran ();
void input();
void proses();

private :
int r;
float volume;
};

lingkaran::lingkaran(){
cout<<"=================================\n";
cout<<"Menghitung Volume Lingkaran \n";
cout<<"=================================\n";
}

void lingkaran::input (){
cout<<"Masukkan Jari-Jari : ";
cin>>r;
}

void lingkaran::proses(){
volume=(4/(float)3)*(22/(float)7)*r*r*r;
cout<<"Volume : "<<volume;
}

int main(int argc, char** argv) {
lingkaran Lkrn;
Lkrn.input();
Lkrn.proses();

return 0;
}


5#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
class lingkaran {
public :
lingkaran ();
void input();
void proses();
private :
int r;
float keliling;
};

lingkaran::lingkaran(){
cout<<"=================================\n";
cout<<"Menghitung Keliling Lingkaran\n";
cout<<"=================================\n";
}

void lingkaran::input (){
cout<<"Masukkan Jari-Jari : ";
cin>>r;
}

void lingkaran::proses(){
keliling=2*(22/(float)7)*r;
cout<<"Keliling : "<<keliling;
}
int main(int argc, char** argv) {
lingkaran Lkrn;
Lkrn.input();
Lkrn.proses();
return 0;
}


6.#include <iostream>
using namespace std;
class segitiga {
public :
segitiga ();
void input();
void proses();
private :
int a;
int t;
int hasil;
};
segitiga::segitiga(){
cout<<"=================================\n";
cout<<"\n\nLuas Segitiga Siku-siku : \n"<<endl;
cout<<"=================================\n";
}

void segitiga::input (){
cout<<"Masukkan Alas : ";
cin>>a;
cout<<"Masukkan Tinggi : ";
cin>>t;
}

void segitiga::proses(){
hasil = (a*t)/2;
cout<<"Luas : "<<hasil;
}

main ()
{

segitiga Sgtg;
Sgtg.input();
Sgtg.proses();
return 0;
}



10.#include <iostream>
#include <conio.h>
using namespace std;

int main(){
    int i,r, n, P, x;
    int fak_n=1;
    int fak_x=1;
   
    cout<<"Masukkan nilai r: ";cin>>r;
    cout<<"Masukkan nilai n: ";cin>>n;
    x=n-r;
    for (i=1; i<=x; i++){
        fak_x = fak_x * i;}
    for (i=1; i<=n; i++){
        fak_n = fak_n * i;}
   
    cout<<"\nFaktor dari "<<n<<" adalah: "<<fak_n;
    cout<<"\nFaktor dari n-r ("<<x<<") adalah: "<<fak_x;
   
    P= fak_n /(fak_x);
    cout<<"\n\nMaka Permutasinya: "<<P;
    getch();
    return 0;
    }

0 komentar:

Posting Komentar