CLASS-POLİNOM(TOPLAMA-ÇIKARMA)
// ax^2+bx+c=0 kullanacağımız formüller
// bx+c=0
// x=-c/b
#include <iostream>
#include <cmath>
using namespace std;
class Polinom{ classın tanımı
float a,b,c; private üyelerin tanımı
void kokbul(float b, float c); private fonksiyonların prototipi
void kokbul(float a, float b, float c);
public:
void kokbul(); erişilebilir fonksiyonun prototipi
Polinom(int _a, int _b, int _c); yapıcı fonksiyonun prototipi
void set_a(float _a); atama fonksiyonlarımı
void set_b(float _b);
void set_c(float _c);
float get_a(){ return a; } döndürme fonksiyonlarımız
float get_b(){ return b; }
float get_c(){ return c; }
};
Polinom::Polinom (int _a=0,int _b=0,int _c=0) yapıcı fonksiyonun tanımı değer atanıyor
{
a=_a;
b=_b;
c=_c;
}
void Polinom::kokbul() polinomun 1.derecedenmi 2.derecedenmi olduğuna bakılıyor
{
if(a==0)
{
kokbul(b,c);
}
else
{
kokbul(a,b,c);
}
}
void Polinom::kokbul(float b, float c) 1.dereceden denklemin işlemi yapılıyor
{
float kok1=-c/b;
cout << kok1;
}
void Polinom::kokbul(float a, float b, float c) 2.dereceden denklemin işlemi yapılıyor
{
int delta = b*b-4*a*c;
if(delta>=0)
{
float kok1=(-b-sqrt(delta))/(2*a);
float kok2=(-b+sqrt(delta))/2*a;
cout << kok1 << "\t" << kok2 << endl;
}
else
cout << "Gercek kok yok." << endl;
}
void Polinom::set_a(float _a) atama fonksiyonları tanımlanıyor
{
a=_a;
}
void Polinom::set_b(float _b)
{
b=_b;
}
void Polinom::set_c(float _c)
{
c=_c;
}
Polinom islem(Polinom A, Polinom B, char i) polinomların toplanmasını sağlıyor
{
Polinom sonuc;
if(i=='+')
{
sonuc.set_a(A.get_a()+B.get_a());
sonuc.set_b(A.get_b()+B.get_b());
sonuc.set_c(A.get_c()+B.get_c());
}
else if(i=='-') farkının alınmasını sağlıyor
{
sonuc.set_a(A.get_a()-B.get_a());
sonuc.set_b(A.get_b()-B.get_b());
sonuc.set_c(A.get_c()-B.get_c());
}
else
cout << "Girdiginiz islem yanlis.";
return sonuc;
}
Polinom islem(Polinom A, Polinom B)
{
Polinom sonuc;
sonuc.set_a(A.get_a()+B.get_a());
sonuc.set_b(A.get_b()+B.get_b());
sonuc.set_c(A.get_c()+B.get_c());
return sonuc;
}
int main()
{
Polinom P1(0,4,4),P2(1,2,2),P3; nesneler aracılığı ile değrler gönderiliyor
P3=islem(P1,P2); p3 polinomu oluşturuluyor
cout << P3.get_a() << " " << P3.get_b() << " " << P3.get_c() << endl; ekrana yazdırılıyor
return 0;
}
EKRAN ÇIKTISI
// ax^2+bx+c=0 kullanacağımız formüller
// bx+c=0
// x=-c/b
#include <iostream>
#include <cmath>
using namespace std;
class Polinom{ classın tanımı
float a,b,c; private üyelerin tanımı
void kokbul(float b, float c); private fonksiyonların prototipi
void kokbul(float a, float b, float c);
public:
void kokbul(); erişilebilir fonksiyonun prototipi
Polinom(int _a, int _b, int _c); yapıcı fonksiyonun prototipi
void set_a(float _a); atama fonksiyonlarımı
void set_b(float _b);
void set_c(float _c);
float get_a(){ return a; } döndürme fonksiyonlarımız
float get_b(){ return b; }
float get_c(){ return c; }
};
Polinom::Polinom (int _a=0,int _b=0,int _c=0) yapıcı fonksiyonun tanımı değer atanıyor
{
a=_a;
b=_b;
c=_c;
}
void Polinom::kokbul() polinomun 1.derecedenmi 2.derecedenmi olduğuna bakılıyor
{
if(a==0)
{
kokbul(b,c);
}
else
{
kokbul(a,b,c);
}
}
void Polinom::kokbul(float b, float c) 1.dereceden denklemin işlemi yapılıyor
{
float kok1=-c/b;
cout << kok1;
}
void Polinom::kokbul(float a, float b, float c) 2.dereceden denklemin işlemi yapılıyor
{
int delta = b*b-4*a*c;
if(delta>=0)
{
float kok1=(-b-sqrt(delta))/(2*a);
float kok2=(-b+sqrt(delta))/2*a;
cout << kok1 << "\t" << kok2 << endl;
}
else
cout << "Gercek kok yok." << endl;
}
void Polinom::set_a(float _a) atama fonksiyonları tanımlanıyor
{
a=_a;
}
void Polinom::set_b(float _b)
{
b=_b;
}
void Polinom::set_c(float _c)
{
c=_c;
}
Polinom islem(Polinom A, Polinom B, char i) polinomların toplanmasını sağlıyor
{
Polinom sonuc;
if(i=='+')
{
sonuc.set_a(A.get_a()+B.get_a());
sonuc.set_b(A.get_b()+B.get_b());
sonuc.set_c(A.get_c()+B.get_c());
}
else if(i=='-') farkının alınmasını sağlıyor
{
sonuc.set_a(A.get_a()-B.get_a());
sonuc.set_b(A.get_b()-B.get_b());
sonuc.set_c(A.get_c()-B.get_c());
}
else
cout << "Girdiginiz islem yanlis.";
return sonuc;
}
Polinom islem(Polinom A, Polinom B)
{
Polinom sonuc;
sonuc.set_a(A.get_a()+B.get_a());
sonuc.set_b(A.get_b()+B.get_b());
sonuc.set_c(A.get_c()+B.get_c());
return sonuc;
}
int main()
{
Polinom P1(0,4,4),P2(1,2,2),P3; nesneler aracılığı ile değrler gönderiliyor
P3=islem(P1,P2); p3 polinomu oluşturuluyor
cout << P3.get_a() << " " << P3.get_b() << " " << P3.get_c() << endl; ekrana yazdırılıyor
return 0;
}
EKRAN ÇIKTISI
0 yorum:
Yorum Gönder
yorum yaz