Muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalari universitetining


Download 63.57 Kb.
Sana30.04.2023
Hajmi63.57 Kb.
#1402319
Bog'liq
1-amaliy Ulug`bek


MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETINING


1-kurs 120-22 etO` guruh talabasi Shavkatov Ulug`bekning
Dasturlash II(SWD002-1) fanidan amaliy topshirig`i

­­

1.Dasturchi_1 va Dasturchi_2 nomli nomlar fazosida Swap nomli sinf yarating, bu sinfda double a,b,c va set(), get() va berilgan a,b,c sonlarning qiymatlarini ozaro almashtiradigan metodlar mavjud bo’lsin.


Topshiriq : Bu ikkala nomlar fazosidagi sinf maydonlari va metodlariga asosiy dasturda murojat qiling.

#include


using namespace std;

namespace Dasturchi1 {


class swap {
private:
int a,b,c;
public:
void setabc(int a, int b, int c){
this -> a = a;
this -> b = b;
this -> c = c;
}

void func() {
int a1, b1, c1;
a1 = b;
b1 = c;
c1 = a;

cout << "a=" << a1 << endl;
cout << "b=" << b1 << endl;
cout << "c=" << c1 << endl;
}
};
}

namespace Dasturchi2 {


class swap {
private:
int a,b,c;
public:
void setabc(int a, int b, int c){
this -> a = a;
this -> b = b;
this -> c = c;
}

void func() {
int a1, b1, c1;
a1 = c;
b1 = a;
c1 = b;

cout << "a=" << a1 << endl;
cout << "b=" << b1 << endl;
cout << "c=" << c1 << endl;
}
};
}

int main(){


int a,b,c;
cout << "a="; cin >> a;
cout << "b="; cin >> b;
cout << "c="; cin >> c;
Dasturchi1::swap obj1;
obj1.setabc(a,b,c);
obj1.func();
Dasturchi2::swap obj2;
obj2.setabc(a,b,c);
obj2.func();
}

Dastur natijasi:




2.Universitetlar va kollejlar uchun sinflar yaratish va ularni bog'laydigan funktsiyalarni yaratish


#include


using namespace std;

class universitet {


int kengligi, sigimi;
string til;
public:
void MyFunc (int kengligi1,string til1,int sigimi1){
kengligi = kengligi1;
til = til1;
sigimi = sigimi;
cout << "Universitet kengligi: " << kengligi << endl;
cout << "Universitet tili: " << til << endl;
cout << "Universitet sig`imi: " << sigimi << endl;
cout << " " << endl;
}
};

class kollej {


int kengligi, sigimi;
string til;
public:
void MyFunc (int kengligi1,string til1,int sigimi1){
kengligi = kengligi1;
til = til1;
sigimi = sigimi1;
cout << "Kollej kengligi: " << kengligi << endl;
cout << "Kollej tili: " << til << endl;
cout << "kollej sig`imi: " << sigimi << endl;
cout << " " << endl;
}
};

int main() {


int kengligi, sigim;
string til;
universitet obj1;
cout << "kenglik kiriting: "; cin >> kengligi;
cout << "sig`im kiriting: "; cin >> sigim;
cout << "Til kiriting: "; cin >> til;
obj1.MyFunc(kengligi, til, sigim);
kollej obj2;
cout << "kenglik kiriting: "; cin >> kengligi;
cout << "sig`im kiriting: "; cin >> sigim;
cout << "Til kiriting: "; cin >> til;
obj2.MyFunc(kengligi, til, sigim);
}
Dastur natijasi:



Download 63.57 Kb.

Do'stlaringiz bilan baham:




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