0% found this document useful (0 votes)
18 views5 pages

2-MI (Amaliy) Napasov Donyor

The document discusses three programming examples related to creating classes and objects in C++. The first example creates a class to represent books with attributes like title, author, and number of pages. The second creates a class to represent student records with attributes like name, group, and grade. The third creates a class to represent cars with attributes like name, year, color, price, and horsepower.

Uploaded by

doniyornapasov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views5 pages

2-MI (Amaliy) Napasov Donyor

The document discusses three programming examples related to creating classes and objects in C++. The first example creates a class to represent books with attributes like title, author, and number of pages. The second creates a class to represent student records with attributes like name, group, and grade. The third creates a class to represent cars with attributes like name, year, color, price, and horsepower.

Uploaded by

doniyornapasov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

O‘ZBEKISTON RESPUBLIKASI

RAQAMLI TEXNOLOGIYALARI VAZIRLIGI

MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT


AXBOROT TEXNOLOGIYALARI UNIVERSITETI
SAMARQAND
FILIALI
“KOMPYUTER INJINIRINGI” FAKULTETI
“DASTURIY INJINIRING” KAFEDRASI
“DASTURLASH 2” FANIDAN

MUSTAQIL ISHI
Bajardi: Napasov Donyor
Tekshirdi: Rahmonova Robiya

Samarqand 2024
1- Misol:
Kitob mallifi, kitob nomi, chiqarilgan yili, kitob sahifalari sonidan iborat
struktura yarating. Siz kiritgan sondan sahifalar soni kam bo’ldan kitoblar
ro’yxarini ko’rsatuvchi dastur tuzing.
Javobi:
Dastur kodi:
#include <iostream>
using namespace std;
class kitob
{ private:
string nomi;
string avtor; int
page; public:
void Kitob (int b) {
page = b;
if (page>400 and page <= 600) {
nomi = "Oxirat";
avtor = "Temur Malik";
page = 580;
cout << "Kitob nomi: " << nomi << endl << "Kitob muallifi: " <<
avtor << endl << "Sahifa soni: " << page << endl;
}
if (page>200 and page <= 400) {
nomi = "Oq kema";
avtor = "Chingiz Aytmatov";
page = 400;
cout << "Kitob nomi: " << nomi << endl << "Kitob muallifi: " <<
avtor << endl << "Sahifa soni: " << page << endl;
}
if (page>0 and page <= 200) {
nomi = "Pul psixologiyasi";
avtor = "Morgan Xauzel";
page = 150;
cout << "Kitob nomi: " << nomi << endl << "Kitob avtori: " <<
avtor << endl << "Sahifa soni: " << page << endl;
}
}
}; int
main() {
kitob w;
int a;
cout << "Kitob sahifasi sonini kriting:"; cin >> a;
w.Kitob(a);
return main();
}

Dastur natijasi(screenshot):
2- Misol:
Talabalar ruyhatini tuzing: talaba ismi, talaba guruhi, talaba bahosi. Besh bahoga
o’qiydigan talabalarni ko’rsatuvchi dastur tuzing.
Javobi:

Dastur kodi:
#include <iostream>
#include <string>
using namespace std;
class ruyxat
{ private:
string ism;
string guruh; int
baho; public:
void ruyhat(int b) {
baho = b;
if (baho == 5) {
ism = "Abdumalik Ikromov";
guruh = "KI 22_04";
cout << "Talabaning ismi: " << ism << endl << "Talaba guruhi: " <<
guruh<<endl;
}
if (baho == 4) {
ism = "Ixtyor Baxriddinov";
guruh = "KI 22_14";
cout << "Talabaning ismi: " << ism << endl << "Talaba guruhi: " <<
guruh<<endl;
}
if (baho == 3) {
ism = "Shamsiddin Bobomurodov";
guruh = "KI 22_06";
cout << "Talabaning ismi: " << ism << endl << "Talaba guruhi: " <<
guruh<<endl;
}
}
};
int main() {
ruyxat w;
int a;
cout << "Bahoni kiriting: "; cin >> a;
w.ruyhat(a);
return main();
}

Dastur natijasi(screenshot):

3- Misol:
Mashinaning nomi, ishlab chiqarilgan yili, rangi, narxi, ot kuchidan iborat
struktura tuzing. Mashinaning nomini kiriting, agar mavjud bo’lsa
ma’lumotlarni ko’rsatuvchi, aks holda “mavjud emas” xabarini chiqaruvchi
dastur tuzing.

Javob:
Dastur kodi:
#include <iostream>
#include <string>
using namespace std;
class car { private:
string nomi;
string rangi;
int narxi; int
ot_kuchi; public:
void Car(string b) {
nomi = b;
if (nomi == "cobalt" or nomi=="Cobalt") {
nomi = "Cobalt";
rangi = "oq";
narxi = 11000;
ot_kuchi = 105; cout
<< "Mashina nomi: " << nomi << endl <<
"Rangi: " << rangi
<< endl << "Narxi: " << narxi << "$" << endl << "Ot kuchi: " << ot_kuchi << endl;
}
if (nomi == "Gentra" or nomi == "gentra") {
nomi = "Gentra";
rangi = "qora";
narxi = 11500;
ot_kuchi = 107;
cout << "Mashina nomi: " << nomi << endl << "Rangi: " << rangi
<< endl << "Narxi: " << narxi << "$" << endl << "Ot kuchi: " << ot_kuchi << endl;
}
if (nomi == "Damas" or nomi == "damas") {
nomi = "Damas";
rangi = "oq";
narxi = 8000;
ot_kuchi = 105;
cout << "Mashina nomi: " << nomi << endl << "Rangi: " << rangi
<< endl << "Narxi: " << narxi << "$" << endl << "Ot kuchi: " << ot_kuchi << endl;
}
if (nomi == "nexia" or nomi == "Nexia") {
nomi = "Nexia";
rangi = "oq";
narxi = 6000;
ot_kuchi = 105;
cout << "Mashina nomi: " << nomi << endl << "Rangi: " << rangi
<< endl << "Narxi: " << narxi << "$" << endl << "Ot kuchi: " << ot_kuchi << endl;
}
}
}; int
main() {
car w;
string a;
cout << "Mashina markasini kriting: "; cin >> a;
w.Car(a);
return main();
}

Dastur natijasi(screenshot):

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy