Declare Class instance and use them
#include <iostream>
#include <cstring>
using namespace std;
class Book {
char title[80]; // book title
char author[40]; // author
int number; // number in library
public:
void store(char *t, char *name, int num);
void show();
};
void Book::store(char *t, char *name, int num)
{
strcpy(title, t);
strcpy(author, name);
number = num;
}
void Book::show()
{
cout << "Title: " << title << endl;
cout << "Author: " << author << endl;
cout << "Number on hand: " << number << endl;
}
int main()
{
Book book1, book2, book3;
book1.store("D", "t", 2);
book2.store("T", "v", 2);
book3.store("T", "e", 1);
book1.show();
book2.show();
book3.show();
return 0;
}
Related examples in the same category