Inkapsulyatsiya Merosxo‘rlik. Abstrakt sinflar Nazorat savollari


Download 23.02 Kb.
bet3/8
Sana31.03.2023
Hajmi23.02 Kb.
#1313063
1   2   3   4   5   6   7   8
Bog'liq
Reja Inkapsulyatsiya Merosxo‘rlik. Abstrakt sinflar

using namespace std;

  • class book_series{

  • public:

  • book_series(char *, char *, float);

  • void show_book(void); void set_pages(int);

  • private:

  • static int page_count; /*bu umumiy elеmеnt hisoblanadi*/

  • char title[64]; char author[64];

  • float price; };

  • int book_series::page_count; /*sinfdan tashaoidaumumiy o‘zgaruvchini e`lon qilish*/

  • void book_series::set_pages(int pages){

  • page_count = pages; }

  • book_series::book_series(char *title, char *author, float price){ /*Sinfning konstruktori*/

  • strcpy(book_series::title, title); /*string sinfiga ulanish uchun zarur bo‘lgan, strcpy() funksiyasi*/

  • strcpy(book_series::author, author);

  • book_series::price = price; }

  • void book_series:: show_book (void){

  • printf("Sarlavha: %s\n",title); printf("Muallif:%s\n",author);

  • printf("Narx: %.2f\n",price);

  • printf("Sahifalar: %d\n",page_count); }

  • void main(){

  • book_series programming("Studiing C++", "Author1", 22.95);

    /*programming obyektini konstruktor yordamida yaratish*/

    1. book_series word( "Studiing to work with Word for Windows 7", "Author2", 19.95); /*word obyektini konstruktor yordamida yaratish*/

    2. word.set_pages(256); /*Word o`еktining sahifalari soni bеriladi, bu programmingga ham ta`sir qiladi */

    3. programming.show_book ();

    4. word.show_book() ;

    5. programming.set_pages(512); /*page_countni o‘zgartirish*/


    6. Download 23.02 Kb.

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




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