Notebook *notebooks = new Notebook[n]
Download 0.54 Mb.
|
- Bu sahifa navigatsiya:
- TOSHKENT 2022
- Natijasi: 2.3 Mijoz sinfini yarating. Unda kamida 5 ta maydon va ularni ekranga chiqaruvchi, qayta ishlovchi usullarni yarating. Yechilishi
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI TELEKOMMUNIKATSIYALAR FAKULTETI Dasturlash 1 fani 4-amaliy ishi Bajardi: 411-22-guruh 1-bosqich talabasi Abdusattorov Akbar Tekshirdi: Gulyamova Dilfuza Rahmatullayevna TOSHKENT 2022 1.3 Telefon va notebook class larini yarating va ularni bog’lovchi funksiyalar yarating Yechilishi: #include using namespace std; class Telefon{ private: string brend, model; int narx,yil; public: Telefon(){}; Telefon(string brend, string model, int narx, int yil){ this -> brend = brend; this -> model = model; this -> narx = narx; this -> yil = yil; } void getAll(){ cout << "Brend: " << brend << " Model: " << model << " Narx: " << narx << "$ Yili: " << yil << endl; } int get_narx(){ return narx; } int get_year(){ return yil; } }; class Notebook{ private: string brend, model; int narx,yil; public: Notebook(){}; Notebook(string brend, string model, int narx, int yil){ this -> brend = brend; this -> model = model; this -> narx = narx; this -> yil = yil; } void getAll(){ cout << "Brend: " << brend << " Model: " << model << " Narx: " << narx << "$ Yili: " << yil << endl; } int get_narx(){ return narx; } int get_year(){ return yil; } }; int main(){ int n, narx, yil; string brend, model; cout << "Nechta noubtuk va telefon kiritmoqchisiz: "; cin >> n; Notebook *notebooks = new Notebook[n]; Telefon *phones = new Telefon[n]; cout << "Noutbooklar va telefonlarni harakteriskasini kiriting(HP Victus 570 2022): \n"; for(int i=0;i cin >> brend >> model >> narx >> yil; notebooks[i] = Notebook(brend, model, narx, yil); cout << i+1 <<"-Telefon: "; cin >> brend >> model >> narx >> yil; phones[i] = Telefon(brend, model, narx, yil); } for(int i=0;i cout << "Ushbu gadjet yangiroq: "; phones[i].getAll(); }else if(phones[i].get_year()==notebooks[i].get_year()){ cout << "Ikkala qurilma bir xil yilda chiqarilgan: " << phones[i].get_year() << endl; }else{ cout << "Ushbu gadjet yangiroq: "; notebooks[i].getAll(); } } for(int i=0;i cout << "Ushbu gadjet arzonroq: "; notebooks[i].getAll(); }else if(phones[i].get_narx()==notebooks[i].get_narx()){ cout << "Ikkala qurilma narxlari bir xil: " << phones[i].get_narx() << endl; }else{ cout << "Ushbu gadjet arzonroq: "; phones[i].getAll(); } } } Natijasi: 2.3 Mijoz sinfini yarating. Unda kamida 5 ta maydon va ularni ekranga chiqaruvchi, qayta ishlovchi usullarni yarating. Yechilishi: #include using namespace std; class Mijoz{ private: string f_name,l_name,u_name; int balans,tovar,l_tovar=0; public: Mijoz(){}; Mijoz(string f_name, string l_name,string u_name,int balans,int tovar){ this -> f_name = f_name; this -> l_name = l_name; this -> u_name = u_name; this -> balans = balans; this -> tovar = tovar; } void set_lTovar(int l_tovar){ this -> l_tovar = l_tovar; balans = balans - l_tovar; tovar = tovar + l_tovar; } void addbalans(int bnew){ balans+=bnew; } void set_name(string f_name, string l_name, string u_name){ this -> f_name = f_name; this -> l_name = l_name; this -> u_name = u_name; } void getAll(){ cout << "Mijozning ism familyasi: " << f_name << " " << l_name; cout << "\nMijozning foydalnuvchi nomi: " << u_name; cout << "\nMijoz balansi: " << balans; cout << "\nMijozning umumiy tovar harajati: " << tovar << "\n\n"; } }; int main(){ string arr[5][3] = {{"Akbar","Abdusattorov","falador4587"},{"Azamat","Habibullayev","_azuz_of"},{"Xushnud","Xomidov","nahotk1"},{"Abbos","Abdusattorov","coder_ooo"},{"Sherzod","Toshtemirov","Faladors"}}; Mijoz *mijozlar = new Mijoz[5]; for(int i=0;i<5;i++){ mijozlar[i] = Mijoz(arr[i][0],arr[i][1],arr[i][2],400,0); } for(int i=0;i<5;i++){ mijozlar[i].getAll(); } mijozlar[0].set_lTovar(30); mijozlar[0].addbalans(20); mijozlar[0].getAll(); mijozlar[2].set_name("Vaxobov", "Muhammad Ali", "vakhobov04"); mijozlar[2].getAll(); } Natijasi: 3.3 Uchburchak sinfi yaratilsin va konstruktor e’lon qilinsin. Unda kamida uchta maydon va ularni ekranga chiqaruvchi va qayta ishlovchi sinf metodlarini yarating. Yechilishi: #include #include using namespace std; class Uchburchak{ private: float a,b,c,s=0,p=0; string tur; public: Uchburchak(float a, float b, float c){ this->a = a; this->b = b; this->c = c; }; void setYP(){ this ->p = (a+b+c); this ->s = sqrt(p/2*(p/2-a)*(p/2-b)*(p/2-c)); } void getYP(){ cout << "Uchburchak perimetri: " << p; cout << " Uchburchak yuzi: " << s << endl; } void setType(){ if((c*c)==(a*a+b*b)) this -> tur = "To'g'ri"; else if((c*c)<(a*a+b*b)) this -> tur = "O'tkir"; else{ this -> tur = "O'tmas"; } } void getType(){ cout << "Uchburchakning turi: " << tur << " burchakli.\n"; } void set_tomon(float a, float b, float c){ this->a = a; this->b = b; this->c = c; } void get_tomon(){ cout << a << " " << b << " " << c << endl; } }; int main(){ float a,b,c; cout << "Uchburchakning tomonlarini kiriting(a,b,c): ";cin >> a >> b >> c; Uchburchak obj = Uchburchak(a,b,c); obj.setYP(); obj.setType(); obj.getYP(); obj.getType(); cout << "Yangi qiymatlarni kiriting: "; cin >> a>>b>>c; obj.set_tomon(a,b,c); cout << "Yangi qiymatlar uchun: \n"; obj.get_tomon(); obj.setYP(); obj.setType(); obj.getYP(); obj.getType(); } Natijasi: Download 0.54 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling