# Sobirov Abrorbek Mavzu: Ob’ektga yo’naltirilgan dasturlash asoslari

 Sana 12.12.2019 Hajmi 38,43 Kb. #29791
Bog'liq
Abrorbek

Laboratoriya 3
 Guruh FISH Baho 640-19 Sobirov Abrorbek

Mavzu: Ob’ektga yo’naltirilgan dasturlash asoslari.

1. Klass yaratish, klass a’zolariga muroljat qilish usullari.

#include

#include

using namespace std;

class konus

{

public:

float kattaR;

float kichikR;

float yasovchiL;

float yuza;

float hajm;

void show()

{

cout << "Yuza :" << yuza << endl;

cout << "Hajm :" << hajm;

}

};

int main()

{

konus a;

cout << "katta radius :"; cin >> a.kattaR;

cout << "kichik radius :"; cin >> a.kichikR;

cout << "yasovchi :"; cin >> a.yasovchiL;

a.yuza = M_PI * (pow(a.kattaR,2) + (a.kattaR + a.kichikR) + pow(a.kichikR,2));

a.hajm = M_PI * (pow(a.kattaR,2) + (a.kattaR * a.kichikR) + pow(a.kichikR,2)) * 1 / 3;

a.show();

return 0;

}

1. Klass yaratishda metodlardan foydalanish.

#include

#include

using namespace std;

class konus

{

private:

float kattaR;

float kichikR;

float yasovchiL;

float yuza;

float hajm;

public:

void setKattaR(float r)

{

kattaR = r;

}

void setKichikR(float r)

{

kichikR = r;

}

void setYasovchi(float l)

{

yasovchiL = l;

}

void calcYuza()

{

yuza = M_PI * (pow(kattaR,2) + (kattaR + kichikR) + pow(kichikR,2));

}

void calcHajm()

{

hajm = M_PI * (pow(kattaR,2) + (kattaR * kichikR) + pow(kichikR,2)) * 1 / 3;

}

void show()

{

cout << "Yuza :" << yuza << endl;

cout << "Hajm :" << hajm;

}

};

int main()

{

konus a;

float d, b, c;

cout << "katta radius :"; cin >> d;

cout << "kichik radius :"; cin >> b;

cout << "yasovchi :"; cin >> c;

a.setKattaR(d);

a.setKichikR(b);

a.setYasovchi(c);

a.calcHajm();

a.calcYuza();

a.show();

return 0;

}

1. Konstruktorlar va destruktordan foydalanish.

#include

#include

using namespace std;

class konus

{

private:

float kattaR;

float kichikR;

float yasovchiL;

float yuza;

float hajm;

public:

konus(float a, float b, float c)

{

kattaR = a;

kichikR = b;

yasovchiL = c;

calcHajm();

calcYuza();

}

void calcYuza()

{

yuza = M_PI * (pow(kattaR,2) + (kattaR + kichikR) + pow(kichikR,2));

}

void calcHajm()

{

hajm = M_PI * (pow(kattaR,2) + (kattaR * kichikR) + pow(kichikR,2)) * 1 / 3;

}

~konus()

{

cout << "Yuza :" << yuza << endl;

cout << "Hajm :" << hajm;

}

};

int main()

{

float d, b, c;

cout << "katta radius :"; cin >> d;

cout << "kichik radius :"; cin >> b;

cout << "yasovchi :"; cin >> c;

konus a(d,b,c);

return 0;

}