privstru.cpp
上传用户:dq031136
上传日期:2022-08-08
资源大小:802k
文件大小:1k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. #include <iostream.h>
  2. #include <string.h>
  3. struct MyBook {
  4.   char title[64];  // Public by default
  5.   void show_book(void) 
  6.     {
  7.       cout << "Book: " << title << " Price: $" << price ;  
  8.     };
  9.   
  10.   void set_price(float amount) { price = amount; };
  11.   void assign_title(char *name) { strcpy(title, name); };
  12.   private:
  13.     float price;
  14. };
  15. void main(void)
  16.  {
  17.    MyBook book; 
  18.    book.assign_title("Jamsa's C/C++ Programmer's Bible");
  19.    book.set_price(49.95);
  20.    book.show_book();
  21.  }