|
Muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalari universiteti telekommunikatsiyalar fakulteti
|
tarix | 08.04.2023 | ölçüsü | 0,63 Mb. | | #94783 |
| zaxriddinov
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
TELEKOMMUNIKATSIYALAR FAKULTETI
DASTURLASH II
6-Amaliy mashg’ulot
Bajardi: 414 -22-guruh 1-bosqich talabasi
Zaxriddinov Mexriddin
Tekshirdi: Shobdarov Elbek
TOSHKENT 2023
1-topshiriq
Kastyum va shim class larini yarating va ularni bog’lovchi funksiyalar yarating#include
#include
using namespace std;
void show(listnewlist)
{
list:iterator i;
for(i=newlist. begin(); i!=newlist.end();i++)
cout<<*t; cout<
}
int main0
{
list newlist;
newlist.push_back(-100);
newlist.push_back(26);
newlist.push_back(-17);
newlist.push_back(-11);
newlist.push_back(133);
show(list);
list.pop_back0;#include
#include
using namespace std;
void show(listnewlist)
{
list:iterator i;
for(i=newlist. begin(); i!=newlist.end();i++)
cout<<*t; cout<
}
int main0
{
list newlist;
newlist.push_back(-100);
newlist.push_back(26);
newlist.push_back(-17);
newlist.push_back(-11);
newlist.push_back(133);
show(list);
list.pop_back0;#include
#include
using namespace std;
void show(listnewlist)
{
list:iterator i;
for(i=newlist. begin(); i!=newlist.end();i++)
cout<<*t; cout<
}
int main0
{
list newlist;
newlist.push_back(-100);
newlist.push_back(26);
newlist.push_back(-17);
newlist.push_back(-11);
newlist.push_back(133);
show(list);
list.pop_back0;
#include
using namespace std;
class Kostyum{
private:
int narxi;
string color, brendi;
public:
Kostyum(){}
Kostyum(int narxi, string color, string brendi){
this->narxi = narxi;
this->color = color;
this->brendi = brendi;}
void chiqar(){
cout<<"Narxi: "<
int narx(){
return this->narxi;}};
class Shim{
private:
int narxi;
string color, brendi;
public:
Shim(){};
Shim(int narxi, string color, string brendi){
this->narxi = narxi;
this->color = color;
this->brendi = brendi;}
void chiqar(){
cout<<"Narxi: "<
int narx(){
return this->narxi;}};
int main(){
int narxi;
string color, brendi;
cout<<"Nechta mahsulot kiritmoqchisiz: ";
int n; cin>>n;
Kostyum *kostyum = new Kostyum[n];
Shim *shim = new Shim[n];
for(int i=0; i
cout<
cin>>narxi>>color>>brendi;
kostyum[i] = Kostyum(narxi,color,brendi);
cout<
cin>>narxi>>color>>brendi;
shim[i] = Shim(narxi,color,brendi);}
for(int i=0; i
if(kostyum[i].narx()>shim[i].narx()){
cout<<"Kostyum shimdan qimmatroq"<
kostyum[i].chiqar();}
else if(kostyum[i].narx()
cout<<"Kostyum shimdan arzonroq"<
shim[i].chiqar();}
else{
cout<<"Kostyum va shim bir xil narxda"<
kostyum[i].chiqar(); shim[i].chiqar();}}}
Topshiriq Ro‘yxatdagi oxirgi elementga ko‘rsatkich qaytaruvchi funksiya yozing.
#include
using namespace std;
// Ro‘yxatni yaratuvchi funksiya
int* createArray(int size) {
int* arr = new int[size];
return arr;
}
// Ko‘rsatkich qaytaruvchi funksiya
int* getLastElement(int* arr, int size) {
return &arr[size - 1];
}
int main() {
int size = 5;
int* arr = createArray(size);
for (int i = 0; i < size; i++) {
arr[i] = i + 1;
}
int* lastElement = getLastElement(arr, size);
cout << "Ro‘yxatdagi oxirgi element: " << *lastElement << endl;
delete[] arr; // Yoddan o‘chirish
return 0;
}
Bu dastur ro‘yxatni yaratib, unga qiymatlar yuklaydi, oxirgi elementini ko‘rsatkich qaytaruvchi funksiyaga uzatib, keyin o‘zgaruvchini chiqaradi.
Dostları ilə paylaş: |
|
|