-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBookList.hpp
79 lines (64 loc) · 2.63 KB
/
BookList.hpp
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
#pragma once // include guard
#include <iostream>
#include <iomanip>
#include <cstddef> // size_t
#include <string>
class Book
{
// Friend functions: read and write
friend std::ostream & operator<<( std::ostream & stream, const Book & book );
friend std::istream & operator>>( std::istream & stream, Book & book );
public:
// Constructor (can be the default constructor)
Book(const std::string & title = "", const std::string & author = "", const std::string & isbn = "", const double & price = 0.0 );
// Queries or getters
std::string get_isbn () const;
std::string get_title () const;
std::string get_author() const;
double get_price () const;
// Mutators or setters
void set_isbn ( const std::string & newIsbn );
void set_title ( const std::string & newTitle );
void set_author( const std::string & newAuthor );
void set_price ( double newPrice );
//private:
std::string _isbn;
std::string _title;
std::string _author;
double _price = 0.0;
};
// Ordinary functions: Relational Operators
bool operator==( const Book & lhs, const Book & rhs );
bool operator!=( const Book & lhs, const Book & rhs );
class BookList
{
// Friend functions: read and write
friend std::ostream & operator<<( std::ostream & stream, const BookList & bookList );
friend std::istream & operator>>( std::istream & stream, BookList & bookList );
public:
// Types and Exceptions
enum class Position {TOP, BOTTOM};
// Constructors, destructor, and assignment operators
BookList(const std::size_t & newCap = 30); //TO DO
// can be the default constructor
BookList( const BookList & other ) = default; // copy constructor
BookList( BookList && other ) = default; // move constructor
BookList & operator=(const BookList& rhs ) = default; // assignment operator
BookList & operator+=( const BookList & rhs);
// TO DO
// concatenates the rhs list to the end of this list
~BookList(); // TO DO // destructor
// Queries or getters
std::size_t size() const; // TO DO
// returns the number of books in the list
std::size_t find( const Book & book ) const; // TO DO // returns the (zero-based) offset from top of list where the book is found, or the size of the list if the book is not found
Book operator[](std::size_t index) const;// TO DO
// returns the book at the specified <index>
// read from a file
void readInFile(const std::string& filename);
private:
// Instance Attributes
std::size_t _capacity; // maximum number of books that can be stored in the dynamic array
std::size_t _books_array_size; // number of books in the list
Book * _bookArray; // the dynamic array of books
};