#include <iostream>
#include <iomanip> // Diperlukan untuk mengatur format output desimal
using namespace std;
// Fungsi untuk menghitung dan menampilkan persentase
void hitungPersentaseGenetika() {
// Diasumsikan persilangan monohibrid dari dua induk heterozigot (Bb x Bb)
// Proporsi genotipe F1: 1 BB : 2 Bb : 1 bb
// Total perbandingan unit: 1 + 2 + 1 = 4
const double total_unit = 4.0; // Total unit perbandingan (misalnya, dari kotak Punnett 2x2)
// Perbandingan Genotipe
const double unit_homozigot_dominan = 1.0; // BB
const double unit_heterozigot = 2.0; // Bb
const double unit_homozigot_resesif = 1.0; // bb
// Perbandingan Fenotipe (Fenotipe Dominan dan Resesif)
// Fenotipe Dominan (BB + Bb) -> sifat yang muncul
const double unit_fenotipe_dominan = unit_homozigot_dominan + unit_heterozigot; // 1 + 2 = 3
// Fenotipe Resesif (bb) -> sifat yang tersembunyi/tidak muncul
const double unit_fenotipe_resesif = unit_homozigot_resesif; // 1
cout << "==========================================================" << endl;
cout << " 🧪 Program Persentase Sifat Keturunan F1" << endl;
cout << " (Asumsi Persilangan Heterozigot: Bb x Bb)" << endl;
cout << "==========================================================" << endl;
// Menghitung Persentase Genotipe
double persen_BB = (unit_homozigot_dominan / total_unit) * 100.0;
double persen_Bb = (unit_heterozigot / total_unit) * 100.0;
double persen_bb = (unit_homozigot_resesif / total_unit) * 100.0;
cout << "\n--- Persentase Genotipe F1 (Perbandingan 1:2:1) ---" << endl;
// Menggunakan setprecision(2) dan fixed untuk 2 angka di belakang koma
cout << fixed << setprecision(2);
cout << "1. Homozygot Dominan (BB): " << persen_BB << " %" << endl;
cout << "2. Heterozygot (Bb): " << persen_Bb << " %" << endl;
cout << "3. Homozygot Resesif (bb): " << persen_bb << " %" << endl;
cout << "----------------------------------------------------------" << endl;
// Menghitung Persentase Fenotipe
double persen_fenotipe_dominan = (unit_fenotipe_dominan / total_unit) * 100.0;
double persen_fenotipe_resesif = (unit_fenotipe_resesif / total_unit) * 100.0;
cout << "\n--- Persentase Fenotipe F1 (Perbandingan 3:1) ---" << endl;
cout << fixed << setprecision(2);
cout << "1. Fenotipe Dominan (BB & Bb): " << persen_fenotipe_dominan << " %" << endl;
cout << "2. Fenotipe Resesif (bb): " << persen_fenotipe_resesif << " %" << endl;
cout << "----------------------------------------------------------" << endl;
cout << "\n" << endl;
}
// Fungsi utama program
int main() {
hitungPersentaseGenetika();
return 0;
}