DASTURLASH
Topshirdi: Mirzamahmudov G’ayrajon
Tek: Aliqulov Akmal
#include
#include
#include
#include
#include
#pragma warning(disable: 4996);
template struct NoAction {
bool operator()(T a, T b) const {
return false;
}
};
using namespace std;
class Zaprafka {
public:
Zaprafka() {}
string nomi, turi, versiya, hajmi;
int yili;
Zaprafka(string a, string b, string c, string d, string e, int f, int g) :
nomi(a), turi(b), versiya(c), hajmi(d), yili(g) {}
friend void search(multiset> jm, string a, char e) {
multiset> tr;
int b;
stringstream(a) >> b;
if (e == '0') for (auto t : jm) if (t.nomi == a)
{
printf("Nomi: %s, Turi: %s, Yoqilg'i turi: %s, Hajmi: %s, Sana: %d\n", t.nomi.c_str(), t.turi.c_str(), t.versiya.c_str(), t.hajmi.c_str());
tr.insert(t);
}
if (e == '1') for (auto t : jm) if (t.turi == a)
{
printf("Nomi: %s, Turi: %s, Yoqilg'i turi: %s, Hajmi: %s, Sana: %d\n", t.nomi.c_str(), t.turi.c_str(), t.versiya.c_str(), t.hajmi.c_str());
tr.insert(t);
}
if (e == '2') for (auto t : jm) if (t.versiya == a)
{
printf("Nomi: %s, Turi: %s, Yoqilg'i turi: %s, Hajmi: %s, Sana: %d\n", t.nomi.c_str(), t.turi.c_str(), t.versiya.c_str(), t.hajmi.c_str());
tr.insert(t);
}
if (e == '3') for (auto t : jm) if (t.hajmi == a)
{
printf("Nomi: %s, Turi: %s, Yoqilg'i turi: %s, Hajmi: %s, Sana: %d\n", t.nomi.c_str(), t.turi.c_str(), t.versiya.c_str(), t.hajmi.c_str());
tr.insert(t);
}
if (e == '4') for (auto t : jm)
{
printf("Nomi: %s, Turi: %s, Yoqilg'i turi: %s, Hajmi: %s, Sana: %d\n", t.nomi.c_str(), t.turi.c_str(), t.versiya.c_str(), t.hajmi.c_str());
tr.insert(t);
}
if (e == '5') for (auto t : jm)
{
printf("Nomi: %s, Turi: %s, Yoqilg'i turi: %s, Hajmi: %s, Sana: %d\n", t.nomi.c_str(), t.turi.c_str(), t.versiya.c_str(), t.hajmi.c_str());
tr.insert(t);
}
if (e == '6') for (auto t : jm) if (t.yili == b)
{
printf("Nomi: %s, Turi: %s, Yoqilg'i turi: %s, Hajmi: %s, Sana: %d\n", t.nomi.c_str(), t.turi.c_str(), t.versiya.c_str(), t.hajmi.c_str());
tr.insert(t);
}
cout << "C diskdagi output.txt ga soxranit qilaylikmi [y/n] = ";
char t;
cin >> t;
if (t == 'y') {
FILE* f = fopen("C:\\output.txt", "w");
for (auto t : tr)
fprintf(f, "Nomi: %s, Turi: %s, Yoqilg'i turi: %s, Hajmi: %s, FIK: %d, Yadrosi: %s, Sana: %d\n", t.nomi.c_str(), t.turi.c_str(), t.versiya.c_str(), t.hajmi.c_str());
}
else return;
}
friend void searchBy(multiset> jm) {
char t;
cout << "Nima bo'yicha qidirmoqdasiz : [0,1,2,3,4,5,6] = ";
cin >> t;
string name;
cout << "Tekshiruvning matnini kirgazing: ";
cin >> name;
search(jm, name, t);
}
friend multiset> MakeSetT(multiset> jm, char e) {
multiset> tr;
if (e == '0') for (auto t = jm.begin(); t!=jm.end();) {
int key = 0;
for (auto e = jm.begin(); e != jm.end(); ++e) if (t != e && t->nomi == e->nomi) { key = 1; break; };
if (!key) t = jm.erase(t);
else t++;
}
if (e == '1') for (auto t = jm.begin(); t != jm.end();) {
int key = 0;
for (auto e = jm.begin(); e != jm.end(); ++e) if (t != e && t->turi == e->turi) { key = 1; break; };
if (!key) t = jm.erase(t);
else t++;
}
if (e == '2') for (auto t = jm.begin(); t != jm.end();) {
int key = 0;
for (auto e = jm.begin(); e != jm.end(); ++e) { key = 1; break; };
if (!key) t = jm.erase(t);
else t++;
}
return jm;
}
void kiritish() {
cout << "Mashina nomi: ";
cin >> nomi;
cout << "Yoqilg'i turi : ";
cin >> versiya;
cout << "Hajmi: ";
cin >> hajmi;
cout << "yil : ";
cin >> yili;
cout << endl;
}
};
int main() {
multiset> mashina;
int a;
cout << " Mashinalar soni : ";
cin >> a;
for (int c = 0; c < a; c++) {
Zaprafka t;
t.kiritish();
mashina.insert(t);
}
multiset> toplam2 = MakeSetT(mashina, '0'), toplam3 = MakeSetT(mashina, '1'), toplam4 = MakeSetT(mashina, '2');
searchBy(mashina);
}
Do'stlaringiz bilan baham: |