fork download
  1. #include <iostream>
  2. #include <iomanip> // Diperlukan untuk mengatur format output desimal
  3.  
  4. using namespace std;
  5.  
  6. // Fungsi untuk menghitung dan menampilkan persentase
  7. void hitungPersentaseGenetika() {
  8. // Diasumsikan persilangan monohibrid dari dua induk heterozigot (Bb x Bb)
  9. // Proporsi genotipe F1: 1 BB : 2 Bb : 1 bb
  10. // Total perbandingan unit: 1 + 2 + 1 = 4
  11.  
  12. const double total_unit = 4.0; // Total unit perbandingan (misalnya, dari kotak Punnett 2x2)
  13.  
  14. // Perbandingan Genotipe
  15. const double unit_homozigot_dominan = 1.0; // BB
  16. const double unit_heterozigot = 2.0; // Bb
  17. const double unit_homozigot_resesif = 1.0; // bb
  18.  
  19. // Perbandingan Fenotipe (Fenotipe Dominan dan Resesif)
  20. // Fenotipe Dominan (BB + Bb) -> sifat yang muncul
  21. const double unit_fenotipe_dominan = unit_homozigot_dominan + unit_heterozigot; // 1 + 2 = 3
  22. // Fenotipe Resesif (bb) -> sifat yang tersembunyi/tidak muncul
  23. const double unit_fenotipe_resesif = unit_homozigot_resesif; // 1
  24.  
  25. cout << "==========================================================" << endl;
  26. cout << " 🧪 Program Persentase Sifat Keturunan F1" << endl;
  27. cout << " (Asumsi Persilangan Heterozigot: Bb x Bb)" << endl;
  28. cout << "==========================================================" << endl;
  29.  
  30. // Menghitung Persentase Genotipe
  31. double persen_BB = (unit_homozigot_dominan / total_unit) * 100.0;
  32. double persen_Bb = (unit_heterozigot / total_unit) * 100.0;
  33. double persen_bb = (unit_homozigot_resesif / total_unit) * 100.0;
  34.  
  35. cout << "\n--- Persentase Genotipe F1 (Perbandingan 1:2:1) ---" << endl;
  36. // Menggunakan setprecision(2) dan fixed untuk 2 angka di belakang koma
  37. cout << fixed << setprecision(2);
  38. cout << "1. Homozygot Dominan (BB): " << persen_BB << " %" << endl;
  39. cout << "2. Heterozygot (Bb): " << persen_Bb << " %" << endl;
  40. cout << "3. Homozygot Resesif (bb): " << persen_bb << " %" << endl;
  41. cout << "----------------------------------------------------------" << endl;
  42.  
  43. // Menghitung Persentase Fenotipe
  44. double persen_fenotipe_dominan = (unit_fenotipe_dominan / total_unit) * 100.0;
  45. double persen_fenotipe_resesif = (unit_fenotipe_resesif / total_unit) * 100.0;
  46.  
  47. cout << "\n--- Persentase Fenotipe F1 (Perbandingan 3:1) ---" << endl;
  48. cout << fixed << setprecision(2);
  49. cout << "1. Fenotipe Dominan (BB & Bb): " << persen_fenotipe_dominan << " %" << endl;
  50. cout << "2. Fenotipe Resesif (bb): " << persen_fenotipe_resesif << " %" << endl;
  51. cout << "----------------------------------------------------------" << endl;
  52.  
  53. cout << "\n" << endl;
  54. }
  55.  
  56. // Fungsi utama program
  57. int main() {
  58. hitungPersentaseGenetika();
  59. return 0;
  60. }
Success #stdin #stdout 0s 5320KB
stdin
2 2
0 0
0 0
stdout
==========================================================
       🧪 Program Persentase Sifat Keturunan F1
         (Asumsi Persilangan Heterozigot: Bb x Bb)
==========================================================

--- Persentase Genotipe F1 (Perbandingan 1:2:1) ---
1. Homozygot Dominan (BB): 25.00 %
2. Heterozygot (Bb):       50.00 %
3. Homozygot Resesif (bb): 25.00 %
----------------------------------------------------------

--- Persentase Fenotipe F1 (Perbandingan 3:1) ---
1. Fenotipe Dominan (BB & Bb): 75.00 %
2. Fenotipe Resesif (bb):      25.00 %
----------------------------------------------------------