201-guruh talabasi Rustamov Farruxning Mustaqil ishi


Download 107.08 Kb.
bet2/4
Sana18.06.2023
Hajmi107.08 Kb.
#1572788
1   2   3   4
Bog'liq
Rustamov Programalash maruza

Mustaqil ish-2
Tenglama, bikvadrat tenglama, kubik tenglama, chiziqli tenglamalarga bog’lab kiritilgan kvadrat tenglama sinflari mavjud bu sinflarda tenglama yechimi degan virtual funksiya hosil qiling. Har biridan 10tadan tenglama yechimi olinsin.
Dastur kodi:
#include
using namespace std;
class Tenglama
{ public:
virtual float yechim() { cout<<"Yechimlar"; }
};
class Kv_tenglama: public Tenglama
{ private:
float a,b,c,x1,x2,dt;
public:
Kv_tenglama(float a, float b, float c)
{
this->a=a;
this->b=b;
this->c=c;
}
float getDt() { return dt=b*b-4*a*c; }
float getx1() { return x1=(-b-sqrt(getDt()))/(2*a); }
float getx2() { return x2=(-b+sqrt(getDt()))/(2*a); }
virtual float yechim()
{ cout<<"\t\tKvadrat tenglama yechimlari!"<if(getDt()>0)
{ cout<<"x1= "<cout<<"x2= "<else if(getDt()==0) cout<<"x1 == x2 = "<else cout<<"Kvadrat tenglama yechimga ega emas"<} };
class Bkv_tenglama:public Tenglama
{
private:
float a,b,c,x1,x2,t1,t2,dt;
public:
Bkv_tenglama(float a, float b, float c)
{
this->a=a;
this->b=b;
this->c=c;
}
float getDt() { return dt=pow(b,2)-4*a*c; }
float getx1() { return x1=(-b-sqrt(getDt()))*1./(2*a); }
float getx2() { return x2=(-b+sqrt(getDt()))*1./(2*a); }
float gett1() { return t1=sqrt(x1); }
float gett2() { return t2=sqrt(x2); }
virtual float yechim()
{
cout<<"\t\tBikvadrat tenglama yechimlari!"<if(getx2()>0&&getx1()>0)
{ cout<<"x1= "<cout<<"x2= "<<-gett1()<cout<<"x3= "<cout<<"x4= "<<-gett2()<else if(getx1()==0 && getx2()==0)
{ cout<<"x1 == x2 == x3 == x4 = "<else if(getx1()<0 && getx2()>0)
{
cout<<"x1= "<cout<<"x2= "<<-gett2()<}
else if(getx1()==0 && getx2()>0)
{
cout<<"x1= "<cout<<"x2= "<cout<<"x3= "<<-gett2()<}
else cout<<"Bikvadrat tenglama yechimga ega emas!!"<};
class Ch_tenglama:public Tenglama
{
private:
float a,b,x;
public:
Ch_tenglama(float a, float b)
{
this->a=a; this->b=b;
}
float getx()
{ return x=(-b)*1./a; }
virtual float yechim()
{ cout<<"\t\tChiziqli tenglama yechimlari!"<if(a!=0) cout<<"x= "<else cout<<"Yechim mavjud emas!!!"<< endl;
} };
int main()
{
float a,b,c,d;
cout<<" a = "; cin>>a;
cout<<" b = "; cin>>b;
cout<<" c = "; cin>>c;
Kv_tenglama kv(a,b,c);
Tenglama *Kv= &kv;
Kv->yechim();
Bkv_tenglama bkv(a,b,c);
Tenglama *Bkv=&bkv;
Bkv->yechim();
Ch_tenglama ch(a,b);
Tenglama *Ch=&ch;
Ch->yechim();
return 0;
}


Download 107.08 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling