Laman

Jumat

tugas mandiri


mencari akar dengan menggunakan class


#include

#include

class akar{

public :

akar();

input();

disk(){disk=(b*b)-(4*a*c);}

//float akar_disk();

akar1();

akar2();

cetak();

private:

float X1, X2;

int b, a, c;

};

akar::akar()

{

cout << “Program Mencarai nilai akar1 dan akar2″<

}

akar::input()

{

cout << “Masukkan nilai a : “; cin >> a;

cout << “Masukkan nilai b : “; cin >> b;

cout << “Masukkan nilai c : “; cin >> c;

}

akar::akar1()

{

X1=(-b+sqrt(disk))/(2*a);

}

akar::akar2()

{

X2=(-b-sqrt(disk))/(2*a);

}

akar::cetak()

{

cout << “a = “<<

cout << “b = “<<

cout << “c = “<<

cout << “Akar 1 = “<<

cout << “akar 2 = “<<

}

int main()

{

akar cari;

cari.input();

cari.akar1();

cari.akar2();

cari.cetak();

return 0;

}

Tidak ada komentar:

Posting Komentar