Tolong pilih kategori sesuai, jenis posting (pertanyaan atau bukan) dan sertakan tag/topik yang sesuai misal komputer, php, mysql, dll.
Promosi atau posting tidak pada tempatnya akan kami hapus.
Mencantumkan kode program di posting Anda, tolong ikuti aturan yang sesuai, baca http://diskusiweb.com/discussion/39204/aturan-cara-menyisipkan-kode-program-di-diskusiweb

Baca cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

Ada yang bisa bantu saya

saya akan coba bantu utk soal no. 1
yg benar adalah diskriminan, bukan determinan
[code]
#include
#include

using namespace std;

class PersamaanKuadrat {
public:
PersamaanKuadrat () {
a = b = c = 0.0;
}

PersamaanKuadrat (float a, float b, float c) {
this->a = a;
this->b = b;
this->c = c;
}

float nilaiDiskriminan () const {
return (b * b) - (a * c * 4.0);
}

bool nilaiX1X2 (float &x1, float &x2) {
if (a != 0.0) {
x1 = (-b + sqrtf(nilaiDiskriminan())) / (2.0 * a);
x2 = (-b - sqrtf(nilaiDiskriminan())) / (2.0 * a);
return true;
}

return false;
}

private:
float a;
float b;
float c;
};

// test program
int main ()
{
PersamaanKuadrat pk(3, 8, 5);
float x1, x2;

cout

Tanggapan

  • Hasil usaha TS ya bertanya itu.
    Khan capek juga ngetik segitu banyak. :D:D

    Standar user yg sekali bertanya langsung cabut.
    Dijawab syukur, ga' dijawab besok2 pake nick lain.
  • hasil dari usaha anda mana ?
  • saya kan bertanya dan minta bantuannya karena saya memang belum paham benar dengan pemrograman C++, untuk no 1 sebenarnya saya dah ngerjain tapi itu gak pake class

    Terima kasih
  • cphcph
    edited March 2011
    saya akan coba bantu utk soal no. 1
    yg benar adalah diskriminan, bukan determinan<div class='geshi_syntax'><table><tr><td><div class='code'><pre class="c"><span class="co2">#include <iostream></span>
    <span class="co2">#include <cmath></span>
     
    using namespace std<span class="sy0">;</span>
     
    class PersamaanKuadrat <span class="br0">{</span>
    public<span class="sy0">:</span>
    PersamaanKuadrat <span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
    a <span class="sy0">=</span> b <span class="sy0">=</span> c <span class="sy0">=</span> <span class="nu16">0.0</span><span class="sy0">;</span>
    <span class="br0">}</span>
     
    PersamaanKuadrat <span class="br0">(</span><span class="kw4">float</span> a<span class="sy0">,</span> <span class="kw4">float</span> b<span class="sy0">,</span> <span class="kw4">float</span> c<span class="br0">)</span> <span class="br0">{</span>
    this<span class="sy0">-></span>a <span class="sy0">=</span> a<span class="sy0">;</span>
    this<span class="sy0">-></span>b <span class="sy0">=</span> b<span class="sy0">;</span>
    this<span class="sy0">-></span>c <span class="sy0">=</span> c<span class="sy0">;</span>
    <span class="br0">}</span>
     
    <span class="kw4">float</span> nilaiDiskriminan <span class="br0">(</span><span class="br0">)</span> <span class="kw4">const</span> <span class="br0">{</span>
    <span class="kw1">return</span> <span class="br0">(</span>b <span class="sy0">*</span> b<span class="br0">)</span> <span class="sy0">-</span> <span class="br0">(</span>a <span class="sy0">*</span> c <span class="sy0">*</span> <span class="nu16">4.0</span><span class="br0">)</span><span class="sy0">;</span>
    <span class="br0">}</span>
     
    bool nilaiX1X2 <span class="br0">(</span><span class="kw4">float</span> <span class="sy0">&</span>x1<span class="sy0">,</span> <span class="kw4">float</span> <span class="sy0">&</span>x2<span class="br0">)</span> <span class="br0">{</span>
    <span class="kw1">if</span> <span class="br0">(</span>a <span class="sy0">!=</span> <span class="nu16">0.0</span><span class="br0">)</span> <span class="br0">{</span>
    x1 <span class="sy0">=</span> <span class="br0">(</span><span class="sy0">-</span>b <span class="sy0">+</span> sqrtf<span class="br0">(</span>nilaiDiskriminan<span class="br0">(</span><span class="br0">)</span><span class="br0">)</span><span class="br0">)</span> <span class="sy0">/</span> <span class="br0">(</span><span class="nu16">2.0</span> <span class="sy0">*</span> a<span class="br0">)</span><span class="sy0">;</span>
    x2 <span class="sy0">=</span> <span class="br0">(</span><span class="sy0">-</span>b <span class="sy0">-</span> sqrtf<span class="br0">(</span>nilaiDiskriminan<span class="br0">(</span><span class="br0">)</span><span class="br0">)</span><span class="br0">)</span> <span class="sy0">/</span> <span class="br0">(</span><span class="nu16">2.0</span> <span class="sy0">*</span> a<span class="br0">)</span><span class="sy0">;</span>
    <span class="kw1">return</span> <span class="kw2">true</span><span class="sy0">;</span>
    <span class="br0">}</span>
     
    <span class="kw1">return</span> <span class="kw2">false</span><span class="sy0">;</span>
    <span class="br0">}</span>
     
    private<span class="sy0">:</span>
    <span class="kw4">float</span> a<span class="sy0">;</span>
    <span class="kw4">float</span> b<span class="sy0">;</span>
    <span class="kw4">float</span> c<span class="sy0">;</span>
    <span class="br0">}</span><span class="sy0">;</span>
     
    <span class="co1">// test program</span>
    <span class="kw4">int</span> main <span class="br0">(</span><span class="br0">)</span>
    <span class="br0">{</span>
    PersamaanKuadrat pk<span class="br0">(</span><span class="nu0">3</span><span class="sy0">,</span> <span class="nu0">8</span><span class="sy0">,</span> <span class="nu0">5</span><span class="br0">)</span><span class="sy0">;</span>
    <span class="kw4">float</span> x1<span class="sy0">,</span> x2<span class="sy0">;</span>
     
    <span class="kw3">cout</span> <span class="sy0"><<</span> <span class="st0">"Diskriminan : "</span> <span class="sy0"><<</span> pk.<span class="me1">nilaiDiskriminan</span><span class="br0">(</span><span class="br0">)</span> <span class="sy0"><<</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">(</span>pk.<span class="me1">nilaiX1X2</span><span class="br0">(</span>x1<span class="sy0">,</span> x2<span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span>
    <span class="kw3">cout</span> <span class="sy0"><<</span> <span class="st0">"x1 : "</span> <span class="sy0"><<</span> x1 <span class="sy0"><<</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy0">;</span>
    <span class="kw3">cout</span> <span class="sy0"><<</span> <span class="st0">"x2 : "</span> <span class="sy0"><<</span> x2 <span class="sy0"><<</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy0">;</span>
    <span class="br0">}</span>
     
    <span class="kw1">return</span> <span class="nu0">0</span><span class="sy0">;</span>
    <span class="br0">}</span></pre></div></td></tr></table></div>

    utk yg lainnya, tdk selalu bisa diselesaikan dgn menggunakan class.
    sebenarnya anda bs "memaksakannya" dengan menggunakan class yg memiliki fungsi2 static
  • Terima Kasih banyak atas bantuannya "cph"
  • u r welcome :)
    belajar terus...
Sign In or Register to comment.