#include <iostream>
using namespace std;
class Books {
public:
string Title;
string Author;
string Topic;
char intRegister;
int ID_Book;
void printAll() {
cout << "Title: \t" << Title << endl;
cout << "Author: \t" << Author << endl;
cout << "Topic: \t" << Topic << endl;
cout << "intRegister: \t" << intRegister << endl;
cout << "ID Book: \t" << ID_Book << endl;
}
};
int main() {
Books UniqBook;
UniqBook.Title = "Wires in Space";
UniqBook.Author = "Sheldon";
UniqBook.Topic = "String Theory";
UniqBook.intRegister = 'B';
UniqBook.ID_Book = 254121;
UniqBook.printAll();
return 0;
}
The code defines a class called Books
with several data types, such as string
and char
, and a member function called printAll()
.
The class Books
contains the following data members:
Title
: A string representing the title of the book.Author
: A string representing the author of the book.Topic
: A string representing the topic of the book.intRegister
: A character representing the book's registration status.ID_Book
: An integer representing the book's ID number.
The member function printAll()
prints out all the data members of the class to the console.
In the main()
function, an object of the Books
class is created and its data members are initialized with some values. Then, the printAll()
function is called on the UniqBook
object to print out its data members to the console.
The code demonstrates the use of a class to define a "book" object with various properties such as title, author, topic, and ID.
This code could be useful in a program that manages a library or book inventory, where book objects need to be created and tracked with specific information.
By defining a book class with different data types for each property, it becomes easier to create and manage book objects and their associated properties within the program. The class can also have member functions that perform operations on book objects such as searching, sorting, or printing.
No comments:
Post a Comment