#include
#include
#include
using namespace std;
namespace cars
{
class car_store
{
char nomi[100];
public:
int narxi;
char fabric[20];
void enter()
{
cout << "avtomobil nomini kiriting : ";
cin >> nomi;
cout << "avtomobil narxini kiriting : ";
cin >> narxi;
cout << "Ishlab chiqarilgan fabrikasi : ";
cin >> fabric;
}
void show()
{
cout << endl << "avtomobil nomi : " << nomi << endl;
cout << "Narxi : " << narxi << " so'm" << endl;
cout << "Ishlab chiqarilgan fabrikasi : " << fabric << endl;
}
friend void search(car_store shop[], int n);
};
void search(car_store shop[], int n)
{
char nomi_u[100];
cout << "\n1)Nomi bo'yicha qidirish\n2) ishlab chiqarilgan fabrika bo'yicha
qidirish\n->";
int a; cin >> a;
if (a == 1) {
cout << "\nLoading...\nQidirilayotgan avtomobil nomini kiriting : ";
cin >> nomi_u;
bool info = false;
for (int i = 0; i < n; i++)
{
if (strcmp(shop[i].nomi, nomi_u) == 0)
{
shop[i].show();
info = true;
break;
}
}
if (info == false)
{
cout << "\nXatolik yuz berdi...\n";
}
}
else if (a == 2) {
cout << "\nLoading...\nQidirilayotgan fabrika nomini kiriting : ";
cin >> nomi_u;
bool info = false;
for (int i = 0; i < n; i++)
{
if (strcmp(shop[i].fabric, nomi_u) == 0)
{
shop[i].show();
info = true;
break;
}
}
if (info == false)
{
cout << "\nXatolik yuz berdi ! \n";
}
}
}
void sort(car_store nomi_u[], int n) {
cout << "\nLoading...\nNarxi bo'yicha saralash->\n";
{
for (int i = 0; i < n - 1; i++)
{
for (int j = i + 1; j < n; j++)
{
if (nomi_u[i].narxi < nomi_u[j].narxi)
{
swap(nomi_u[i], nomi_u[j]);
}
}
}
cout << "\navtomobilning narxi bo'yicha saralangan ro'yxati :\n";
for (int i = 0; i < n; i++)
{
nomi_u[i].show();
}}
}
}
using namespace cars;
int main()
{
car_store nomi[20];
int n;
kiritish: {
cout << "Kiritilayotgan ro'yxatdagi avtomobillar soni - ";
cin >> n;
for (int i = 0; i < n; i++)
{
cout << i + 1 << " - avtomobil haqidagi ma'lumotlarini kiriting:\n";
nomi[i].enter();
}
}
takror:
{
cout << "Metodlardan birini tanlang :\n1)Ma'lumotlarni qayta
kiritish\n2)Qidirish\n3)Saralash\n->";
int metod; cin >> metod;
switch (metod) {
case 1: goto kiritish; break;
case 2: search(nomi, n); break;
case 3: sort(nomi, n); break;
default: cout << "\nBunday amal mavjud emas ! \n";
}
}
cout << " Yana biror amal bajarasizmi ? \n1)HA\n2)YO'Q\n->";
int num;
cin >> num;
if (num == 1) {
goto takror;
}
else return 0;
system("Pause");
return 0;
}
Do'stlaringiz bilan baham: |