Mega Code Archive

 
Categories / C++ / Class
 

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(); }