1. 6 Noma’lum turlar va noma’lum nomlar fazosi Kalit va qulf


Download 0.61 Mb.
bet1/2
Sana03.05.2020
Hajmi0.61 Mb.
#102990
  1   2
Bog'liq
labaraturya ishi


Jamoliddinov Ibrohomning dasturlash fanidan labaratuya ishi

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

Kalit va qulf class larini yarating va ularni bog’lovchi funksiyalar yarating

#include

#include

#include

#include

#include

using namespace std;

namespace mySpace

{

class Kalit{



string nomi, turi;

int yili, soni;

public:

friend void qidirish(mySpace::Kalit k[], int n);

friend void saralash(mySpace::Kalit k[], int n);

friend void ozgartirish(mySpace::Kalit k[], int n);

void set_malumot(string N, string T, int Y){

nomi=N;


turi=T;

yili=Y;

srand(time(NULL));

soni=rand()%20+5;

}

void get_malumot(){



cout << setw(15) << nomi << setw(15) << turi << setw(15) << yili << setw(15) << soni << endl;;

}

void cha(){



cout << setw(5) << "N" << setw(15) << "Nomi" << setw(15) << "Turi" << setw(15) << "Yili" << setw(15) << "Soni" << endl;

}

void qidirish(mySpace::Kalit k[], int n){



cout << "Qidirayotgan kalit nomini kiriting : ";

string s; cin >> s; bool bor=false;

cha();

for(int i=0; i

if(k[i].nomi.compare(s)==0){

int b=i;

bor=true;

cout << setw(5) << ++b;

k[i].get_malumot();

}

}



if(!bor){

cout << "Bunday nomdagi kalit topilmadi.\n";

}

}

void saralash(mySpace::Kalit k[], int n){



cout << "Nomi bo`yicha saralash holati.\n\n";

mySpace::Kalit templ;

for(int i=0; i

for(int j=0; j

if(k[i].nomi.compare(k[j].nomi)<0){

templ=k[i];

k[i]=k[j];

k[j]=templ;

}

}

}



cha();

int b=1;

for(int i=0; i

cout << setw(5) << b;

k[i].get_malumot();

b++;


}

}

void ozgartirish(mySpace::Kalit k[], int n){



int a;

cout << "Qaysi kalit malumotlarini o`zgartirishni hohlaysiz : ";

string s; cin >> s; bool bor=false;

for(int i=0; i

if(k[i].nomi.compare(s)==0){

bor=true;

cout << "1 : Harid qilish\n" << "2 : Sotish\n";

cin >> a;

switch(a){

case 1 :

{

int b=i;



k[i].soni++;

cha();


cout << setw(5) << ++b;

k[i].get_malumot();

cout << endl;

break;


}

case 2 : {

if(k[i].soni==0){

cout << "Bunday kalitdan qolmagan.\n";

} else{

int b=i;

k[i].soni--;

cha();


cout << setw(5) << ++b;

k[i].get_malumot();

cout << endl;

}

break;



}

default : cout << "Bunday amalni bajarib bo`lmaydi.\n";

}

}

}



if(!bor){

cout << "Bunday nomdagi kalit topilmadi.\n";

}

}

};



class Qulif{

string nomi, turi;

int yili, soni;

public:


friend void qidirish(mySpace::Qulif q[], int n);

friend void saralash(mySpace::Qulif q[], int n);

friend void ozgartirish(mySpace::Qulif q[], int n);

void set_malumot(string N, string T, int Y){

nomi=N;

turi=T;


yili=Y;

srand(time(0));

soni=rand()%20+5;

}

void get_malumot(){



cout << setw(15) << nomi << setw(15) << turi << setw(15) << yili << setw(15) << soni << endl;

}

void cha(){



cout << setw(5) << "N" << setw(15) << "Nomi" << setw(15) << "Turi" << setw(15) << "Yili" << setw(15) << "Soni" << endl;

}

void qidirish(mySpace::Qulif q[], int n){



cout << "Qidirayotgan qulif nomini kiriting : \n";

string s; cin >> s; bool bor=false;

for(int i=0; i

if(q[i].nomi.compare(s)==0){

bor=true;

int b=i;

cha();

cout << setw(5) << ++b;



q[i].get_malumot();

}

}



if(!bor){

cout << "Bunday nomdagi qulif topilmadi.\n";

}

}

void saralash(mySpace::Qulif q[], int n){



cout << "Nomi bo`yicha saralash holati.\n\n";

mySpace::Qulif templ;

for(int i=0; i

for(int j=0; j

if(q[i].nomi.compare(q[j].nomi)<0){

templ=q[i];

q[i]=q[j];

q[j]=templ;

}

}

}



cha();\

int b=1;

for(int i=0; i

cout << setw(5) << b;

q[i].get_malumot();

b++;


}

}

void ozgartirish(mySpace::Qulif q[], int n){



int a;

cout << "Qaysi qulif malumotlarini o`zgartirishni hohlaysiz.\n";

string s; cin >> s; bool bor=false;

for(int i=0; i

if(q[i].nomi.compare(s)==0){

bor=true;

cout << "1 : Harid qilish\n" << "2 : Sotish\n";

cin >> a;

switch(a){

case 1 : {

cha();

int b=i;



cout << setw(5) << ++b;

q[i].get_malumot();

break;

}

case 2 : {



if(q[i].soni==0){

cout << "Bu qulifdan boshqa qolmagan.\n";

} else {

int b=i;

cha();

cout << setw(5) << ++b;



q[i].get_malumot();

}

break;



}

default : cout << "Bunday amalni bajarib bo`lmaydi.\n";

}

}

}



if(!bor){

cout << "Bunday nomdagi qulif topilmadi.\n";

}

}

};



}

