1- laboratoriya ishi noma’lumturlarvanoma’lumnomlarfazosi


Download 91.53 Kb.
Sana03.02.2023
Hajmi91.53 Kb.
#1152803
Bog'liq
1- laboratoriya ishi obyektga yo’naltirilgan dasturlash


1- LABORATORIYA ISHI

    1. Noma’lumturlarvanoma’lumnomlarfazosi

  1. Klavyaturavasichqoncha class lariniyaratingvaularnibog’lovchimetodlaryarating

#include
#include
using namespace std;
classkomputer {
private:
stringfirmasi;
intmakeyear;
public:
komputer ( intmakeyear, string firmasi){
this ->makeyear=makeyear;
this ->firmasi=firmasi;
}
virtualintgetmakeyear (){
returnmakeyear;
}
virtual string getfirmasi (){
returnfirmasi;
}
};
classKlaviatura : public komputer {
public:
Klaviatura( intmakeyear, string firmasi) : komputer (makeyear, firmasi){}
};
classSichqoncha : public komputer {
public:
Sichqoncha (intmakeyear, string firmasi) :komputer ( makeyear , firmasi){}
};
int main (){
Klaviatura K = Klaviatura (2019,"acer");
Sichqoncha S = Sichqoncha (2016, "lietod");
cout<<"\n _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n";
cout<<" ishlabchiqilganyili : "< cout<<" chiqarilganfirmasi: "< cout<<"_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n";

cout<<" ishlabchiqilganyili : "<
cout<<" chiqarilganfirmasi: "< cout<<"_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n";
}



    1. Classlar o’rtasidavorisliknitashkilqilish. Overriding va overloading bo’ladiganfunksiyalarniyaratish


Sana (uchta son):
kun, oy, yil

Do’stlarro’yhati:
FIO, telefon, tug’ilgansanasi

Do’stingiznitug’ilgankuniganecha kun qolganinihisoblang

Dasturi:
#include


#include
using namespace std;
class Day {
private: intsana, oy, yil;
public:
Day (int san, into,int y){ sana=san; oy=o; yil= y; }
intgetsana (){ return sana; }
intgetoy (){ return oy; }
intgetyil(){ return yil; }
Day (){};
};
class Friends {
private:
stringismi, familyasi, ota_ismi;
inttsana, toy, tyil;
public:
Friends (string is, string fa, string ot, intsa, int oy, intyil){

ismi=is; familyasi= fa; ota_ismi= ot; tsana= sa; toy= oy; tyil=yil; }


stringgetismi (){ return ismi; }
stringgetfamilyasi (){ return familyasi; }
stringgetotaismi (){ return ota_ismi ; }
intgettsana (){ return tsana; }
intgettoy (){ return toy; }
intgettyil(){ return tyil; }
Friends (){};
};
class Kun : public Friends , public Day {
private:
Day day;
Friends friends ;
public:
Kun ( Dayday, Friends friends ){
this -> day= day;
this -> friends= friends;
}
void Sana (){
int q=0;
q= ((friends.gettoy()-day.getoy())*30+(friends.gettsana()-day.getsana()));
cout<<"\n\n";
if (q) {
cout<<"Ismi : "< cout<<" Tug'ilgankunga : "< }
else cout<<" Buguntug'ilgankuni :) \n\n";
}
};
int main (){
string is, fa, ot;
intaa,bb,cc; intdd,ee,ff;
cout<<"\n\n ";
cout<<" Do'stingizisminikiriting : "; cin>>is;
cout<<" Do'stingizfamilyasinikiriting : "; cin>>fa;
cout<<" Do'stingizotasiniisminikiriting : "; cin>>ot;
cout<<" Do'stingiztug'ilganyilnikiriting : "; cin>>aa;
cout<<" Do'stingiztug'ilganoyinikiriting : "; cin>>bb;
cout<<" Do'stingiztug'ilgansanasinikiriting: "; cin>>cc;
cout<<"============================================================\n\n";
cout<<" bugungisananikiriting : "; cin>>dd;
cout<<" buoynikiriting : "; cin>>ee;
cout<<" buyilnikiritng : "; cin>>ff;
cout<<"============================================================\n\n";
Friends friends (is, fa, ot, cc, bb,aa);
Day day (dd, ee,ff);
Kun kun (day, friends );
kun.Sana();
cout<<"===============================================================\n";
cout<<"===============================================================\n";
main ();
}




    1. OYD ning merosxo’rlik va polimorfizm xususiyatlaridan foydalangan holda vazifaga muvofiq dasturlar yaratish





