class to represent a book : Base Class « Class « C++






class to represent a book

   
#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); 
    void assign_publisher(char *name) { strcpy(publisher, name); };
  private:
    char publisher[256];
    void show_publisher(void) { cout << publisher << '\n'; };
};

void Book::show_book(void) 
{ 
    show_title(); 
    show_publisher(); 
};
  
int main(void)
{
   Book tips, diary; 
  
   strcpy(tips.title, "C");
   strcpy(tips.author, "D");
   tips.price = 49.95;
   tips.assign_publisher("E");
   
   strcpy(diary.title, "F");
   strcpy(diary.author, "G");
   diary.price = 9.95;
   diary.assign_publisher("None");

   tips.show_book();
   diary.show_book();
 
}
  
    
    
  








Related examples in the same category

1.Base class and derived classBase class and derived class
2.Using base pointers on DerivedClass class objects.Using base pointers on DerivedClass class objects.
3.Pass arguments to base classPass arguments to base class
4.Init member variables from base classInit member variables from base class
5.Use Base keyword to call method in parent class from subclass