Labaratoriya ishi guruh: swd-002 Bajardi: Nuriddinov Elshod Tekshirdi: Ibragimova Kamila Axmedovna Toshkent 2022 laboratoriya ishi obyektga yo'llangan dasturlash noma’lum tiplar va noma’lum nomlar fazosi


Download 208.25 Kb.
Sana13.04.2023
Hajmi208.25 Kb.
#1353663
Bog'liq
dasturlash lab1


O’zbekiston Respublikasi Axborot Texnologiyalari va


Kommunikatsiyalarini Rivojlantirish Vazirligi
Muhammad Al-Xorazmiy nomidagi
Toshkent Axborot Texnologiyalari Universiteti.


LABARATORIYA ISHI

Guruh: SWD-002


Bajardi: Nuriddinov Elshod
Tekshirdi: Ibragimova Kamila Axmedovna
Toshkent 2022

  1. LABORATORIYA ISHI
    OBYEKTGA YO'LLANGAN DASTURLASH
    Noma’lum tiplar va noma’lum nomlar fazosi.

1-topshiriq
10. Dasturchi_1 va Dasturchi_2 nomli nomlar fazosida Kasr nomli sinf yarating, bu sinfda int a,b,c,d,
set(), get() va berilgan a/b va c/d kasr sonlarni solishtiruvchi metodlar mavjud bolsin.
Topshiriq :Bu ikkala nomlar fazosidagi sinf maydonlari va metodlariga asosiy dasturda murojat qiling.


#include
using namespace std;
namespace Dasturchi_1
{
class Kasr
{
double a, b, c, d;


public:
void taqqoslash()
{
double t = a / b, t1 = c / d;
if (t > t1)
{
cout << "a/b katta c/d dan(" << a << "/" << b << " > " << c << "/" << d << ")";
}
else if (t == t1)
{
cout << "a/b kichik c/d dan(" << a << "/" << b << " = " << c << "/" << d << ")";
}
else
{
cout << "a/b kichik c/d dan(" << a << "/" << b << " < " << c << "/" << d << ")";
}
}
int getA()
{
return this->a;
}
void setA(double a)
{
this->a = a;
}
int getB()
{
return this->b;
}
void setB(double b)
{
this->b = b;
}
int getC()
{
return this->c;
}
void setC(double c)
{
this->c = c;
}
int getD()
{
return this->d;
}
void setD(double d)
{
this->d = d;
}
};
}
namespace Dasturchi_2
{
class Kasr
{
double a, b, c, d;


public:
void taqqoslash()
{
double t = a / b, t1 = c / d;
if (t > t1)
{
cout << "a/b katta c/d dan(" << a << "/" << b << " > " << c << "/" << d << ")";
}
else if (t == t1)
{
cout << "a/b kichik c/d dan(" << a << "/" << b << " = " << c << "/" << d << ")";
}
else
{
cout << "a/b kichik c/d dan(" << a << "/" << b << " < " << c << "/" << d << ")";
}
}
int getA()
{
return this->a;
}
void setA(double a)
{
this->a = a;
}
int getB()
{
return this->b;
}
void setB(double b)
{
this->b = b;
}
int getC()
{
return this->c;
}
void setC(double c)
{
this->c = c;
}
int getD()
{
return this->d;
}
void setD(double d)
{
this->d = d;
}
};
}
int main()
{
Dasturchi_1::Kasr kasr1;
Dasturchi_2::Kasr kasr2;
kasr1.setA(12);
kasr1.setB(3);
kasr1.setC(16);
kasr1.setD(4);
kasr1.taqqoslash();
cout << "\n\n";


kasr2.setA(13);
kasr2.setB(4);
kasr2.setC(17);
kasr2.setD(5);
kasr2.taqqoslash();
cout << "\n\n";
}




2-topshiriq
Kitob va daftar sinflarini yarating va ularni birlashtiruvchi funksiyalarni yarating
#include
#include
#include
using namespace std;
class Kitob
{
int pages;
double price;


public:
Kitob()
{
}
Kitob(int pages, double price)
{
this->pages = pages;
this->price = price;
}
void setPages(int pages)
{
this->pages = pages;
}
int getPages()
{
return this->pages;
}
void setPrice(double price)
{
this->price = price;
}
int getPrice()
{
return this->price;
}
};
class Daftar
{
int pages;
double price;


public:
Daftar()
{
}
Daftar(int pages, double price)
{
this->pages = pages;
this->price = price;
}
void setPages(int pages)
{
this->pages = pages;
}
int getPages()
{
return this->pages;
}
void setPrice(double price)
{
this->price = price;
}
int getPrice()
{
return this->price;
}
};


void show(vector book, vector notebook)
{
double sum = 0;
while (!book.empty())
{
sum += book.back().getPrice();
book.pop_back();
}
cout << "\nJami kitobolar narxi" << sum;
sum = 0;
while (!notebook.empty())
{
sum += notebook.back().getPrice();
notebook.pop_back();
}
cout << "\n\nJami daftarlar narxi" << sum;
}
int main()
{
vector v1;
int cnt;
cout << "Daftarlar soni: ";
cin >> cnt;
for (int i = 0; i < cnt; i++)
{
cout << i + 1 << " - daftar malumotlari: \n";
int pages;
double price;
cout << "pages: ";
cin >> pages;
cout << "price: ";
cin >> price;
Daftar i_d;
i_d.setPages(pages);
i_d.setPrice(price);
v1.push_back(i_d);
}
vector v2;
cout << "Kitoblar soni: ";
cin >> cnt;
for (int i = 0; i < cnt; i++)
{
cout << i + 1 << " - kitob malumotlari: \n";
int pages;
double price;
cout << "pages: ";
cin >> pages;
cout << "price: ";
cin >> price;
Kitob i_k;
i_k.setPages(pages);
i_k.setPrice(price);
v2.push_back(i_k);
}
show(v2, v1);
cout << "\n\n";
}

Download 208.25 Kb.

Do'stlaringiz bilan baham:




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