10-mavzu 9-masala “Kutubxona”
Download 134.69 Kb.
|
JAVOB-10-MAVZU AMALIY DASTURLASH-2-PROG26MBK last.pdf
10-MAVZU 9-masala “Kutubxona” classini yarating. Maydoni:nomi,mualifi,saxifalar_soni,janri Array konteyneridan foydalanib saxifalar_soni bo’yicha saralang. (kamida 33 xonali sonaar ketma-ketligidan iborat bo‘lsin). Dasturi: #include #include #include #include #include using namespace std; class Kutubxona { private: string nom; string muallif; string janr; public:
void input() { cout << "\n Kitob nomi: "; getline(cin, nom); getline(cin, nom); cout << " Muallifi: "; getline(cin, muallif); cout << " Sahifalar soni: "; cin >> saxifalar_soni; cout << " Janri: "; cin >> janr; } void output() { cout << " " << nom << " " << muallif << " " << janr << " " << " " << saxifalar_soni << endl; } }; bool solishtir(string s1, string s2) { if (s1.length() != s2.length()) return s1.length() < s2.length(); else return s1 < s2; } int main() { array int na; cout << "\n Kitoblar sonini kiriting: "; cin >> na; for (int i = 0; i < na; i++) { cout << "\n"; cout << "------- " << i + 1 << " -------" << endl; A_T_ob_arr1[i].input(); } int min_index = 0; for (int i = 0; i < na - 1; i++) { min_index = i; for (int j = i + 1; j < na; j++) { if (solishtir(A_T_ob_arr1[j].saxifalar_soni, A_T_ob_arr1[min_index].saxifalar_soni)) { min_index = j; } } Kutubxona temp; temp = A_T_ob_arr1[min_index]; A_T_ob_arr1[min_index] = A_T_ob_arr1[i]; A_T_ob_arr1[i] = temp; } cout << "\n Barcha kitoblar sahifalar soni bo'yicha saralandi:\n " << endl; for (int i = 0; i < na; i++) { cout << "|] " << setw(3) << i + 1; A_T_ob_arr1.at(i).output(); cout << endl; } cout << endl; system("pause"); return 0; } Download 134.69 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling