Protect.cpp
Upload User: dq031136
Upload Date: 2022-08-08
Package Size: 802k
Code Size: 1k
Development Platform:

C++ Builder

  1. #include <iostream.h>
  2. #include <string.h>
  3. class Book 
  4. {
  5.   public:
  6.     Book(char *title) { strcpy(Book::title, title); }; 
  7.     void show_title(void) { cout << title << endl; };
  8.   protected:
  9.     float cost;
  10.     void show_cost(void) { cout << cost << endl; };
  11.   private:
  12.     char title[64];
  13. };
  14. class LibraryCard : public Book 
  15. {
  16.   public:
  17.     LibraryCard(char *title, char *author, char *publisher) : Book(title) 
  18.       { 
  19.         strcpy(LibraryCard::author, author); 
  20.         strcpy(LibraryCard::publisher, publisher); 
  21.         cost = 49.95;
  22.       };
  23.     void show_library(void) 
  24.         show_title();
  25.         show_cost();
  26.         cout << author << ' ' << publisher; 
  27. };
  28.   private:
  29.     char author[64];
  30.     char publisher[64];
  31. };
  32. void main(void)
  33.  {
  34.    LibraryCard card("Jamsa's C/C++ Programmer's Bible", "Jamsa and Klander", 
  35.    "Jamsa Press");
  36.    card.show_library();
  37.  }