Tampilkan postingan dengan label Programming. Tampilkan semua postingan
Tampilkan postingan dengan label Programming. Tampilkan semua postingan

Jumat, 01 April 2022

Program C++ Konversi suhu

Buka aplikasi DEV-C++ lalu salin source code dibawah ini:

 

#include<iostream>

using namespace std;

 

int main(){

              cout<<"Konversi suhu"<<endl;

             

              double celcius, kelvin, farenheit, hasil;

              int pilih, celcius2, kelvin2, farenheit2;

             

              cout<<"pilih jenis suhu:\n [1. celcius]\n [2.kelvin]\n [3.fahrenheit]\n masukkan jenis suhu : ";

              cin>>pilih;

//           jenis suhu yg di inginkan

    if(pilih == 1){

//           CELCIUS

              cout<<endl;

              cout<<"[celcius]\nsuhu yang mau di konversikan \n [1.kelvin]\n [2.fahrenheit]\n suhu : ";cin>>celcius2;

              if(celcius2 == 1){

                             cout<<"[celcius]: "; cin>>celcius;

                             hasil = celcius + 273.15;

                             cout<<"[kelvin]: "<<hasil<<endl;

                             cout<<"Rumus: "<<celcius<<"C + 273,15 = "<<hasil<<"K";

                             }

                             else if(celcius2 == 2){

                                           cout<<"[celcius]: "; cin>>celcius;

                             hasil = (celcius * 9/5) + 32;

                             cout<<"[fahrenheit]: "<<hasil<<endl;

                             cout<<"Rumus: ("<<celcius<<"C * 9/5) + 32 = "<<hasil<<"F";

                             }

              } else if(pilih == 2){

//                         KELVIN

                             cout<<endl;

              cout<<"[kelvin]\nsuhu yang mau di konversikan \n [1.celcius]\n [2.fahrenheit]\n suhu : ";cin>>kelvin2;

              if(kelvin2 == 1){

                             cout<<"[kelvin]: "; cin>>kelvin;

                             hasil = kelvin - 273.15;

                             cout<<"[celcius]: "<<hasil<<endl;

                             cout<<"Rumus: "<<kelvin<<"K - 273,15 = "<<hasil<<"C";

                             }

                             else if(kelvin2 == 2){

                                           cout<<"[kelvin]: "; cin>>kelvin;

                             hasil = (kelvin - 273.15) * 9/5 + 32;

                             cout<<"[fahrenheit]: "<<hasil<<endl;

                             cout<<"Rumus: ("<<kelvin<<"K -273,15) * 9/5 + 32 = "<<hasil<<"F";

                             }

              } else if(pilih == 3){

//                         FAHRENHEIT

                             cout<<endl;

              cout<<"[fahrenheit]\nsuhu yang mau di konversikan \n [1.celcius]\n [2.kelvin]\n suhu : ";cin>>farenheit2;

              if(farenheit2 == 1){

                             cout<<"[fahrenheit]: "; cin>>farenheit;

                             hasil = (farenheit - 32) * 5/9;

                             cout<<"[celcius]: "<<hasil<<endl;

                             cout<<"Rumus: ("<<farenheit<<"F -32) * 5/9 = "<<hasil<<"C";

                             }

                             else if(farenheit2 == 2){

                                           cout<<"[fahrenheit]: "; cin>>farenheit;

                             hasil = (farenheit - 32) * 5/9 + 273.15;

                             cout<<"[kelvin]: "<<hasil<<endl;

                             cout<<"Rumus: ("<<farenheit<<"F- 32) * 5/9 + 273,15 = "<<hasil<<"K";

                             }

              }

             

             

              return 0;

}

 

 

Output/hasilnya:

 





Minggu, 06 Maret 2022

Membuat kalkulator berbasis web

     Pertama buat dulu 1 file tipe .html lalu copy source code dibawah :