using namespace mySpace;

int main(){

string nomi[]={"cassl", "franch", "china", "coss"};

string turi[]={"po`lat", "temir", "qattiq metal", "sensrli"};

int yili[]={2005, 2003, 20010, 2018};

cout << setw(45) << "<>\n\n";

Kalit k[100];

Kalit ka;

ka.cha();

int t=1;

for(int i=0; i<4; i++){

k[i].set_malumot(nomi[i], turi[i], yili[i]);

cout << setw(5) << t;

k[i].get_malumot();

t++;


}

cout << endl;

ka.qidirish(k,4);

ka.saralash(k,4);

ka.ozgartirish(k,4);

cout << setw(45) << "<>\n\n";

Qulif q[100];

Qulif qa;

qa.cha();

int b=1;

for(int i=0; i<4; i++){

q[i].set_malumot(nomi[i], turi[i], yili[i]);

cout << setw(5) << b;

q[i].get_malumot();

b++;

}

cout << endl;



qa.qidirish(q,4);

qa.saralash(q,4);



qa.ozgartirish(q,4);

}



    1. Classlar o’rtasida vorislikni tashkil qilish.

Overriding va overloading bo’ladigan funksiyalarni yaratish

Kitob:

nomi, sahifalar soni, narxi



Chop etilgan kitob:

nomi, sahifalar soni, narxi, kitob muallifi, nashriyotga berilgan sanasi

Bugungi sana bilan kitobni nashriyotga berilganiga necha kun bo’lgan.

#include

#include

#include

#include

#include

using namespace std;

namespace mySpace

{

class Kitob

{

public:

string nomi;

int sah_soni;

int narxi;

};

class Chop_Et_Kitob : public Kitob{

public:

string mualifi;

int chop_yilli;

int chop_oyi;

int chop_kuni;

friend void disply(mySpace::Chop_Et_Kitob k[], int n);

friend void hisobla(mySpace::Chop_Et_Kitob k[],int n);

void set_malumot(string N, int S, int Na, string M, int Y,int O, int K){

nomi=N;

sah_soni=S;

narxi=Na;

mualifi=M;

chop_yilli=Y;

chop_oyi=O;

chop_kuni=K;

}

void ch(){

cout << setw(5) << "N" << setw(20) << "Nomi" << setw(20) << "Sahifalari soni" << setw(20) << "Narxi" << setw(20) << "Mualifi" << setw(27) << "chopetilgan sanasi";

}

void get_malumot()

{

cout << setw(20) << nomi << setw(20) << sah_soni << setw(20) << narxi << setw(20) << mualifi << setw(20) << chop_kuni << "." << chop_oyi << "." << chop_yilli;

}

void disply(mySpace::Chop_Et_Kitob k[], int n)

{

mySpace::Chop_Et_Kitob ka;

ka.ch(); cout << endl;

for(int i=0; i

int b=i;

cout << setw(5) << ++b;

k[i].get_malumot();

cout << endl;

}

}

void hisobla(mySpace::Chop_Et_Kitob k[],int n){

mySpace::Chop_Et_Kitob ka;

int x, y, z, day[n];

cout << "Bugingi sanani kiriting : ";

cin >> x >> y >> z;

ka.ch();

cout << setw(25) << "Kun" << endl;

for(int i=0; i

for(int j=k[i].chop_yilli; j

if(j%4==0){

day[i]+=366;

} else day[i]+=365;

}

}

for(int i=0; i

for(int j=k[i].chop_oyi; j

if(j%12==(1||3||5||7||10||12)){

day[i]+=31;

}

else if(j%12==(4||6||8||9||11)){

day[i]+=30;

} else if(j%12==2&&k[i].chop_yilli%4==0){

day[i]+=29;

} else day[i]+=28;

}

}

for(int i=0; i

day[i]+=k[i].chop_kuni;

day[i]-=x;

}

int b=1;

for(int i=0; i

cout << setw(5) << b;

k[i].get_malumot(); cout << setw(25) << day[i] << endl;

b++;

}

}

};

}

using namespace mySpace;

int main(){

string nomi[]={"Xamsa","Kimyo","Milliy G`oya","Geografiya","Ona tili"};

int sah_soni[]={32456,204,125,174,141};

int narxi[]={24500,23300,23100,12200,17600,};

string mualifi[]={"Navoiy", "Asqarov", "Nishonova", "Musayev", "Qodirov"};

int chop_yilli[]={2000,2004,2001, 2005, 2008};

int chop_oyi[]={5,2,6,9,7};

int chop_kuni[]={12,1,10,19,18};

Chop_Et_Kitob ch[100],cho;

cout << setw(55) <<"<<>>" << "\n\n";

for(int i=0; i<5; i++){

ch[i].set_malumot(nomi[i],sah_soni[i],narxi[i],mualifi[i],chop_yilli[i],chop_oyi[i],chop_kuni[i]);

}

cho.disply(ch,5);

cho.hisobla(ch,5); }



    1. Download 0.61 Mb.

      Do'stlaringiz bilan baham:
  1   2




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