1- laboratoriya ishi obyektga yo’naltirilgan dasturlash


Download 33.37 Kb.
Sana13.03.2023
Hajmi33.37 Kb.
#1265927
Bog'liq
1-lab 10 topshiriq(moodle)


1- LABORATORIYA ISHI

  1. OBYEKTGA YO’NALTIRILGAN DASTURLASH

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

  1. Kitob va daftar class larini yarating va ularni bog’lovchi funksiyalar yarating.

Dastur kodi:
#include
#include
using namespace std;
class oquv_qurollari {
private:
string rangi;
string material;
public:
oquv_qurollari (string rang, string materal ){
this ->rangi= rang;
this ->material= materal;
}
virtual string getrang (){
return rangi;
}
virtual string getmaterial (){
return material;}
};
class kitob : public oquv_qurollari{
public:
kitob (string rangi, string material): oquv_qurollari(rangi, material){ }
};
class daftar : public oquv_qurollari {
public:
daftar (string rangi , string material ): oquv_qurollari (rangi, material){}
};
int main (){
kitob K= kitob ("qora","qog'ozdan");
daftar D= daftar ("yashil","qog'ozdan");
cout<<"\n";
cout<<" kitob rangi : "< cout<<" kitob materali: "< cout<<"____________________________\n";
cout<<" daftar rangi : "< cout<<" daftar materiali : "< }

    1. Classlar o’rtasida vorislikni tashkil qilish. Overriding va overloading bo’ladigan funksiyalarni yaratish

10.



Xodim:
FIO, maoshi, tug’ilgan sanasi

Firma xodimi:
FIO, maoshi, tug’ilgan sanasi, lavozimi

Programmist lavozimidagi va yoshi 35 dan oshmagan xodimlarni oyligini 20% ga oshirilsin.

Dastur kodi:
#include
#include
using namespace std;
class Firma_xodimi {
private:
string FIO;
string lavozimi;
double maoshi;
double yoshi;
double foiz;
public:
Firma_xodimi (string FIO, double maoshi, string lavozimi, double yoshi){
FIO=FIO; maoshi = maoshi; lavozimi=lavozimi; yoshi=yoshi;
}
string getFIO (){
return FIO; }
double getmaoshi(){
return maoshi; }
string getlavozimi (){
return lavozimi;}
double getyoshi (){
return yoshi; }
double getfoiz ( int oylik){
foiz=maoshi;
if (yoshi<=35){
foiz=foiz+ (maoshi)*(20)/100;
}
return foiz;
}
};
int main (){
string FIO, lavozimi;
double maoshi, yoshi;
int oylik;

cout<<"\n firma xodimini nomini kiriting : "; cin>>FIO;


cout<<" xodimning maoshini kiriting kiriting : "; cin>>maoshi;
cout<<" xodim lavozimini kiriting : "; cin>>lavozimi;
cout<<" xodim yoshini kiriting : "; cin>>yoshi;
cout<<" 20 % bonus bor : "; cin>>oylik;
cout<<"_________________________________________\n\n";
Firma_xodimi fir=Firma_xodimi (FIO, maoshi, lavozimi, yoshi );
cout<<" FIO : "< cout<<" xodim lavozimi : " < cout<<" Xodimning yoshi : "< cout<<" Xodimning oyligiga 20% qoshimcha bor : ";

cout<<" Xodimning maoshi : "<}

10.

“Kinofilm” classini yarating. Maydonlari: Nomlanishi, Rejessor, davomiyligi (minut da), aktyorlar soni. “Narx” nomli virtual metod yozing, kinofilm narxi quyidagi formula orqali hisoblanadi: davomiyligi * 20 + aktyorlarning soni * 30, lekin agar rejissori = “Stiven Spilberg” yoki “Djeyms Kemeron” bo’lsa narxi ikki barobarga qimmat bo’ladi. Shuningdek, film haqidagi ma'lumotlarni ekranga chiqaruvchi “Axborot” metodini yozing: Nomlanishi, rejissori, davomiyligi, aktyorlar soni va narxi.
Bundan tashqari, “Multifilm” avlod classini yarating. Qayta yuklangan “Narx” metodi formulasi quyidagicha: davomiyligi * 25 + aktyorlarning soni * 10 (rejissyordan qat'i nazar).
Asosiy dasturda 2 ta film yarating rejissori “Stiven Spilberg” va “Jorj Gofman” filmlari, multifilm yarating va ular haqida ma’lumotni chiqaring.

Dastur kodi:
#include
#include
using namespace std;

namespace Movie {


class Kinofilm {
private:
string name, rname;
double time, asoni, narxi;
public:
Kinofilm(){};
Kinofilm (string nam, string rnam, double tim, double ason): name(nam), rname(rnam), time ( tim), asoni (ason) {}
virtual double getnarx (){
narxi= ( time )*20+(asoni)*30;
if (rname=="Stiven_Spilberg" || rname=="Djeyms_Kemeron"){
narxi*=2;
}
return narxi;
}
virtual void Axborot (){
cout<<" Kinofilm nomi -> "< cout<<" Kinofilm rejjisori->"< cout<<" Kinofilm davomiyigi->"< cout<<" Kinofilm aktlar soni->"< cout<<" Kinofilm narxi ->"< }
};
class Multfilm : public Kinofilm{
private:
string mname, mrname;
double mtime, masoni, mnarxi;
public:
Multfilm(string mnam, string mrnam, double mtim, double mason): mname(mnam), mrname(mrnam), mtime(mtim), masoni(mason) {}
double getnarx (){
mnarxi= ( mtime )*25+(masoni)*10;

return mnarxi;


}
void Axborot (){
cout<<" Multfilm nomi -> "< cout<<" Multfilm rejjisori->"< cout<<" Multfilm davomiyigi->"< cout<<" Multfilm aktlar soni->"< cout<<" Multfilm narxi ->"< }
};
}
using namespace Movie;
int main (){
int a;
cin>>a;
Kinofilm kino=Kinofilm ( "3_savdoyi", "Stiven_Spilberg", 150,40 );
Multfilm mult= Multfilm( "Garry_Potor","Stiven_Spilberg", 100,30);
Kinofilm kino1=Kinofilm ( "Karib_dengiz_qaroqchilari", "Djeyms_Kemeron", 145,35 );
Multfilm mult1= Multfilm( "Ov_mavsumi","Djeyms_Kemeron", 100,30);
if(a==1){
cout<<" kinofilm 1 \n"; kino.Axborot();}
if (a==2){
cout<<" kinofilm 2 2\n"; kino1.Axborot();}

cout<<"____________________________________\n";
if (a==3){
cout<<" multfilm 1 \n"; mult.Axborot();}
if (a==4){
cout<<" multfilm 2 \n"; mult1.Axborot();}
main ();
}

Download 33.37 Kb.

Do'stlaringiz bilan baham:




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