3- variant.
1- LABORATORIYA ISHI
OBYEKTGA YO’NALTIRILGAN DASTURLASH
Noma’lum turlar va noma’lum nomlar fazosi
Telefon va notebook class larini yarating va ularni bog’lovchi funksiyalar yarating
Dastur ko’di:
// Telefon va notebook classlarini bog'lovchi funksiyalar
#include
using namespace std;
class mobile {
private:
int makeyear;
int hotirasi;
public:
mobile ( int makeyear, int hotirasi){
this ->makeyear=makeyear;
this ->hotirasi=hotirasi;
}
virtual int getmakeyear (){
return makeyear;
}
virtual int gethotirasi (){
return hotirasi;
}
};
class Telefon : public mobile {
public:
Telefon ( int makeyear, int hotirasi) : mobile (makeyear, hotirasi){}
};
class Notebook : public mobile {
public:
Notebook (int makeyear, int hotirasi) : mobile ( makeyear , hotirasi){}
};
int main (){
Telefon Tel= Telefon (2019,16);
Notebook Note= Notebook (2016, 1000);
cout<<"\n _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n";
cout<<" chiqilgan yili : "< cout<<" telefon xotirasi GB : "< cout<<"_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n";
cout<<" ishlab chiqilgan yili : "<
cout<<" notebook xotirasi GB : "< cout<<"_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n";
}
Natija:
Classlar o’rtasida vorislikni tashkil qilish. Overriding va overloading bo’ladigan funksiyalarni yaratish
3.
|
Sana (uchta son):
kun, oy,yil
|
Dori-darmon:
nomi, ishlab chiqarilgan sanasi, ishlab chiqarish firmasi
|
Dori-darmon ishlab chiqarilganidan keyin necha kun o’tganligini hisoblang.
|
Dastur ko’di:
#include
#include
using namespace std;
class Day {
private: int sana, oy, yil;
public:
Day (int san, int o,int y){ sana=san; oy=o; yil= y; }
int getsana (){ return sana; }
int getoy (){ return oy; }
int getyil(){ return yil; }
Day (){}
};
class Dori {
private:
string dorinomi, firmasi;
int chsana, choy, chyil;
public:
Dori (string d, string f, int sa, int oy, int yil){
dorinomi=d; firmasi= f; chsana= sa; choy= oy; chyil=yil; }
string getdorinomi (){ return dorinomi; }
string getfirmasi (){ return firmasi; }
int getchsana (){ return chsana; }
int getchoy (){ return choy; }
int getchyil(){ return chyil; }
Dori (){}
};
class Kun : public Dori , public Day {
private:
Day day; Dori dori;
public:
Kun ( Day day, Dori dori ){
this -> day= day; this -> dori= dori;
}
void Sana (){ int q=0;
q= (day.getyil()- dori.getchyil())*366+(day.getoy()-dori.getchoy())*30+(day.getsana()-dori.getchsana());
cout<<"\n\n";
if (q) {
cout<<"Dori nomi : "< }
else cout<<" Siz sanani hatoni kiritdingiz hali dori chiqman :) \n\n";
}
};
int main (){
string dor, fir;
int aa,bb,cc; int dd,ee,ff;
cout<<"\n\n ";
cout<<" dori nomini kiriting : "; cin>>dor;
cout<<" dori firmasini kiriting : "; cin>>fir;
cout<<" dorining chiqgan yilni kiriting : "; cin>>aa;
cout<<" dorining chiqgan oyini kiriting : "; cin>>bb;
cout<<" dorining chiqgan sanasini kiriting: "; cin>>cc;
cout<<"============================================================\n\n";
cout<<" bugungi sanani kiriting : "; cin>>dd;
cout<<" bu oyni kiriting : "; cin>>ee;
cout<<" bu yilni kiritng : "; cin>>ff;
cout<<"============================================================\n\n";
Dori dori(dor, fir,cc, bb,aa);
Day day (dd, ee,ff);
Kun kun (day, dori );
kun.Sana();
}
Natija:
OYD ning merosxo’rlik va polimorfizm xususiyatlaridan foydalangan holda vazifaga muvofiq dasturlar yaratish
3
|
“Kompyuter” classini yarating. Maydonlari: Protsessor chastotasi (MGts), yadro soni, operativ xotira hajmi (MB), qattiq disk hajmi (GB), narxi. Ikkita virtual metod yarating: “Narx” metodida quyidagi formula orqali taxminiy narxni hisoblang: protsessor chastotasi 2000 MGts, yadro soni 2 dan kam bo’lmagan operativ xotira hajmi kamida 2048 Mb va qattiq disk hajmi 320 Gb bo’lsa, Protsessor chastotasi * yadro soni / 100 + xotira miqdori / 80 + qattiq disk hajmi / 20 formula orqali narxni($ dollar hisobida) hisoblasin. Mantiqiy tur qaytaruvchi “Yaroqlilik” nomli metod yarating. Ushbu metod Protsessor chastotasi 2000 MGts, yadro soni 2 dan kam bo’lmasa, operativ xotirasi 2048 MB dan kam bo’lmasa va qattiq disk hajmi kamida 320 GB bo’lsa rost(true), aks holda yolg’on(false) qiymat qaytarsin. Bundan tashqari, kompyuterlar haqida ma'lumotlarni chop etuvchi “Print” metodini yarating: protsessor chastotasi, yadro soni, operativ xotira hajmi, qattiq disk hajmi, narxi va ehtiyojlarimiz uchun yaroqliligi.
Shuningdek, |
Do'stlaringiz bilan baham: |