class array and object method call
#include <iostream>
#include <iomanip>
#include <string.h>
using namespace std;
class Book
{
public:
void show_title(void) { cout << title << '\n'; };
void show_book(void) { show_title(); show_publisher(); };
void assign_members(char *, char *, char *, float);
private:
char title[256];
char author[64];
float price;
char publisher[256];
void show_publisher(void) { cout << publisher << '\n'; };
};
void Book::assign_members(char *title, char *author, char *publisher,float price)
{
strcpy(Book::title, title);
strcpy(Book::author, author);
strcpy(Book::publisher, publisher);
Book::price = price;
}
int main(void)
{
Book Library[4];
Library[0].assign_members("A", "B","C", 49.95);
Library[1].assign_members("D", "E", "F", 54.95);
Library[2].assign_members("G", "H","I", 49.95);
Library[3].assign_members("J", "K","L", 24.95);
for (int i = 0; i < 4; i++)
Library[i].show_book();
}
Related examples in the same category