Toshquvvatov Samandar swd014-L3 guruh talabasi 8-laboratoriya ishi
Download 117.5 Kb.
|
Labaratoriya ishi 8 Suyunova M
- Bu sahifa navigatsiya:
- Topshiriq
Toshquvvatov Samandar SWD014-L3 guruh talabasi 8-laboratoriya ishi 12-variant OYD da juda murakkab saralash algoritmlari asosida dasturlar yaratish 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. 1. class hayvonlar: nomi, necha_yili_yashashi class parrandalar : turi
yashash joyi, Array konteniridan foydalanib ishchilar parrandalar ro’yxatida necha yil yashashi bo’yicha saralang. #include #include #include #include #include using namespace std; int n; class hayvonlar { public:
string nomi; int yil_yashash; }; class parranda:public hayvonlar{ public: string turi; string yashash_joyi; parranda(string nom, string t, int yy, string m){ this->nomi = nom; this->turi = t; this->yil_yashash = yy; this->yashash_joyi = m; } int gety(){ return yil_yashash; } string getn(){ return nomi; } string gett(){ return turi; } string getyj(){ return yashash_joyi; } void print() { cout < }
};
{ int yy; string nom, t, yj; cout<<"Parrandalar soni: "; cin>>n; for(int i=0; i cin>>nom; cout<
cin>>t;
cout<cin>>yj; cout< } }
l) { cout<<"\n Nomi | turi | yashash yili | yashash manzili\n"; list ::iterator itr; for (itr = l.begin(); itr != l.end(); itr++)
{ (*itr).print(); } }
l){ list
int a[n],k=0; string b[n], c[n], d[n]; for (itr = l.begin(); itr != l.end(); itr++) {
b[k]=(*itr).getn(); c[k]=(*itr).gett(); d[k]=(*itr).getyj(); k++;
} for (int gap = k / 2; gap > 0; gap /= 2) { for (int i = gap; i < k; i += 1) { int temp = a[i]; int j; for (j = i; j >= gap && a[j - gap] > temp; j -= gap) a[j] = a[j - gap]; a[j] = temp; } } list
for (int i = 0; i l1.push_back(parranda(b[i], c[i], a[i], d[i]));
}
print(l1); int main() { list
add(hayvon); print(hayvon); printf("\nSorting list:\n"); //Shell sort Shell(hayvon); } 2. “Sovitgich” classini yarating. Maydonlari: Marka, Model, Narx,bo’yi_sm, eni_sm. Array konteniridan foydalanib narxi bo’yicha saralang. (kamida 37 xonali sonlar ketma-ketnligidan iborat bo‘lsin). #include #include #include #include #include using namespace std; class sovitgich{ public: string marka; string model; string narx; int buy; int eni;
sovitgich(string ma, string mo, int b, int e, string n){ this->marka = ma; this->model = mo; this->buy = b; this->eni = e; this->narx = n; } void print() { cout < }
};
int n; int b, e; string ma,mo,narx; cout<<"Sovitgich soni: "; cin>>n; for(int i=0; i cin>>ma;
cout<<"Sovitgich Modeli: "; cin>>mo;
cout<<"Sovitgich bo'yi: "; cin>>b;
cout<<"Sovitgich eni: "; cin>>e;
cout<<"Sovitgich Narxi: "; cin>>narx; cout< v.push_back(sovitgich(ma,mo,b,e,narx)); }
}
cout<<"\n Marka | Model | buyi | eni | narxi:\n"; vector for (itr = v.begin(); itr != v.end(); itr++)
{ (*itr).print(); } }
{ int n1 = lhs.narx.length(), n2 = rhs.narx.length(); if (n1 < n2) return true; if (n2 < n1) // Agar uzunliklar bir xil bo'lsa for (int i=0; i { if (lhs.narx[i] < rhs.narx[i])
return true; if (lhs.narx[i] > rhs.narx[i])
return false; } return false;
}
int main() vector add(vec); printvec(vec); cout<<"\n\nSaralangan holda: \n"; sort(vec.begin(), vec.end(), sortBynarx); printvec(vec); } Download 117.5 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling