Ajdod class va uning maydonlari



Download 0,71 Mb.
Sana23.07.2022
Hajmi0,71 Mb.
#844328
Bog'liq
Dasturlash 5- laboratoriya


Jo`rayev Bekzod
Dasturlash 5-laboratoriya ishi
1 - mashq.



Ajdod class va uning maydonlari

Voris class (ajdod class maydonlaridan foydalangan holda)

Obektlar massivini yarating.
Murakkab saralash algortimlaridan foydalanib saralash metodlari yarating.
(saralang o’sib borish tartibida yoki kamayib borish tartibida va alifbo tartibida)

11.

class tovar:
nomi,
narxi,
chiqarilgan yili

class dori_darmonlar;
saqlanish_muddati

Array konteyneridan foydalanib ishchilar dori darmonlar ro’yxatida chiqarilgan yili bo’yicha saralang.



#include

using namespace std;

class product {


public:
string name;
float price{};
int produced_year{};
};

class Drugs : public product {


public:
int keepingLimit{};
public:
void set();

int getKeepingLimit() const;



string getName();

int getProducedYear();

float getPrice();

string toString();
};

void Drugs::set() {


cout << "Item Name = ";
cin >> name;
cout << "Price = ";
cin >> price;
cout << "Produced year = ";
cin >> produced_year;
cout << "Keeping limit by years = ";
cin >> keepingLimit;
}

string Drugs::getName() {
return this->name;
}

int Drugs::getProducedYear() {
return this->produced_year;
}

float Drugs::getPrice() {
return this->price;
}

int Drugs::getKeepingLimit() const {
return this->keepingLimit;
}

string Drugs::toString() {
return "{ nomi : " + this->getName() + ", narxi : " + to_string(this->getPrice()) +
", ishlab chiqarilgan yili : " + to_string(this->getProducedYear()) +
", saqlash muddati : " + to_string(this->getKeepingLimit()) + " }";
}

void sortingByProducedYear(Drugs drugs[], int length) {
int swapCount = -1, keptSwapCount = 0;
while (swapCount != keptSwapCount) {
swapCount = keptSwapCount;
for (int index = 0; index < length; ++index)
if (drugs[index].getProducedYear() - drugs[index + 1].getProducedYear() < 0) {
Drugs temp = drugs[index];
drugs[index] = drugs[index + 1];
drugs[index + 1] = temp;
swapCount++;
}
}
}

void print(Drugs drugs[], int length) {
for (int i = 0; i < length; i++)
cout << i + 1 << ". dori - " << drugs[i].toString() << endl;

}

int main() {
int n;
cout << "dorilar sonini kiritiong - ";
cin >> n;
Drugs drugs[n];
for (int i = 0; i < n; i++) {
cout << i + 1 << ". Drug fields " << endl;
drugs[i].set();
}
sortingByProducedYear(drugs, n);
print(drugs, n);
}

2 - mashq.



11.

Kinofilmlar” classini yarating.
Maydonlari: Nomlanishi, davomiyligi (minut da), aktyorlar soni.
Deque konteyneridan foydalanib davomiyligi bo’yicha saralang.
(kamida 29 xonali sonlar ketma-ketligidan iborat bo‘lsin).



#include
#include
#include

using namespace std;

class Films {


private:
string name;
string duration;
int amountOFActors{};
public:
void setFilm();

string getName() const;

string getDuration() const;

int getAmountOfActors() const;



string toString() const;

};

void Films::setFilm() {


cout << "Name = ";
cin >> this->name;
cout << "Duration (in Minutes) = ";
cin >> this->duration;
cout << "Amount of played Actors = ";
cin >> this->amountOFActors;
}

string Films::getName() const {
return name;
}

string Films::getDuration() const {
return this->duration;
}

int Films::getAmountOfActors() const {
return this->amountOFActors;
}

string Films::toString() const {
return "{ nomi : " + this->getName() + ", davomiyligi : " + this->getDuration() +
", qatnashgan aktyorlar soni : " + to_string(this->getAmountOfActors()) + " }";
}

bool comparing(const Films& film1, const Films& film2) {
if (film1.getDuration().length() > film2.getDuration().length())
return true;
else if (film1.getDuration().length() < film2.getDuration().length())
return false;
for (int i = 0; i < film1.getDuration().length(); ++i)
if ((int)film1.getDuration()[i] > (int)film2.getDuration()[i])
return true;
else if((int)film1.getDuration()[i] < (int)film2.getDuration()[i])
return false;
return false;
}

void print(deque films) {
deque::iterator it;
for (it = films.begin(); it != films.end(); ++it)
cout << it->toString() << endl;
}

int main() {
int n;
cout << "Please enter amount of movies - ";
cin >> n;

deque films;

for (int i = 0; i < n; ++i) {


Films aFilm;
cout << i+1 << " - kino " << endl;
aFilm.setFilm();
films.push_back(aFilm);
}

sort(films.begin(), films.end(), comparing);



deque::iterator it;

print(films);

return 0;


}

Download 0,71 Mb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish