Private and public sections : Private « Class « C++






Private and public sections

   
#include <iostream>
#include <iomanip>
#include <string.h>
using namespace std;
class Book 
{
  public: 
    char title[256];
    char author[64];
    float price;
    void show_title(void) { cout << title << '\n'; };
    float get_price(void) { return(price); };
    void show_book(void) 
    { 
      show_title(); 
      show_publisher();
    };
    
    void assign_publisher(char *name) { strcpy(publisher, name); };
  private:
    char publisher[256];
    void show_publisher(void) { cout << publisher << '\n'; };
};

int main(void){
   Book bible; 
  
   strcpy(bible.title, "A");
   strcpy(bible.author, "B");
   bible.price = 49.95;
   bible.assign_publisher("C");

   bible.show_book();
}
  
    
    
  








Related examples in the same category

1.Private and protected member variablesPrivate and protected member variables
2.Private and public variables and methodsPrivate and public variables and methods
3.Class combination with private fields
4.Keep the private on your own
5.Setting member access levels
6.Use public methods to access private fields