Bu ikkala nomlar fazosidagi sinf maydonlari va metodlariga asosiy dasturda murojat qiling


Download 320.59 Kb.
Sana30.04.2023
Hajmi320.59 Kb.
#1403839
Bog'liq
Rashidov


MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
TELEKOMMUNIKATSIYALAR FAKULTETI


Dasturlash 2 fani


1-mustaqil amaliyot ish

Bajardi: 009-2-guruh 1-bosqich talabasi


Rashidov Rahmon

TOSHKENT 2023
Variant-18

2-topshiriq
18. Dasturchi_1 va Dasturchi_2 nomli nomlar fazosida Fazo nomli sinf yarating, bu sinfda double x0,y0,z 0, x1,y1,z1 set(), get() va berilgan x0,y0,z0 koordinatadan x1,y1,z1koordinatagacha bo’lgan masofani hisoblovchi shablon funksiya mavjud bo’lsin.
Topshiriq :
Bu ikkala nomlar fazosidagi sinf maydonlari va metodlariga asosiy dasturda murojat qiling.

#include
#include

using namespace std;


class Tort {


private:
double a, b, c, d;

public:
void set(double x, double y, double z, double w) {


a = x;
b = y;
c = z;
d = w;
}

double getA() { return a; }


double getB() { return b; }
double getC() { return c; }
double getD() { return d; }

double perimeter() {


return a + b + c + d;
}

double area() {


double s = (a + b + c + d) / 2;
return sqrt((s - a) * (s - b) * (s - c) * (s - d));
}
};

int main() {


Tort t;
double a, b, c, d;

cout << "Tomonlarni kiriting: ";


cin >> a >> b >> c >> d;

t.set(a, b, c, d);


cout << "Perimeter = " << t.perimeter() << endl;


cout << "Yuza = " << t.area() << endl;

return 0;


}
1-topshiriq
18. Dasturchi_1 va Dasturchi_2 nomli nomlar fazosida Rev nomli sinf yarating, bu sinfda double *a, set(), get() va berilgan a massivni sonni teskari yozuvchi metodlar mavjud bo’lsin.
Topshiriq :
Bu ikkala nomlar fazosidagi sinf maydonlari va metodlariga asosiy dasturda murojat qiling.

#include

namespace Dasturchi_1{


namespace Dasturchi_2{
class Rev {
double *a;
int size;
public:
Rev(int n) {
size = n;
a = new double[size];
}
void set(double *arr) {
for(int i = 0; i < size; i++)
a[i] = arr[i];
}
void get(double *arr) {
for(int i = 0; i < size; i++)
arr[i] = a[i];
}
void reverse() {
for(int i = 0; i < size/2; i++) {
double temp = a[i];
a[i] = a[size-i-1];
a[size-i-1] = temp;
}
}
~Rev() {
delete[] a;
}
};
}
}

using namespace Dasturchi_1;


using namespace Dasturchi_2;

int main() {


int n = 5;
double arr[n] = {1.0, 2.0, 3.0, 4.0, 5.0};
Rev obj(n);
obj.set(arr);
std::cout << "Before reverse: ";
for(int i = 0; i < n; i++)
std::cout << arr[i] << " ";
std::cout << std::endl;
obj.reverse();
obj.get(arr);
std::cout << "After reverse: ";
for(int i = 0; i < n; i++)
std::cout << arr[i] << " ";
std::cout << std::endl;
return 0;
}

Download 320.59 Kb.

Do'stlaringiz bilan baham:




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