|
1 – dars. C++ Dasturlash tilining kelib chiqishi xaqida ma’lumot
|
bet | 76/89 | Sana | 16.11.2023 | Hajmi | 313,45 Kb. | | #100010 |
Bog'liq @AKT Official C haqida o\'zbekcha darslar majmuiSinf do’stlari
C++ biror sinf do’stlariga shu sinfning hususiy elementlariga murojaat qilishgsha imkon beradi.Misol uchun qo’yida keltirilgan book sinfi librarian sinfini o’zining do’sti deb e'lon qiladi. Shuning uchun librarian sinfi ob'ektlari to’g’ridan to’g’ri book, sinfining hususiy elementlariga murojaat qilishlari mumkin ispol'zuya:
class book
{
public:
book (char *, char *, char *);
void show_book(void);
friend librarian;
private:
char title [64] ;
char author[64];
char catalog[64];
};
Qo’yidagi VIEWBOOK.CPP dasturida librarian sinfi book sinfini uz do’sti deb e'lon qiladi.Dasturda librarian sinfining change_catalog funktsiyasidan foydalanilgan:
#include
#include
class book
{
public:
book (char *, char *, char *);
void show_book(void);
friend librarian;
private:
char title[64] ;
char author[64];
char catalog[64];
};
book::book(char *title, char *author, char •catalog)
{
strcpy(book::title, title);
strcpy(book::author, author) ;
strcpy(book::catalog, catalog);
}
void book::show_book(void)
{
cout << "Nazvanie: " << title << endl;
cout << "Avtor: " << author << endl;
cout << "Katalog: " << catalog << endl;
}
class librarian
{
public:
void change_catalog(book *, char *);
char *get_catalog(book);
};
void librarian::change_catalog(book *this_book, char *new_catalog)
{
strcpy(this_book->catalog, new_catalog);
}
char *librarian: :get__catalog(book this_book)
{
static char catalog[64];
strcpy(catalog, this_book.catalog);
return(catalog) ;
}
void main(void)
{
book programming( "Uchimsya programmirovat' na yazihke C++", "Jamsa", "P101");
librarian library;
programming.show_book();
library.change_catalog(&programming, "Legkiy C++ 101");
programming.show_book();
}
|
| |