Dedline 5.
613-20 guruh talabasi:
Imomaliyev Shakhboz.
1- amaliytopshiriq. Klаssyarаtish ,vorislikyordamidaklasslar
yaratish.
2- amaliytopshiriq. Klаsslardaamallarniqaytayuklash.
3- amaliytopshiriq. Klasslardaoperatorlarniqaytayuklash.
Pаrаlеlоpipеdni ifоdаlоvchi klаssyarаting.
Topshiriq.
#include
#include
using namespace std;
classppiped
{
public:
int a, b, h, S, V;
voidkirit()
{
cout<< "a="; cin>> a;
cout<< "b="; cin>> b;
cout<< "h="; cin>> h;
}
void Top()
{
S = 2 * (a * b + a * h + b * h);
V = a * b * h;
}
voidchiqar()
{
cout<< "S = " << S <cout<< "V = " << V <}
};
classprizma: public ppiped
{
public:
float c;
voidPrizma_hisobla()
{
float p = (a + b + c) / 2.;
S = sqrt(p * (p - a) * (p - b) * (p - c));
V = S * h;
}
};
int main()
{
ppiped p;
p.kirit();
p.Top();
p.chiqar();
cout<< "Uchburchakliprizmakiriting: \n";
prizma u;
u.kirit();
cout<< "c = "; cin>>u.c;
u.Prizma_hisobla();
u.chiqar();
return 0;
}
2.Topshiriq
#include
#include
using namespace std;
class ppiped
{
public:
float a, b, h, S, V;
void kirit()
{
cout << "a="; cin >> a;
cout << "b="; cin >> b;
cout << "h="; cin >> h;
}
void Top()
{
S = 2 * (a * b + a * h + b * h);
V = a * b * h;
}
void chiqar()
{
cout << "S = " << S << endl;
cout << "V = " << V << endl;
}
};
class prizma: public ppiped
{
public:
float c;
void Prizma_hisobla()
{
float p = (a + b + c) / 2.;
S = sqrt(p * (p - a) * (p - b) * (p - c));
V = S * h;
}
};
float& operator + (prizma& q, ppiped& w)
{
float v = q.V + w.V;
return v;
}
int main()
{
ppiped p;
p.kirit();
p.Top();
p.chiqar();
cout << "Uchburchakli prizma kiriting: \n";
prizma u;
u.kirit();
cout << "c = "; cin >> u.c;
u.Prizma_hisobla();
u.chiqar();
cout << "Ikkala shakl hajmlari yig`indisi: ";
cout << u + ;
return 0;
}
3. Topshiriq
#include
#include
using namespace std;
class ppiped
{
public:
int a, b, h, S, V;
void kirit()
{
}
void Top()
{
S = 2 * (a * b + a * h + b * h);
V = a * b * h;
}
void chiqar()
{
cout << "S = " << S << endl;
cout << "V = " << V << endl;
}
};
class prizma: public ppiped
{
public:
float c;
void Prizma_hisobla()
{
float p = (a + b + c) / 2.;
S = sqrt(p * (p - a) * (p - b) * (p - c));
V = S * h;
}
};
istream& operator >> (istream& kirit, ppiped& o)
{
cout << "a="; kirit >> o.a;
cout << "b="; kirit >> o.b;
cout << "h="; kirit >> o.h;
}
ostream& operator << (ostream& chiqar, ppiped& t)
{
chiqar << "S = " << t.S << endl;
chiqar << "V = " << t.V << endl;
}
int main()
{
ppiped p;
cin >> p;
p.Top();
cout << p;
cout << "Uchburchakli prizma kiriting: \n";
prizma u;
cin >> u;
cout << "c = "; cin >> u.c;
u.Prizma_hisobla();
cout << u;
return 0;
}
Do'stlaringiz bilan baham: |