942 – 19 guruhi talabasi Zaripboyev Anvar 12 – tajriba ishi (mta)
Download 53.91 Kb.
|
12 - tajriba ishi
private;static int shared_value; Sinf e‘lon qilingach, elementni sinfdan tashqaridagi global o‘zgaruvchi sifatida e’1on qilish kerak. Bu quyida ko‘rsatilgan: int class_name::shared_value;Navbatdagi dastur book_series smflni aniqlaydi. Bu sinf (seriya)ning barcha obyektlari (kitoblari) uchun bir xilda bo‘lgan page_count elementidan birgalikda foydalanadi. Agar dastur ushbu element qiymatini o‘zgartirsa. bu o‘zgarish shu ondayoq barcha sinf obyektlarida o‘z aksini topadi: #include using namespace std; class book_series { public:
book_series(float); void show_book(void); void set_pages(int); private:
static int page_count; float price; }; int book_series::page_count; void book_series::set_pages(int pages) { page_count= pages; } book_series::book_series(float price) { book_series::price = price; } void book_series:: show_book (void) { cout << "Narx:" << price << endl; cout << "Betlar:" << page_count << endl; }; int main() {
book_series word(19.95); word.set_pages(256); programming.show_book (); word.show_book(); cout << endl << "page_count ning o‘zgarishi "<< endl; programming.set_pages(512); programming.show_book(); word.show_book(); return 0; }
Download 53.91 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling