Mashina va motosikl class larini yarating va ularni bog’lovchi funksiyalar yarating


Download 192.65 Kb.
Sana31.03.2023
Hajmi192.65 Kb.
#1312936

18-variant
Mashina va motosikl class larini yarating va ularni bog’lovchi funksiyalar yarating.

#include "stdafx.h"


#include
#include
using namespace std;
class Mashina
{
private:
string name, brend;
int narxi, tezlik;

public:
Mashina(){};


Mashina(string name, string brend, int narxi, int tezlik)
{
this->name = name;
this->brend = brend;
this->narxi = narxi;
this->tezlik = tezlik;
}
friend void chiqarish(Mashina);
int narx()
{
return this->narxi;
}
int tez()
{
return this->tezlik;
}
};
void chiqarish(Mashina m)
{
cout << "Nomi: " << m.name << " Brendi: " << m.brend << " Narxi:" << m.narxi << " Tezligi:" << m.tezlik << endl;
}
class Motosikl
{
private:
string name, brend;
int narxi, tezlik;

public:
Motosikl(){};


Motosikl(string name, string brend, int narxi, int tezlik)
{
this->name = name;
this->brend = brend;
this->narxi = narxi;
this->tezlik = tezlik;
}
friend void chiqarish(Motosikl);
int narx()
{
return this->narxi;
}
int tez()
{
return this->tezlik;
}
};
void chiqarish(Motosikl m)
{
cout << "Nomi: " << m.name << " Brendi: " << m.brend << " Narxi:" << m.narxi << " Tezligi:" << m.tezlik << endl;
}
int main()
{
int n;
cout << "Mashinalar va Motosikl sonini kiriting: ";
cin >> n;
Mashina *moshina = new Mashina[n];
Motosikl *motosikl = new Motosikl[n];
string name, brend;
int narxi, tezlik;
for (int i = 0; i < n; i++)
{
cout << i + 1 << " - Mashinani nomini kiriting: ";
cin >> name;
cout << "Mashina brendini kiriting: ";
cin >> brend;
cout << "Mashina narxini kiriting: ";
cin >> narxi;
cout << "Mashina tezligini kiriting: ";
cin >> tezlik;
moshina[i] = Mashina(name, brend, narxi, tezlik);
cout << i + 1 << " - Motosiklni kiriting: ";
cin >> name;
cout << "Motosikl brendini kiriting: ";
cin >> brend;
cout << "Motosikl narxini kiriting: ";
cin >> narxi;
cout << "Motosikl tezligini kiriting: ";
cin >> tezlik;
motosikl[i] = Motosikl(name, brend, narxi, tezlik);
}
for (int i = 0; i < n; i++)
{
if (moshina[i].narx() > motosikl[i].narx())
{
cout << "Ushbu mashina motosikldan qimmatroq: ";
chiqarish(moshina[i]);
}
else if (moshina[i].narx() < motosikl[i].narx())
{
cout << "Ushbu mashina motosikldan arzonroq: ";
chiqarish(motosikl[i]);
}
else
{
cout << "Mashina va Motosikl bir xil narxda";
chiqarish(motosikl[i]);
chiqarish(moshina[i]);
}
}
for (int i = 0; i < n; i++)
{
if (moshina[i].tez() > motosikl[i].tez())
{
cout << "Ushbu mashina motosikldan tezroq: ";
chiqarish(moshina[i]);
}
else if (moshina[i].tez() < motosikl[i].tez())
{
cout << "Ushbu mashina motosikldan sekinroq: ";
chiqarish(motosikl[i]);
}
else
{
cout << "Mashina va Motosikl bir xil tezlikda";
chiqarish(motosikl[i]);
chiqarish(moshina[i]);
}
}
system("pause");
return 0;
}



Download 192.65 Kb.

Do'stlaringiz bilan baham:




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