Jo’rayev Xudoyshukur 8-variant
------------------------------------------------------------------------------------------
Ta’mirlash ustaxonasida bir nechta (N ta) mashina bor. Ular to‘g‘risida quyidagi ma’lumotlarga
egamiz: raqami, markasi, egasining ismi, oxirgi marta ta’mirlanganligi sanasi (kuni, oyi, yili),
ta’mirdan chiqishi lozim bo‘lgan sana (kun, oy, yil).
To‘g‘ridan-to‘g‘ri qo‘shish usulidan foydalanib, saralashni amalga
oshirish dasturini ishlab chiqish (variantga mos ravishda):
O‘tgan yildan beri ta’mirlanmagan mashinalarni ularning egalari ismlari
bo‘yicha alifbo tartibida joylashtiring.
------------------------------------------------------------------------------------------
#include
using namespace std;
class Mashina{
public:
string raqami;
string markasi;
string egasiIsmi;
string oxirgiTamir;
string tamirTugashi;
Mashina(){}
Mashina(string raqami, string markasi, string egasiIsmi, string oxirgiTamir, string tamirTugashi){
this->raqami = raqami;
this->markasi = markasi;
this->egasiIsmi = egasiIsmi;
this->oxirgiTamir = oxirgiTamir;
this->tamirTugashi = tamirTugashi;
}
void toString(){
cout << "Mashina(" << this->raqami << ", " << this->markasi << ", " << this->egasiIsmi << ", "
<< this->oxirgiTamir << "," << this->tamirTugashi << ")" << endl;
}
};
void print(Mashina mashinalar[], int size){
for(int i = 0; i < size; i++){
mashinalar[i].toString();
}
}
int main()
{
// Hayoliy mashinalar hosil qilamiz...
Mashina mashina1 = Mashina("75 A 437 BA", "Chevrolet", "Akbar", "12.10.2019", "15.10.2020");
Mashina mashina2 = Mashina("70 Y 740 SA", "Toyota", "Shokir", "09.09.2019", "12.09.2020");
Mashina mashina3 = Mashina("01 S 235 FD", "Mers", "Behzod", "11.11.2019", "14.11.2020");
Mashina mashina4 = Mashina("10 T 831 HG", "BMW", "Donyor", "17.08.2020", "20.08.2020");
Mashina mashina5 = Mashina("85 D 583 JK", "Tesla", "Hayrulla", "19.09.2019", "23.09.2020");
Mashina mashina6 = Mashina("30 B 825 UY", "Tesla", "Ilhom", "24.10.2020", "27.10.2020");
Mashina mashina7 = Mashina("25 F 046 YA", "Toyota", "Azamat", "28.10.2019", "31.10.2020");
Mashina mashinalar[] = {mashina1, mashina2, mashina3, mashina4, mashina5, mashina6,
mashina7};
Mashina selected[7];
int k = 0;
for(int i = 0; i < 7; i++){
string date = mashinalar[i].oxirgiTamir;
string year = date.substr(6, 9);
if(year == "2019"){
selected[k] = mashinalar[i];
k++;
}
}
cout << "Jami mashinalar" << endl;
print(mashinalar, 7);
cout << "\nO'tgan yildan beri te'mirlanmaganlar" << endl;
print(selected, k);
for(int i = 0; i < k-1; i++){
for(int j = i+1; j < k; j++){
if(selected[i].egasiIsmi > selected[j].egasiIsmi){
Mashina mashina = selected[i];
selected[i] = selected[j];
selected[j] = mashina;
}
}
}
cout << "\nSaralangandan so'ng" << endl;
print(selected, k);
return 0;
}
Do'stlaringiz bilan baham: |