Avtomobil” classini yarating. Maydonlari: Nomi, maksimal tezligi(km/s), narx. Konstruktor orqali faqat nomi va maksimal tezligini kiriting. Ikkita virtual metod yarating: "Narx" metodi – mashina narxini quyidagi fomula bilan hisoblaydi: maksimal tezlik * 100 $(AQSH dollari hisobida) va "Modelni yangilash" metodi maksimal tezlikni 10 km/s ga oshiradi. Bundan tashqari, obyekt haqida ma'lumotlarni chop qiluvchi “Axborot” metodini yarating: Nomi, maksimal tezlik va narx.
Bundan tashqari, “Zamonaviy avtomobil” nomli avlod class yarating. Maydonlarini ajdod class dan qabul qilsin. Qayta yuklangan 2 ta metodi mavjud: "Narx" metodi – mashina narxini quyidagi fomula bilan hisoblaydi: maksimal tezlik * 250 $(AQSH dollari hisobida) va "Modelni yangilash" metodi maksimal tezlikni 25 km/s ga oshiradi.
Asosiy dasturda Avtomobil classidan 140 km/s maksimal tezlikka ega va Zamonaviy avtomobil avlod classidan 160 km/s maksimal tezlikka ega bo’lgan obyektlar yarating. Avtomobillar haqida ma’lumotlarni ekranga chiqaring. Avtomobillarni modellarini yangilang va qayta ma’lumotlarni chop qiling.

Dasturi:
#include
#include
using namespace std;
namespaceUlov {
classAvtomibil {
private:
stringnomi;
doublemaxtezlik, narx;
public:
Avtomibil (){};
Avtomibil (string nomi, double maxtezlik ): nomi(nomi), maxtezlik(maxtezlik){}
virtualintNarx (){
narx = (maxtezlik) * 100;
returnnarx;
}
virtual void Axborot (){
cout<<" Avtomobilnomi : "< cout<<" Avtomobilmaksimaltezligi : "< cout<<" Avtomobilnarxi $ : "< }
virtual void modelnew (){
maxtezlik +=10;
narx= (maxtezlik)* 100;
cout<<" Avtomobilmaksimaltezligi : "< cout<<" Avtomobilnarxi $ : "< }
virtual void Axborot2 (){
cout<<" Avtomobilnomi : "< modelnew();
}
};
classZamonaviy_avtomobil : public Avtomibil {
private:
stringznomi;
doublezmaxtezlik, znarx;
doubleBatareya ;
public:
Zamonaviy_avtomobil( stringznomi, double zmaxtezlik) : znomi(znomi), zmaxtezlik(zmaxtezlik) {}
intZNarx() {
znarx = (zmaxtezlik)*250;
returnznarx;
}
voidAxborot () {
cout<<" ZamonaviyAvtomobilnomi : "< cout<<" ZamonaviyAvtomobilmaksimaltezligi : "< cout<<" ZamonaviyAvtomobilnarxi $ : "< }
voidzmodelnew () {
zmaxtezlik +=25;
znarx= (zmaxtezlik)* 250;
cout<<" Avtomobilmaksimalyangilangantezligi: "< cout<<" Avtomobilyangilangannarxi $ : "< }
void Axborot2 (){
cout<<" Avtomobilnomi : "< zmodelnew();
}
};
}
using namespace Ulov;
int main (){
Avtomibil A= Avtomibil(" Tesla",140 );
Zamonaviy_avtomobilZa= Zamonaviy_avtomobil (" Tesla new",160);
A.Axborot();
cout<<" Yangimodel : \n";
A.Axborot2();
cout<<"___________________________________________________"< Za.Axborot();
cout<<" Yangimodeli : \n";
Za.Axborot2();
return 0;
}

Download 91.53 Kb.

Do'stlaringiz bilan baham:




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