-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook-class-code.cpp
101 lines (90 loc) · 3 KB
/
Book-class-code.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* @file book.cpp
* @brief This program demonstrates the usage of a book class in C++.
*
* The book class has private member variables for id, name, writer, subject, and course.
* It provides public member functions to insert and display book details. The main function
* demonstrates the usage of the book class by creating two book objects, allowing the user
* to input details for each book, inserting the details into the book objects using the
* insert() function, and displaying the details using the display() function.
*/
// Including Header File
#include <iostream>
// Using Namespace
using namespace std;
/// @brief Class for book
class book
{
private:
int id;
public:
string name;
string writer;
string subject;
string course;
/**
* @brief Inserts book details into the object.
*
* This function takes five parameters and assigns them to the corresponding
* member variables of the book object.
*
* @param i An integer representing the book's unique identifier.
* @param n A string representing the book's name.
* @param w A string representing the book's writer.
* @param s A string representing the book's subject.
* @param c A string representing the course the book is associated with.
*
* @return void This function does not return any value.
*/
void insert(int i, string n, string w, string s, string c)
{
id = i;
name = n;
writer = w;
subject = s;
course = c;
}
/**
* @brief Displays the book details.
*
* This function prints out the details of the book object, including its unique identifier, name, writer, subject, and course.
*
* @return void This function does not return any value.
*/
void display()
{
cout << "Book details are:" << endl;
cout << "Id is:" << id << "" << endl;
cout << "Name is:" << name << "" << endl;
cout << "Writer is:" << writer << "" << endl;
cout << "Subject is:" << subject << "" << endl;
cout << "Course is:" << course << "" << endl;
}
};
/**
* @brief The main function of the program.
*
* This function demonstrates the usage of the book class by creating two book objects,
* b1 and b2, and allowing the user to input details for each book. The details are then
* inserted into the book objects using the insert() function, and displayed using the
* display() function.
*
* @return An integer representing the exit status of the program. A return value of 0
* indicates that the program executed successfully.
*/
int main()
{
book b1;
book b2;
int id;
char name[100], writer[100], subject[100], course[100];
cout << "Enter id,name,writer,subject,course:\n";
cin >> id >> name >> writer >> subject >> course;
b1.insert(id, name, writer, subject, course);
b1.display();
cout << "Enter id,name,writer,subject,course:\n";
cin >> id >> name >> writer >> subject >> course;
b2.insert(id, name, writer, subject, course);
b2.display();
return 0;
}