Output list book

Hi everybody. I have code which output books. But I can't create database books to output a list. Where I must create this database? I think in class Book? But how to implement it? Ex. I want output any 5 books .

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
 #pragma once
class Catalog;
class Menu
{
	
	void find()const;
	void view()const;
	void sort();
	void del();
	void ins();
	void aligin(int)const;
public:
	Menu();
	
	Catalog*m_p;  //point on the catalog book
	void showMenu();
	~Menu();
};

#pragma once
#include"Book.h"
#include<string>
using namespace std;

static const int MAX_SIZE = 150;
class Catalog
{
	int m_q;  // fact number books
	
public:
	Catalog();
	Book*m_pBook[MAX_SIZE];

	bool ins(const string&, const string&, int);
	bool del(const string&);
	int find(const string&)const;
	void sort();
	int getNumberofBook()const;   //return quantity books
	~Catalog();
};

#include "Catalog.h"



Catalog::Catalog():m_q(0)
{
}



bool Catalog::ins(const string &autor, const string &title, int year)
{
	if(find(title)!=-1)
	return false;

	m_pBook[m_q++] = new Book(autor, title, year);
	return true;
}

bool Catalog::del(const string &key)
{
	int i = find(key);
	if(i<0)
	return false;
	delete m_pBook[i];

	while (i < m_q - 1)
		m_pBook[++i] = m_pBook[i + 1];
	m_q--;
	return true;
}

int Catalog::find(const string &key) const
{
	for (int i = 0; i < m_q; ++i)
		if (m_pBook[i]->check(key))
			return i;
	return -1;
}

void Catalog::sort()
{
	for(int i=1;i<m_q;++i)
		for(int j=0;j<m_q-1;++j)
			if (m_pBook[i]->getAutor()>m_pBook[i+1]->getAutor())
			{
				Book*tmp = m_pBook[i];
				m_pBook[i] = m_pBook[i + 1];
				m_pBook[i + 1] = tmp;
			}
}


int Catalog::getNumberofBook() const
{
	return m_q;
}

Catalog::~Catalog()
{
	for (int i = 0; i < m_q; ++i)
		delete m_pBook[i];
}

#pragma once
#include<string>
#include<vector>

using namespace std;

class Catalog;
class Book
{
	string m_autor;
	string m_title;
	int m_year;
	//vector<vector<string,string>,int >mBook;

public:
	Book();
	Book(const string&,const string&,int);
	void setAutor(const string&);
	void setTitle(const string&);
	void setYear(const int);
	string getAutor()const {return m_autor; }
	string getTitle()const {return m_title; }
	int getYear()const { return m_year; }
	bool check(const string&)const;
	~Book();
};

#include "Book.h"



Book::Book():m_autor(""),m_title(""),m_year()
{
}

Book::Book(const string &autor, const string &title, int year):m_autor(autor),m_title(title),m_year(year)
{
}



void Book::setAutor(const string &autor)
{
	m_autor = autor;
}

void Book::setTitle(const string &title)
{
	m_title = title;
}

void Book::setYear(const int year)
{
	m_year = year;
}


bool Book::check(const string &key) const
{
	if (m_title == key)
		return true;
	return false;
}

Book::~Book()
{
}
If you want to create a database of books, I suggest you create a different class that stores book objects. From there you would be able to output the books inside that database.
Yes I know. I was trying to create, but do not know how to connect this DataBase? I believe that it is necessary to link from Class Catalog int m_q; // fact number books
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma once
#include"Book.h"
#include"Catalog.h"
#include<vector>
#include<tuple>
using namespace std;
class Book;
class Catalog;
class DataBase
{
	vector<tuple<string,string>,int >mBook;
public:
	DataBase();
	void getBook();
	~DataBase();
};

void DataBase::getBook()
{
	tuple<string, string, int>book1("Shevchenko", "Kobzar", 1596);
	tuple<string, string, int>book2( "Nicolas","Ddd", 2000);
	mBook.push_back(book1);
	mBook.push_back(book2);
}
Topic archived. No new replies allowed.