#include <iostream.h> #include <math.h> #include <conio.h> class Akar { public: Akar(); float akar1() {return -B+sqrt(disk())/(2*A); } float akar2() {return -B-sqrt(disk())/(2*A); } //void cetak_akar(); private: int A, B, C; // input int disk() { return B*B-4*A*C; } float x1, x2; // akar 1 dan akar 2 }; Akar::Akar() { cout << "Koefisien pangkat 2 : "; cin >> A; cout << "Koefisien pangkat 1 : "; cin >> B; cout << "Koefisien pangkat 0 : "; cin >> C; if (A == 0) { cout << "bukan pers. kuadrat.\n"; cout << "Harga akar = " << -C/B; } else { if (disk() > 0) { x1 = akar1(); x2 = akar2(); cout << "diskriminan = " << disk() << endl; cout << "x1 = " << x1 << endl; cout << "x2 = " << x2 << endl; } else if (disk() == 0) { x1 = akar1(); x2 = x1; cout << "diskriminan = 0\n"; cout << "x1 = " << x1 << endl; cout << "x2 = " << x2 << endl; } else cout << "Akar imajiner"; } } main() { Akar kasus; getch(); return 0; }
0 Response for the "Program C++ Mencari Akar Imajiner"
Post a Comment