<!DOCTYPE html>
<html>
    <head>
        <title>Kalkulator sederhana</title>
    </head>
    <body>
        <form name="kalkulator">
            <table border="1">
                <th colspan="2">Kalkulator sederhana berbasis web</th>
                <tr>
                    <td>masukkan angka 1 : </td>
                    <td><input type="text" name="angka1" id="angka1"></td>
                </tr>
                <tr>
                    <td>masukkan angka 2 : </td>
                    <td><input type="text" name="angka2" id="angka2"></td>
                </tr>
                <tr>
                    <td>pilih operator [+, -, /, *] : </td>
                    <td><input type="text" name="operator" id="operator"></td>
                </tr>
                <tr>
                    <td colspan="0"><input type="button" value="submit" onclick="proses();"></td>
                    <td><p id="demo"></p></td>
                </tr>
            </table>
        </form>
    <script src="kalkulator.js" lang="javascript"></script>
    </body>
</html>


jika sudah maka buat lagi 1 file dengan tipe .js lalu copy isi source code dibawah :


function proses() {
    var angka1 = parseInt( kalkulator.angka1.value);
    var angka2 = parseInt( kalkulator.angka2.value);
    var operator = kalkulator.operator.value;

    var hasil = parseInt("");
    if (operator == '+') {
        hasil = angka1 + angka2;
        document.getElementById("demo").innerHTML = hasil;
    } else if (operator == '-') {
        hasil = angka1 - angka2;
        if (angka1 < angka2) {
            alert("angka1 harus lebih besar dari angka2");
        } else {
            document.getElementById("demo").innerHTML = hasil;
        }
    } else if (operator == '*') {
        hasil = angka1 * angka2;
        document.getElementById("demo").innerHTML = hasil;
    } else if (operator == '/') {
        hasil = angka1 / angka2;
        document.getElementById("demo").innerHTML = hasil;
    }
}

Senin, 03 Januari 2022

Program c++ Pola segitiga

 

MEMBUAT POLA SEGITIGA

Listing program: 

#include <iostream>

using namespace std;

 

int main(){

                int n;

                cout<<"masukkan panjang pola: "; cin>>n;

               

                cout<<"pola 1 \n";

                for (int i=1; i <=n; i++){

                    for (int j=1; j <=i; j++){

                                                cout<<"*";

                                }

                cout<<endl;

                }

               

                cout<<"pola 2 \n";

                for (int i=1; i <=n; i++){

                    for (int j=n; j >=i; j--){

                                cout<<"*";

                                }

                    cout<<endl;

                }

               

                cout<<"pola 3 \n";

                for (int i=1; i<=n; i++){

                                for (int j=1; j<i; j++){

                                                cout<<" ";

                                }

                                for (int k=n; k>=i;k--){

                                                cout<<"*";

                                }

                                cout<<endl;

                }

               

                cout<<"pola 4 \n";

                for (int i=1; i<=n; i++){

                                for (int j=n; j>i; j--){

                                                cout<<" ";

                                }

                                for (int k=1; k<=i; k++){

                                                cout<<"*";

                                }

                                cout<<endl;

                }

               

                cin.get();

                return 0;

}

Hasilnya:



Program c++ Kalkulator sederhana

 

MEMBUAT PROGRAM C++ KALKULATOR

Listing program:

#include <iostream>

using namespace std;

 

int main()

{

 float a, b, hasil;

 char aritmatika;

 

 cout << "Selamat datang di program kalkulator\n\n";

 cout << "Masukan angka pertama: ";

 cin >> a;

 cout << "Masukan angka kedua: ";

 cin >> b;

 cout << "Pilih operator [+,-,/,*] : ";

 cin >> aritmatika;

 

 switch (aritmatika)

 {

  case '+':

   hasil = a + b;

   cout << "Hasil Perhitungan: \n";

   cout << a << aritmatika << b << " = " << hasil << endl;

   break;

  case '-':

   hasil = a - b;

   cout << "Hasil Perhitungan: \n";

   cout << a << aritmatika << b << " = " << hasil << endl;

   break;

  case '*':

   hasil = a * b;

   cout << "Hasil Perhitungan: \n";

   cout << a << aritmatika << b << " = " << hasil << endl;

   break;

  case '/':

   hasil = a / b;

   cout << "Hasil Perhitungan: \n";

   cout << a << aritmatika << b << " = " << hasil << endl;

   break;

  default:

   cout << "Operator salah\n";

 }

 

 

  cin.get();

  cin.get();

  return 0;

}

 

Hasilnya:

1.

 





2.