201-guruh talabasi Rustamov Farruxning Mustaqil ishi
Download 107.08 Kb.
|
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!"< { cout<<"x1= "< 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!"< { cout<<"x1= "< { cout<<"x1 == x2 == x3 == x4 = "< { cout<<"x1= "< else if(getx1()==0 && getx2()>0) { cout<<"x1= "< 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!"< } }; 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; } 0> Download 107.08 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling