942 – 19 guruhi talabasi Zaripboyev Anvar 12 – tajriba ishi (mta)


Download 53.91 Kb.
bet6/9
Sana01.12.2021
Hajmi53.91 Kb.
#178642
1   2   3   4   5   6   7   8   9
Bog'liq
12 - tajriba ishi

Sinflar do‘stlari

Bir sinf ikkinchi sinfning umumiy usullaridan foydalanishi mumkin. Masalan: Bir sinf obyektlari massivlari bilan ishlovchi funksiyalarni ikkinchi sinf oshkor statik usullari sifatida ta’riflash mumkin.

#include

using namespace std;

class goods

{

string name;



long price;

float percent;

public:

goods() {};

goods(string name,long price, float percent)

{

goods::name= name;



goods::price= price;

goods::percent= percent;

}

void print()



{

cout << name <

cout << price;

cout << percent;

}

};

class array_goods



{

public:


static void all_input(struct goods a[], int n)

{

string name;



long price;

float percent;

for(int i=0; i

{

cin >> name >> price >> percent;



a[i] = goods(name, price, percent);

}

};



static void all_print(struct goods a[], int n)

{

for(int i=0; i

a[i].print();

}

};



int main()

{

goods a[]= {goods("smit", 34, 0.5), goods("bobbi", 45, 0.7), goods("pit", 56, 0.8)};



array_goods::all_print(a, 3);

array_goods::all_input(a, 3);

array_goods::all_print(a, 3);

return 0;

}


Download 53.91 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9




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