3- variant. Noma’lum turlar va noma’lum nomlar fazosi


Download 89.33 Kb.
bet1/2
Sana02.06.2020
Hajmi89.33 Kb.
#113225
  1   2
Bog'liq
Dasturlash2.lab1.3v


1- LABORATORIYA ISHI

  1. OBYEKTGA YO’NALTIRILGAN DASTURLASH

3- variant.

    1. Noma’lum turlar va noma’lum nomlar fazosi

  1. 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:






    1. 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:






    1. Download 89.33 Kb.

      Do'stlaringiz bilan baham:
  1   2




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