1- laboratoriya ishi obyektga yo’naltirilgan dasturlash
Download 33.37 Kb.
|
1-lab 10 topshiriq(moodle)
1- LABORATORIYA ISHI OBYEKTGA YO’NALTIRILGAN DASTURLASH Noma’lum turlar va noma’lum nomlar fazosi Kitob va daftar class larini yarating va ularni bog’lovchi funksiyalar yarating. Dastur kodi: #include #include using namespace std; class oquv_qurollari { private: string rangi; string material; public: oquv_qurollari (string rang, string materal ){ this ->rangi= rang; this ->material= materal; } virtual string getrang (){ return rangi; } virtual string getmaterial (){ return material;} }; class kitob : public oquv_qurollari{ public: kitob (string rangi, string material): oquv_qurollari(rangi, material){ } }; class daftar : public oquv_qurollari { public: daftar (string rangi , string material ): oquv_qurollari (rangi, material){} }; int main (){ kitob K= kitob ("qora","qog'ozdan"); daftar D= daftar ("yashil","qog'ozdan"); cout<<"\n"; cout<<" kitob rangi : "< cout<<" daftar rangi : "< Classlar o’rtasida vorislikni tashkil qilish. Overriding va overloading bo’ladigan funksiyalarni yaratish
Dastur kodi: #include #include using namespace std; class Firma_xodimi { private: string FIO; string lavozimi; double maoshi; double yoshi; double foiz; public: Firma_xodimi (string FIO, double maoshi, string lavozimi, double yoshi){ FIO=FIO; maoshi = maoshi; lavozimi=lavozimi; yoshi=yoshi; } string getFIO (){ return FIO; } double getmaoshi(){ return maoshi; } string getlavozimi (){ return lavozimi;} double getyoshi (){ return yoshi; } double getfoiz ( int oylik){ foiz=maoshi; if (yoshi<=35){ foiz=foiz+ (maoshi)*(20)/100; } return foiz; } }; int main (){ string FIO, lavozimi; double maoshi, yoshi; int oylik; cout<<"\n firma xodimini nomini kiriting : "; cin>>FIO; cout<<" xodimning maoshini kiriting kiriting : "; cin>>maoshi; cout<<" xodim lavozimini kiriting : "; cin>>lavozimi; cout<<" xodim yoshini kiriting : "; cin>>yoshi; cout<<" 20 % bonus bor : "; cin>>oylik; cout<<"_________________________________________\n\n"; Firma_xodimi fir=Firma_xodimi (FIO, maoshi, lavozimi, yoshi ); cout<<" FIO : "< cout<<" Xodimning maoshi : "<
Dastur kodi: #include #include using namespace std; namespace Movie { class Kinofilm { private: string name, rname; double time, asoni, narxi; public: Kinofilm(){}; Kinofilm (string nam, string rnam, double tim, double ason): name(nam), rname(rnam), time ( tim), asoni (ason) {} virtual double getnarx (){ narxi= ( time )*20+(asoni)*30; if (rname=="Stiven_Spilberg" || rname=="Djeyms_Kemeron"){ narxi*=2; } return narxi; } virtual void Axborot (){ cout<<" Kinofilm nomi -> "< }; class Multfilm : public Kinofilm{ private: string mname, mrname; double mtime, masoni, mnarxi; public: Multfilm(string mnam, string mrnam, double mtim, double mason): mname(mnam), mrname(mrnam), mtime(mtim), masoni(mason) {} double getnarx (){ mnarxi= ( mtime )*25+(masoni)*10; return mnarxi; } void Axborot (){ cout<<" Multfilm nomi -> "< }; } using namespace Movie; int main (){ int a; cin>>a; Kinofilm kino=Kinofilm ( "3_savdoyi", "Stiven_Spilberg", 150,40 ); Multfilm mult= Multfilm( "Garry_Potor","Stiven_Spilberg", 100,30); Kinofilm kino1=Kinofilm ( "Karib_dengiz_qaroqchilari", "Djeyms_Kemeron", 145,35 ); Multfilm mult1= Multfilm( "Ov_mavsumi","Djeyms_Kemeron", 100,30); if(a==1){ cout<<" kinofilm 1 \n"; kino.Axborot();} if (a==2){ cout<<" kinofilm 2 2\n"; kino1.Axborot();} cout<<"____________________________________\n"; if (a==3){ cout<<" multfilm 1 \n"; mult.Axborot();} if (a==4){ cout<<" multfilm 2 \n"; mult1.Axborot();} main (); } Download 33.37 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling