Dasturlash 2 fanidan labaratoriya ishi
Download 16.08 Kb.
|
8- labaratoriya
- Bu sahifa navigatsiya:
- OYD da juda murakkab saralash algoritmlari asosida dasturlar yaratish.
- Ajdod class va uning maydonlari Voris class (ajdod class maydonlaridan foydalangan holda)
- (saralang o’sib borish tartibida yoki kamayib borish tartibida va alvabet tartibida)
- 2-topshiriq.
- Fotoapparatlar”
O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI Dasturlash kafedrasi Dasturlash 2 fanidan LABARATORIYA ISHI MAVZU: OYD da juda murakkab saralash algoritmlari asosida dasturlar yaratish. Bajardi: 015L2 guruh talabasi KARIMOV UMIRZOQ Toshkent 2020 MAVZU: OYD da juda murakkab saralash algoritmlari asosida dasturlar yaratish . 1-topshiriq. Ishning maqsadi: C++ tilida classlar, kontener ko’nikmalari asosida murakkab saralash algortimlarni imkoniyatlaridan foydalanib dasturlash bilimlarini shakllantirish. Topshiriq: Berilgan class va kontenerlar orqali murakkab saralash algoritmlaridan foydalanib dastur yozing.
#include #include #include #include #include using namespace std; #define EBB cout<<"==========================================================\n" class football { public: string ism, fam, sh; long long daromadi; double yoshi; }; class tens : public football { public: double lengtha; tens (string ism, string fam, string sh, long long daromadi, double yoshi, double lengtha){ this->ism=ism; this->fam=fam; this->sh=sh; this->daromadi=daromadi; this->yoshi=yoshi; this->lengtha=lengtha; } void getten() { cout<<ism<<"\t"<<fam<<"\t"<<sh<<endl; cout<<"daromadi-> "<<daromadi<<"\n"<<"yoshi-> "<<yoshi<<"\n"<<"bo'yi uzunligi-> "<<lengtha<<endl; EBB; } }; bool lengths (tens &E, tens &B) { return (E.lengtha > B.lengtha); } int main () { int n; cout<<" Tenschilar necha kishi -> "; cin>>n; string is,f,s; long long d; double y,b; vector< tens > ebb; for (int i = 0; i < n; i++) { cout<<i+1<<"- tenschi ismi -> "; cin>>is; cout<<i+1<<"- tenschi familyasi -> "; cin>>f; cout<<i+1<<"- tenschi sharifi -> "; cin>>s; cout<<i+1<<"- tenschi yillik daromadi -> "; cin>>d; cout<<i+1<<"- tenschi yoshi -> "; cin>>y; cout<<i+1<<"- tenschi bo'yi uzunligi -> "; cin>>b; ebb.push_back( tens (is,f,s,d,y,b)); } EBB; sort(ebb.begin(), ebb.end(),lengths); vector<tens>::iterator ee; for ( ee = ebb.begin(); ee != ebb.end(); ++ee) { tens b= *ee; b.getten(); } system("pause"); } 2-topshiriq.
#include #include #include #include #include using namespace std; #define EBB cout<<"===========================================\n" class photoapparat { public: string model; string pixsel; long long narx, xajm; photoapparat(string model, string pixsel, long long narx, long long xajm){ this->model=model; this->pixsel=pixsel; this->narx=narx; this->xajm=xajm; } // KARIMOV UMIRZOQ string getmodel (){ return model; } string getpixsel (){ return pixsel; } long long getnarx(){ return narx; } long long getxajm(){ return xajm; } void malumot (){ cout<<" fotoapparat nomi -> "<<getmodel()<<endl; cout<<" fotoapparat pixseli -> <"<<getpixsel()<<">"<<endl; cout<<" fotoapparat narxi -> "<<getnarx()<<" $ "<<endl; cout<<" fotoapparat xajmi -> "<<getxajm()<<" MB "<<endl; EBB; } }; // pixselini o'sib borish tartibida saraladim. bool intsort (photoapparat &A, photoapparat &B) { int n1=A.getpixsel().length(), n2=B.getpixsel().length(); if (n1<n2) return true; if (n2<n1) return false; for (int i=0; i<n1; i++) { if (A.getpixsel()<B.getpixsel()) return true; if (A.getpixsel()>B.getpixsel()) return false; } return false; } int main (){ int n; cout<<" Fotoapparratlar sonini kiriting "; cin>>n; string mod; string pix; long long narx, xajm; vector<photoapparat> aa; for (int i = 0; i < n; i++) { // KARIMOV UMIRZOQ cout<<i+1<<" - fotoapparat ma'lumotlarini kiriting :\n"; cout<<" modeli -> "; cin>>mod; cout<<" pixseli -> "; cin>>pix; cout<<" narxi -> "; cin>>narx; cout<<" xajmi -> "; cin>>xajm; EBB; aa.push_back(photoapparat(mod,pix,narx,xajm)); } vector<photoapparat>::iterator bb; sort(aa.begin(), aa.end(), intsort); for(bb=aa.begin(); bb!=aa.end(); ++ bb ){ photoapparat ab= *bb; ab.malumot(); } system("pause"); } Download 16.08 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling