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
|
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
class Book
{
private:
string title;
string author;
string status;
int option;
public:
void setTitle(string title_);
void setAuthor(string author_);
void setStatus(string status_);
void output()const;
string getTitle()const;
string getAuthor()const;
string getStatus()const;
Book();
Book(string title_,string author_);
Book(string title_, string author_,string status_);
};
int main()
{
int option;
int max = 4;
string bookName;
Book object1;
Book libBooks[max] = {Book("The Prince of Milk","Exurb1a","Available"),
Book("Spooky Pookie","Sandra Boynton","Available"),
Book("The Alchemist","Paulo Coelho","Available"),
Book("Primary Colors","Anonymous")};
cout << "What would you like to do? " << endl;
cout << "1. View all books." << endl;
cout << "2. Search for a book." << endl;
cout << "3. Exit." << endl;
do {
cin >> option;
cout << endl;
for (int i = 0; i < max; i++)
{
cout <<"Book "<< i+1 <<": ";
libBooks[i].output();
}
cout << endl;
}while(option == 1);
if(option == 2)
{
cout << "What book would you like details for?: ";
cin >> bookName;
for (int i = 0; i < max; i++)
{
if(bookName = libBooks[i].getTitle()){
cout <<"Book "<< i+1 <<": ";
libBooks[i].output();
}
}
}
return 0;
}
Book::Book()
{
title = "N/A";
author = "N/A";
status = "N/A";
}
Book::Book(string title_, string author_)
{
title = title_;
author = author_;
status = "Available";
}
Book::Book(string title_,string author_, string status_)
{
title = title_;
author = author_;
status = status_;
}
void Book::setTitle(string title_)
{
title = title_;
}
void Book::setAuthor(string author_)
{
author = author_;
}
void Book::setStatus(string status_)
{
status = status_;
}
string Book::getTitle()const {
return title;
}
string Book::getAuthor()const {
return author;
}
string Book::getStatus()const {
return status;
}
void Book::output()const
{
cout << "Title: " << title;
cout << " Author: " << author;
cout << " Status: " << status << endl;
}
| |